Timer interval can now be set and is persisted.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
7 using System.Runtime.InteropServices;
8 //using System.Runtime.Serialization;
10 namespace SharpDisplayManager
14 /// Provide access to our display hardware through MiniDisplay API.
22 iDevice = IntPtr.Zero;
26 public bool Open(TMiniDisplayType aType)
28 if (iDevice == IntPtr.Zero)
30 iDevice = MiniDisplayOpen(aType);
32 return iDevice != IntPtr.Zero;
37 MiniDisplayClose(iDevice);
38 iDevice = IntPtr.Zero;
43 return iDevice != IntPtr.Zero;
48 MiniDisplayClear(iDevice);
53 MiniDisplayFill(iDevice);
56 public void SwapBuffers()
58 MiniDisplaySwapBuffers(iDevice);
61 public int MaxBrightness()
63 return MiniDisplayMaxBrightness(iDevice);
66 public int MinBrightness()
68 return MiniDisplayMinBrightness(iDevice);
71 public void SetBrightness(int aBrightness)
73 if (!IsOpen()) return;
75 MiniDisplaySetBrightness(iDevice, aBrightness);
78 public int WidthInPixels()
80 return MiniDisplayWidthInPixels(iDevice);
83 public int HeightInPixels()
85 return MiniDisplayHeightInPixels(iDevice);
88 public void SetPixel(int aX, int aY, int aValue)
90 MiniDisplaySetPixel(iDevice,aX,aY,aValue);
93 public void RequestPowerSupplyStatus()
95 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
98 public void RequestDeviceId()
100 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
103 public void RequestFirmwareRevision()
105 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
108 public bool PowerSupplyStatus()
110 bool res = MiniDisplayPowerSupplyStatus(iDevice);
114 public TMiniDisplayRequest AttemptRequestCompletion()
116 return MiniDisplayAttemptRequestCompletion(iDevice);
119 public TMiniDisplayRequest CurrentRequest()
121 return MiniDisplayCurrentRequest(iDevice);
124 public bool IsRequestPending()
126 return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
130 public string Vendor()
132 IntPtr ptr = MiniDisplayVendor(iDevice);
133 string str = Marshal.PtrToStringUni(ptr);
137 public string Product()
139 IntPtr ptr = MiniDisplayProduct(iDevice);
140 string str = Marshal.PtrToStringUni(ptr);
144 public string SerialNumber()
146 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
147 string str = Marshal.PtrToStringUni(ptr);
151 public string DeviceId()
153 IntPtr ptr = MiniDisplayDeviceId(iDevice);
154 string str = Marshal.PtrToStringAnsi(ptr);
158 public string FirmwareRevision()
160 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
161 string str = Marshal.PtrToStringAnsi(ptr);
165 //Our display device handle
170 public enum TMiniDisplayType
172 EMiniDisplayAutoDetect, /*Not yet implemented*/
173 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
174 EMiniDisplayFutabaGP1212A01,
175 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
176 EMiniDisplayFutabaGP1212A02
180 public enum TMiniDisplayRequest
182 EMiniDisplayRequestNone,
183 EMiniDisplayRequestDeviceId,
184 EMiniDisplayRequestFirmwareRevision,
185 EMiniDisplayRequestPowerSupplyStatus
188 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
189 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
191 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
192 public static extern void MiniDisplayClose(IntPtr aDevice);
194 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
195 public static extern void MiniDisplayClear(IntPtr aDevice);
197 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
198 public static extern void MiniDisplayFill(IntPtr aDevice);
200 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
201 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
203 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
204 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
206 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
207 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
209 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
210 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
212 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
213 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
215 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
216 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
218 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
219 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
221 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
222 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
224 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
225 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
227 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
228 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
230 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
231 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
233 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
234 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
236 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
237 [return: MarshalAs(UnmanagedType.I1)]
238 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
240 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
241 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
243 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
244 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
246 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
247 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
249 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
250 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);