Display.cs
author sl
Tue, 08 Jul 2014 18:59:07 +0200
changeset 8 5129c03ab7ba
parent 4 0825370a7947
child 10 54671755add3
permissions -rw-r--r--
Adding persistent settings and marquee separator.
     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 
    89 
    90         //Our display device handle
    91         IntPtr iDevice;
    92 
    93         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    94         public static extern IntPtr MiniDisplayOpen();
    95 
    96         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    97         public static extern void MiniDisplayClose(IntPtr aDevice);
    98 
    99         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   100         public static extern void MiniDisplayClear(IntPtr aDevice);
   101 
   102         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   103         public static extern void MiniDisplayFill(IntPtr aDevice);
   104 
   105         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   106         public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
   107 
   108         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   109         public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
   110 
   111         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   112         public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
   113 
   114         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   115         public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
   116 
   117         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   118         public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
   119 
   120         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   121         public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
   122 
   123         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   124         public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
   125 
   126 
   127     }
   128 }