Server/Display.cs
author sl
Fri, 22 Aug 2014 08:24:51 +0200
changeset 40 4846aa0bb10c
parent 18 7acec5059fa6
child 44 a4f39c390e9a
permissions -rw-r--r--
Fixing designer issues with controls being outside our dialog.
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@3
     8
sl@3
     9
namespace SharpDisplayManager
sl@3
    10
{
sl@3
    11
    class Display
sl@3
    12
    {
sl@3
    13
sl@3
    14
        //Constructor
sl@3
    15
        public Display()
sl@3
    16
        {
sl@3
    17
            iDevice = IntPtr.Zero;
sl@3
    18
        }
sl@3
    19
sl@3
    20
        //
sl@39
    21
        public bool Open(TMiniDisplayType aType)
sl@3
    22
        {
sl@3
    23
            if (iDevice == IntPtr.Zero)
sl@3
    24
            {
sl@39
    25
                iDevice = MiniDisplayOpen(aType);
sl@3
    26
            }
sl@3
    27
            return iDevice != IntPtr.Zero;
sl@3
    28
        }
sl@3
    29
sl@3
    30
        public void Close()
sl@3
    31
        {
sl@3
    32
            MiniDisplayClose(iDevice);
sl@3
    33
            iDevice = IntPtr.Zero;
sl@3
    34
        }
sl@3
    35
sl@3
    36
        public bool IsOpen()
sl@3
    37
        {
sl@3
    38
            return iDevice != IntPtr.Zero;
sl@3
    39
        }
sl@3
    40
sl@3
    41
        public void Clear()
sl@3
    42
        {
sl@3
    43
            MiniDisplayClear(iDevice);
sl@3
    44
        }
sl@3
    45
sl@3
    46
        public void Fill()
sl@3
    47
        {
sl@3
    48
            MiniDisplayFill(iDevice);
sl@3
    49
        }
sl@3
    50
sl@3
    51
        public void SwapBuffers()
sl@3
    52
        {
sl@3
    53
            MiniDisplaySwapBuffers(iDevice);
sl@3
    54
        }
sl@3
    55
sl@3
    56
        public int MaxBrightness()
sl@3
    57
        {
sl@3
    58
            return MiniDisplayMaxBrightness(iDevice);
sl@3
    59
        }
sl@3
    60
sl@3
    61
        public int MinBrightness()
sl@3
    62
        {
sl@3
    63
            return MiniDisplayMinBrightness(iDevice);
sl@3
    64
        }
sl@3
    65
sl@3
    66
        public void SetBrightness(int aBrightness)
sl@3
    67
        {
sl@3
    68
            if (!IsOpen()) return;
sl@3
    69
sl@3
    70
            MiniDisplaySetBrightness(iDevice, aBrightness);
sl@3
    71
        }
sl@3
    72
sl@4
    73
        public int WidthInPixels()
sl@4
    74
        {
sl@4
    75
            return MiniDisplayWidthInPixels(iDevice);
sl@4
    76
        }
sl@4
    77
sl@4
    78
        public int HeightInPixels()
sl@4
    79
        {
sl@4
    80
            return MiniDisplayHeightInPixels(iDevice);
sl@4
    81
        }
sl@4
    82
sl@4
    83
        public void SetPixel(int aX, int aY, int aValue)
sl@4
    84
        {
sl@4
    85
            MiniDisplaySetPixel(iDevice,aX,aY,aValue);
sl@4
    86
        }
sl@4
    87
sl@12
    88
        public void RequestPowerSupplyStatus()
sl@12
    89
        {
sl@12
    90
            MiniDisplayRequestPowerSupplyStatus(iDevice);
sl@12
    91
        }
sl@12
    92
sl@12
    93
        public void RequestDeviceId()
sl@12
    94
        {
sl@12
    95
            MiniDisplayRequestDeviceId(iDevice);
sl@12
    96
        }
sl@12
    97
sl@12
    98
        public void RequestFirmwareRevision()
sl@12
    99
        {
sl@12
   100
            MiniDisplayRequestFirmwareRevision(iDevice);
sl@12
   101
        }
sl@12
   102
sl@12
   103
        public bool PowerSupplyStatus()
sl@12
   104
        {
sl@12
   105
            bool res = MiniDisplayPowerSupplyStatus(iDevice);
sl@12
   106
            return res;
sl@12
   107
        }
sl@12
   108
sl@12
   109
        public TMiniDisplayRequest AttemptRequestCompletion()
sl@12
   110
        {
sl@12
   111
            return MiniDisplayAttemptRequestCompletion(iDevice);
sl@12
   112
        }
sl@12
   113
sl@12
   114
        public TMiniDisplayRequest CurrentRequest()
sl@12
   115
        {
sl@12
   116
            return MiniDisplayCurrentRequest(iDevice);
sl@12
   117
        }
sl@12
   118
sl@12
   119
        public bool IsRequestPending()
sl@12
   120
        {
sl@12
   121
            return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
sl@12
   122
        }
sl@12
   123
sl@12
   124
sl@10
   125
        public string Vendor()
sl@10
   126
        {
sl@10
   127
            IntPtr ptr = MiniDisplayVendor(iDevice);
sl@10
   128
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   129
            return str;
sl@10
   130
        }
sl@4
   131
sl@10
   132
        public string Product()
sl@10
   133
        {
sl@10
   134
            IntPtr ptr = MiniDisplayProduct(iDevice);
sl@10
   135
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   136
            return str;
sl@10
   137
        }
sl@10
   138
sl@10
   139
        public string SerialNumber()
sl@10
   140
        {
sl@10
   141
            IntPtr ptr = MiniDisplaySerialNumber(iDevice);
sl@10
   142
            string str = Marshal.PtrToStringUni(ptr);
sl@10
   143
            return str;
sl@10
   144
        }
sl@4
   145
sl@12
   146
        public string DeviceId()
sl@12
   147
        {
sl@12
   148
            IntPtr ptr = MiniDisplayDeviceId(iDevice);
sl@12
   149
            string str = Marshal.PtrToStringAnsi(ptr);
sl@12
   150
            return str;
sl@12
   151
        }
sl@12
   152
sl@12
   153
        public string FirmwareRevision()
sl@12
   154
        {
sl@12
   155
            IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
sl@12
   156
            string str = Marshal.PtrToStringAnsi(ptr);
sl@12
   157
            return str;
sl@12
   158
        }
sl@12
   159
sl@3
   160
        //Our display device handle
sl@3
   161
        IntPtr iDevice;
sl@3
   162
sl@39
   163
        public enum TMiniDisplayType
sl@39
   164
        {
sl@39
   165
            EMiniDisplayAutoDetect, /*Not yet implemented*/
sl@39
   166
            EMiniDisplayFutabaGP1212A01,
sl@39
   167
            EMiniDisplayFutabaGP1212A02
sl@39
   168
        };
sl@39
   169
sl@39
   170
sl@10
   171
        public enum TMiniDisplayRequest
sl@10
   172
        {
sl@10
   173
            EMiniDisplayRequestNone,
sl@10
   174
            EMiniDisplayRequestDeviceId,
sl@10
   175
            EMiniDisplayRequestFirmwareRevision,
sl@10
   176
            EMiniDisplayRequestPowerSupplyStatus
sl@39
   177
        };
sl@10
   178
sl@3
   179
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@39
   180
        public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
sl@3
   181
sl@3
   182
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   183
        public static extern void MiniDisplayClose(IntPtr aDevice);
sl@3
   184
sl@3
   185
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   186
        public static extern void MiniDisplayClear(IntPtr aDevice);
sl@3
   187
sl@3
   188
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   189
        public static extern void MiniDisplayFill(IntPtr aDevice);
sl@3
   190
sl@3
   191
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   192
        public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
sl@3
   193
sl@3
   194
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   195
        public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
sl@3
   196
sl@3
   197
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   198
        public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
sl@3
   199
sl@3
   200
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   201
        public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
sl@3
   202
sl@4
   203
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   204
        public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
sl@4
   205
sl@4
   206
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   207
        public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
sl@4
   208
sl@4
   209
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   210
        public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
sl@4
   211
sl@10
   212
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   213
        public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
sl@10
   214
sl@10
   215
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   216
        public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
sl@10
   217
sl@10
   218
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   219
        public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
sl@10
   220
sl@10
   221
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   222
        public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
sl@10
   223
sl@10
   224
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   225
        public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
sl@10
   226
sl@10
   227
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@12
   228
        [return: MarshalAs(UnmanagedType.I1)]
sl@10
   229
        public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
sl@10
   230
sl@10
   231
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   232
        public static extern void MiniDisplayRequestDeviceId(IntPtr aDevice);
sl@10
   233
sl@10
   234
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   235
        public static extern void MiniDisplayRequestFirmwareRevision(IntPtr aDevice);
sl@10
   236
sl@10
   237
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   238
        public static extern void MiniDisplayRequestPowerSupplyStatus(IntPtr aDevice);
sl@10
   239
sl@10
   240
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   241
        public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
sl@10
   242
sl@10
   243
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   244
        public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
sl@10
   245
sl@10
   246
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   247
        public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
sl@10
   248
sl@10
   249
sl@3
   250
    }
sl@3
   251
}