Server/Display.cs
author sl
Mon, 13 Oct 2014 19:24:30 +0200
changeset 66 a02bd242f219
parent 53 f7ad2dce46a9
child 104 189aac7dd3d6
permissions -rw-r--r--
Adding bitmap field object.
     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, uint 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 void PowerOn()
   109         {
   110             MiniDisplayPowerOn(iDevice);
   111         }
   112 
   113         public void PowerOff()
   114         {
   115             MiniDisplayPowerOff(iDevice);
   116         }
   117 
   118         public bool SupportPowerOnOff()
   119         {
   120             return MiniDisplaySupportPowerOnOff(iDevice);
   121         }
   122 
   123         public void ShowClock()
   124         {
   125             MiniDisplayShowClock(iDevice);
   126         }
   127 
   128         public void HideClock()
   129         {
   130             MiniDisplayHideClock(iDevice);
   131         }
   132 
   133         public bool SupportClock()
   134         {
   135             return MiniDisplaySupportClock(iDevice);
   136         }
   137 
   138         public bool PowerSupplyStatus()
   139         {
   140             bool res = MiniDisplayPowerSupplyStatus(iDevice);
   141             return res;
   142         }
   143 
   144         public TMiniDisplayRequest AttemptRequestCompletion()
   145         {
   146             return MiniDisplayAttemptRequestCompletion(iDevice);
   147         }
   148 
   149         public TMiniDisplayRequest CurrentRequest()
   150         {
   151             return MiniDisplayCurrentRequest(iDevice);
   152         }
   153 
   154         public bool IsRequestPending()
   155         {
   156             return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
   157         }
   158 
   159 
   160         public string Vendor()
   161         {
   162             IntPtr ptr = MiniDisplayVendor(iDevice);
   163             string str = Marshal.PtrToStringUni(ptr);
   164             return str;
   165         }
   166 
   167         public string Product()
   168         {
   169             IntPtr ptr = MiniDisplayProduct(iDevice);
   170             string str = Marshal.PtrToStringUni(ptr);
   171             return str;
   172         }
   173 
   174         public string SerialNumber()
   175         {
   176             IntPtr ptr = MiniDisplaySerialNumber(iDevice);
   177             string str = Marshal.PtrToStringUni(ptr);
   178             return str;
   179         }
   180 
   181         public string DeviceId()
   182         {
   183             IntPtr ptr = MiniDisplayDeviceId(iDevice);
   184             string str = Marshal.PtrToStringAnsi(ptr);
   185             return str;
   186         }
   187 
   188         public string FirmwareRevision()
   189         {
   190             IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
   191             string str = Marshal.PtrToStringAnsi(ptr);
   192             return str;
   193         }
   194 
   195         //Our display device handle
   196         IntPtr iDevice;
   197 
   198 
   199         //[Serializable]
   200         public enum TMiniDisplayType
   201         {
   202             EMiniDisplayAutoDetect, /*Not yet implemented*/
   203             //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
   204             EMiniDisplayFutabaGP1212A01,
   205             //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
   206             EMiniDisplayFutabaGP1212A02
   207         };
   208 
   209 
   210         public enum TMiniDisplayRequest
   211         {
   212             EMiniDisplayRequestNone,
   213             EMiniDisplayRequestDeviceId,
   214             EMiniDisplayRequestFirmwareRevision,
   215             EMiniDisplayRequestPowerSupplyStatus
   216         };
   217 
   218         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   219         public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
   220 
   221         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   222         public static extern void MiniDisplayClose(IntPtr aDevice);
   223 
   224         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   225         public static extern void MiniDisplayClear(IntPtr aDevice);
   226 
   227         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   228         public static extern void MiniDisplayFill(IntPtr aDevice);
   229 
   230         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   231         public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
   232 
   233         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   234         public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
   235 
   236         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   237         public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
   238 
   239         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   240         public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
   241 
   242         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   243         public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
   244 
   245         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   246         public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
   247 
   248         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   249         public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
   250 
   251         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   252         public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
   253 
   254         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   255         public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
   256 
   257         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   258         public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
   259 
   260         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   261         public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
   262 
   263         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   264         public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
   265 
   266         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   267         [return: MarshalAs(UnmanagedType.I1)]
   268         public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
   269 
   270         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   271         public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
   272 
   273         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   274         public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
   275 
   276         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   277         public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
   278 
   279         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   280         public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
   281 
   282         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   283         public static extern void MiniDisplayPowerOn(IntPtr aDevice);
   284 
   285         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   286         public static extern void MiniDisplayPowerOff(IntPtr aDevice);
   287 
   288         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   289         [return: MarshalAs(UnmanagedType.I1)]
   290         public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
   291 
   292         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   293         public static extern void MiniDisplayShowClock(IntPtr aDevice);
   294 
   295         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   296         public static extern void MiniDisplayHideClock(IntPtr aDevice);
   297 
   298         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   299         [return: MarshalAs(UnmanagedType.I1)]
   300         public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
   301 
   302 
   303     }
   304 }