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