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