Server/Display.cs
author sl
Tue, 19 Aug 2014 21:26:17 +0200
changeset 37 405a2590eda4
parent 12 f37c5ff8af18
child 39 083f4935aae4
permissions -rw-r--r--
Font height now also checked on startup.
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@3
    21
        public bool Open()
sl@3
    22
        {
sl@3
    23
            if (iDevice == IntPtr.Zero)
sl@3
    24
            {
sl@6
    25
                iDevice = MiniDisplayOpen();
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@10
   163
        public enum TMiniDisplayRequest
sl@10
   164
        {
sl@10
   165
            EMiniDisplayRequestNone,
sl@10
   166
            EMiniDisplayRequestDeviceId,
sl@10
   167
            EMiniDisplayRequestFirmwareRevision,
sl@10
   168
            EMiniDisplayRequestPowerSupplyStatus
sl@10
   169
        }
sl@10
   170
sl@3
   171
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   172
        public static extern IntPtr MiniDisplayOpen();
sl@3
   173
sl@3
   174
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   175
        public static extern void MiniDisplayClose(IntPtr aDevice);
sl@3
   176
sl@3
   177
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   178
        public static extern void MiniDisplayClear(IntPtr aDevice);
sl@3
   179
sl@3
   180
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   181
        public static extern void MiniDisplayFill(IntPtr aDevice);
sl@3
   182
sl@3
   183
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   184
        public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
sl@3
   185
sl@3
   186
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   187
        public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
sl@3
   188
sl@3
   189
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   190
        public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
sl@3
   191
sl@3
   192
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@3
   193
        public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
sl@3
   194
sl@4
   195
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   196
        public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
sl@4
   197
sl@4
   198
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   199
        public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
sl@4
   200
sl@4
   201
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@4
   202
        public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
sl@4
   203
sl@10
   204
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   205
        public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
sl@10
   206
sl@10
   207
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   208
        public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
sl@10
   209
sl@10
   210
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   211
        public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
sl@10
   212
sl@10
   213
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   214
        public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
sl@10
   215
sl@10
   216
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   217
        public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
sl@10
   218
sl@10
   219
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@12
   220
        [return: MarshalAs(UnmanagedType.I1)]
sl@10
   221
        public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
sl@10
   222
sl@10
   223
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   224
        public static extern void MiniDisplayRequestDeviceId(IntPtr aDevice);
sl@10
   225
sl@10
   226
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   227
        public static extern void MiniDisplayRequestFirmwareRevision(IntPtr aDevice);
sl@10
   228
sl@10
   229
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   230
        public static extern void MiniDisplayRequestPowerSupplyStatus(IntPtr aDevice);
sl@10
   231
sl@10
   232
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   233
        public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
sl@10
   234
sl@10
   235
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   236
        public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
sl@10
   237
sl@10
   238
        [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
sl@10
   239
        public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
sl@10
   240
sl@10
   241
sl@3
   242
    }
sl@3
   243
}