Server/Display.cs
author sl
Sun, 18 Jan 2015 19:25:56 +0100
changeset 97 be7183f8c14c
parent 53 f7ad2dce46a9
child 104 189aac7dd3d6
permissions -rw-r--r--
Clearing screen when last client disconnects.
sl@3
     1
using System;
sl@3
     2
using System.Collections.Generic;
sl@3
     3
using System.Linq;
sl@3
     4
using System.Text;
sl@3
     5
using System.Threading.Tasks;
sl@3
     6
//
sl@3
     7
using System.Runtime.InteropServices;
sl@46
     8
//using System.Runtime.Serialization;
sl@3
     9
sl@3
    10
namespace SharpDisplayManager
sl@3
    11
{
sl@46
    12
sl@44
    13
    /// <summary>
sl@44
    14
    /// Provide access to our display hardware through MiniDisplay API.
sl@44
    15
    /// </summary>
sl@46
    16
    public class Display
sl@3
    17
    {
sl@3
    18
sl@3
    19
        //Constructor
sl@3
    20
        public Display()
sl@3
    21
        {
sl@3
    22
            iDevice = IntPtr.Zero;
sl@3
    23
        }
sl@3
    24
sl@3
    25
        //
sl@39
    26
        public bool Open(TMiniDisplayType aType)
sl@3
    27
        {
sl@3
    28
            if (iDevice == IntPtr.Zero)
sl@3
    29
            {
sl@39
    30
                iDevice = MiniDisplayOpen(aType);
sl@3
    31
            }
sl@3
    32
            return iDevice != IntPtr.Zero;
sl@3
    33
        }
sl@3
    34
sl@3
    35
        public void Close()
sl@3
    36
        {
sl@3
    37
            MiniDisplayClose(iDevice);
sl@3
    38
            iDevice = IntPtr.Zero;
sl@3
    39
        }
sl@3
    40
sl@3
    41
        public bool IsOpen()
sl@3
    42
        {
sl@3
    43
            return iDevice != IntPtr.Zero;
sl@3
    44
        }
sl@3
    45
sl@3
    46
        public void Clear()
sl@3
    47
        {
sl@3
    48
            MiniDisplayClear(iDevice);
sl@3
    49
        }
sl@3
    50
sl@3
    51
        public void Fill()
sl@3
    52
        {
sl@3
    53
            MiniDisplayFill(iDevice);
sl@3
    54
        }
sl@3
    55
sl@3
    56
        public void SwapBuffers()
sl@3
    57
        {
sl@3
    58
            MiniDisplaySwapBuffers(iDevice);
sl@3
    59
        }
sl@3
    60
sl@3
    61
        public int MaxBrightness()
sl@3
    62
        {
sl@3
    63
            return MiniDisplayMaxBrightness(iDevice);
sl@3
    64
        }
sl@3
    65
sl@3
    66
        public int MinBrightness()
sl@3
    67
        {
sl@3
    68
            return MiniDisplayMinBrightness(iDevice);
sl@3
    69
        }
sl@3
    70
sl@3
    71
        public void SetBrightness(int aBrightness)
sl@3
    72
        {
sl@3
    73
            if (!IsOpen()) return;
sl@3
    74
sl@3
    75
            MiniDisplaySetBrightness(iDevice, aBrightness);
sl@3
    76
        }
sl@3
    77
sl@4
    78
        public int WidthInPixels()
sl@4
    79
        {
sl@4
    80
            return MiniDisplayWidthInPixels(iDevice);
sl@4
    81
        }
sl@4
    82
sl@4
    83
        public int HeightInPixels()
sl@4
    84
        {
sl@4
    85
            return MiniDisplayHeightInPixels(iDevice);
sl@4
    86
        }
sl@4
    87
sl@57
    88
        public void SetPixel(int aX, int aY, uint aValue)
sl@4
    89
        {
sl@4
    90
            MiniDisplaySetPixel(iDevice,aX,aY,aValue);
sl@4
    91
        }
sl@4
    92
sl@12
    93
        public void RequestPowerSupplyStatus()
sl@12
    94
        {
sl@44
    95
            MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
sl@12
    96
        }
sl@12
    97
sl@12
    98
        public void RequestDeviceId()
sl@12
    99
        {
sl@44
   100
            MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
sl@12
   101
        }
sl@12
   102
sl@12
   103
        public void RequestFirmwareRevision()
sl@12
   104
        {
sl@44
   105
            MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
sl@12
   106
        }
sl@12
   107
sl@52
   108
        public void PowerOn()
sl@52
   109
        {
sl@52
   110
            MiniDisplayPowerOn(iDevice);
sl@52
   111
        }
sl@52
   112
sl@52
   113
        public void PowerOff()
sl@52
   114
        {
sl@52
   115
            MiniDisplayPowerOff(iDevice);
sl@52
   116
        }
sl@52
   117
sl@52
   118
        public bool SupportPowerOnOff()
sl@52
   119
        {
sl@52
   120
            return MiniDisplaySupportPowerOnOff(iDevice);
sl@52
   121
        }
sl@52
   122
sl@53
   123
        public void ShowClock()
sl@53
   124
        {
sl@53
   125
            MiniDisplayShowClock(iDevice);
sl@53
   126
        }
sl@53
   127
sl@53
   128
        public void HideClock()
sl@53
   129
        {
sl@53
   130
            MiniDisplayHideClock(iDevice);
sl@53
   131
        }
sl@53
   132
sl@53
   133
        public bool SupportClock()
sl@53
   134
        {
sl@53
   135
            return MiniDisplaySupportClock(iDevice);
sl@53
   136
        }
sl@53
   137
sl@12
   138
        public bool PowerSupplyStatus()
sl@12
   139
        {
sl@12
   140
            bool res = MiniDisplayPowerSupplyStatus(iDevice);
sl@12
   141
            return res;
sl@12
   142
        }
sl@12
   143
sl@12
   144
        public TMiniDisplayRequest AttemptRequestCompletion()
sl@12
   145
        {
sl@12
   146
            return MiniDisplayAttemptRequestCompletion(iDevice);
sl@12
   147
        }
sl@12
   148
sl@12
   149
        public TMiniDisplayRequest CurrentRequest()
sl@12
   150
        {
sl@12
   151
            return MiniDisplayCurrentRequest(iDevice);
sl@12
   152
        }
sl@12
   153
sl@12
   154
        public bool IsRequestPending()
sl@12
   155
        {
sl@12
   156
            return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
sl@12
   157
        }
sl@12
   158
sl@12
   159
sl@10
   160
        public string Vendor()
sl@10
   161
        {
sl@10
   162
            IntPtr ptr = MiniDisplayVendor(iDevice);
sl@10
   163
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   164
            return str;
sl@10
   165
        }
sl@4
   166
sl@10
   167
        public string Product()
sl@10
   168
        {
sl@10
   169
            IntPtr ptr = MiniDisplayProduct(iDevice);
sl@10
   170
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   171
            return str;
sl@10
   172
        }
sl@10
   173
sl@10
   174
        public string SerialNumber()
sl@10
   175
        {
sl@10
   176
            IntPtr ptr = MiniDisplaySerialNumber(iDevice);
sl@10
   177
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   178
            return str;
sl@10
   179
        }
sl@4
   180
sl@12
   181
        public string DeviceId()
sl@12
   182
        {
sl@12
   183
            IntPtr ptr = MiniDisplayDeviceId(iDevice);
sl@12
   184
            string str = Marshal.PtrToStringAnsi(ptr);
sl@12
   185
            return str;
sl@12
   186
        }
sl@12
   187
sl@12
   188
        public string FirmwareRevision()
sl@12
   189
        {
sl@12
   190
            IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
sl@12
   191
            string str = Marshal.PtrToStringAnsi(ptr);
sl@12
   192
            return str;
sl@12
   193
        }
sl@12
   194
sl@3
   195
        //Our display device handle
sl@3
   196
        IntPtr iDevice;
sl@3
   197
sl@46
   198
sl@46
   199
        //[Serializable]
sl@39
   200
        public enum TMiniDisplayType
sl@39
   201
        {
sl@39
   202
            EMiniDisplayAutoDetect, /*Not yet implemented*/
sl@46
   203
            //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
sl@39
   204
            EMiniDisplayFutabaGP1212A01,
sl@46
   205
            //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
sl@39
   206
            EMiniDisplayFutabaGP1212A02
sl@39
   207
        };
sl@39
   208
sl@39
   209
sl@10
   210
        public enum TMiniDisplayRequest
sl@10
   211
        {
sl@10
   212
            EMiniDisplayRequestNone,
sl@10
   213
            EMiniDisplayRequestDeviceId,
sl@10
   214
            EMiniDisplayRequestFirmwareRevision,
sl@10
   215
            EMiniDisplayRequestPowerSupplyStatus
sl@39
   216
        };
sl@10
   217
sl@3
   218
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@39
   219
        public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
sl@3
   220
sl@3
   221
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   222
        public static extern void MiniDisplayClose(IntPtr aDevice);
sl@3
   223
sl@3
   224
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   225
        public static extern void MiniDisplayClear(IntPtr aDevice);
sl@3
   226
sl@3
   227
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   228
        public static extern void MiniDisplayFill(IntPtr aDevice);
sl@3
   229
sl@3
   230
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   231
        public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
sl@3
   232
sl@3
   233
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   234
        public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
sl@3
   235
sl@3
   236
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   237
        public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
sl@3
   238
sl@3
   239
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   240
        public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
sl@3
   241
sl@4
   242
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   243
        public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
sl@4
   244
sl@4
   245
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   246
        public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
sl@4
   247
sl@4
   248
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@57
   249
        public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
sl@4
   250
sl@10
   251
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   252
        public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
sl@10
   253
sl@10
   254
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   255
        public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
sl@10
   256
sl@10
   257
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   258
        public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
sl@10
   259
sl@10
   260
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   261
        public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
sl@10
   262
sl@10
   263
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   264
        public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
sl@10
   265
sl@10
   266
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@12
   267
        [return: MarshalAs(UnmanagedType.I1)]
sl@10
   268
        public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
sl@10
   269
sl@10
   270
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@44
   271
        public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
sl@10
   272
sl@10
   273
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   274
        public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
sl@10
   275
sl@10
   276
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   277
        public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
sl@10
   278
sl@10
   279
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   280
        public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
sl@10
   281
sl@52
   282
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@52
   283
        public static extern void MiniDisplayPowerOn(IntPtr aDevice);
sl@52
   284
sl@52
   285
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@52
   286
        public static extern void MiniDisplayPowerOff(IntPtr aDevice);
sl@52
   287
sl@52
   288
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@52
   289
        [return: MarshalAs(UnmanagedType.I1)]
sl@52
   290
        public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
sl@10
   291
sl@53
   292
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@53
   293
        public static extern void MiniDisplayShowClock(IntPtr aDevice);
sl@53
   294
sl@53
   295
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@53
   296
        public static extern void MiniDisplayHideClock(IntPtr aDevice);
sl@53
   297
sl@53
   298
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@53
   299
        [return: MarshalAs(UnmanagedType.I1)]
sl@53
   300
        public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
sl@53
   301
sl@53
   302
sl@3
   303
    }
sl@3
   304
}