Display.cs
author sl
Wed, 09 Jul 2014 11:06:46 +0200
changeset 11 de55741d90f0
parent 6 70b26a1ae93b
child 12 f37c5ff8af18
permissions -rw-r--r--
Fixing string measurement issues. Font dialog now properly initialized with
loaded font.
     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()
    22         {
    23             if (iDevice == IntPtr.Zero)
    24             {
    25                 iDevice = MiniDisplayOpen();
    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 string Vendor()
    89         {
    90             IntPtr ptr = MiniDisplayVendor(iDevice);
    91             string str = Marshal.PtrToStringUni(ptr);
    92             return str;
    93         }
    94 
    95         public string Product()
    96         {
    97             IntPtr ptr = MiniDisplayProduct(iDevice);
    98             string str = Marshal.PtrToStringUni(ptr);
    99             return str;
   100         }
   101 
   102         public string SerialNumber()
   103         {
   104             IntPtr ptr = MiniDisplaySerialNumber(iDevice);
   105             string str = Marshal.PtrToStringUni(ptr);
   106             return str;
   107         }
   108 
   109         //Our display device handle
   110         IntPtr iDevice;
   111 
   112         public enum TMiniDisplayRequest
   113         {
   114             EMiniDisplayRequestNone,
   115             EMiniDisplayRequestDeviceId,
   116             EMiniDisplayRequestFirmwareRevision,
   117             EMiniDisplayRequestPowerSupplyStatus
   118         }
   119 
   120         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   121         public static extern IntPtr MiniDisplayOpen();
   122 
   123         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   124         public static extern void MiniDisplayClose(IntPtr aDevice);
   125 
   126         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   127         public static extern void MiniDisplayClear(IntPtr aDevice);
   128 
   129         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   130         public static extern void MiniDisplayFill(IntPtr aDevice);
   131 
   132         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   133         public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
   134 
   135         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   136         public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
   137 
   138         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   139         public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
   140 
   141         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   142         public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
   143 
   144         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   145         public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
   146 
   147         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   148         public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
   149 
   150         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   151         public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
   152 
   153         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   154         public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
   155 
   156         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   157         public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
   158 
   159         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   160         public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
   161 
   162         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   163         public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
   164 
   165         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   166         public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
   167 
   168         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   169         public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
   170 
   171         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   172         public static extern void MiniDisplayRequestDeviceId(IntPtr aDevice);
   173 
   174         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   175         public static extern void MiniDisplayRequestFirmwareRevision(IntPtr aDevice);
   176 
   177         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   178         public static extern void MiniDisplayRequestPowerSupplyStatus(IntPtr aDevice);
   179 
   180         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   181         public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
   182 
   183         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   184         public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
   185 
   186         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   187         public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
   188 
   189 
   190         
   191         
   192 
   193 
   194     }
   195 }