MiniDisplay DLL update providing support for MDM166AA.
Published new version.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
7 using System.Runtime.InteropServices;
8 //using System.Runtime.Serialization;
10 namespace SharpDisplayManager
15 /// Provide access to our display hardware through MiniDisplay API.
19 public delegate void OnOpenedHandler(Display aDisplay);
20 public event OnOpenedHandler OnOpened;
22 public delegate void OnClosedHandler(Display aDisplay);
23 public event OnClosedHandler OnClosed;
25 //Our display device handle
29 public static int TypeCount()
31 return MiniDisplayTypeCount();
34 public static string TypeName(TMiniDisplayType aType)
36 IntPtr ptr = MiniDisplayTypeName(aType);
37 string str = Marshal.PtrToStringUni(ptr);
44 iDevice = IntPtr.Zero;
48 public bool Open(TMiniDisplayType aType)
52 //Already open return an error
56 iDevice = MiniDisplayOpen(aType);
58 bool success = iDevice != IntPtr.Zero;
61 //Broadcast opened event
76 //Controversially clearing our screen before closing
77 //Consider moving this up into the UI layer
81 MiniDisplayClose(iDevice);
82 iDevice = IntPtr.Zero;
83 //Broadcast closed event
89 return iDevice != IntPtr.Zero;
94 MiniDisplayClear(iDevice);
99 MiniDisplayFill(iDevice);
102 public void SwapBuffers()
104 MiniDisplaySwapBuffers(iDevice);
107 public int MaxBrightness()
109 return MiniDisplayMaxBrightness(iDevice);
112 public int MinBrightness()
114 return MiniDisplayMinBrightness(iDevice);
117 public void SetBrightness(int aBrightness)
119 if (!IsOpen()) return;
121 MiniDisplaySetBrightness(iDevice, aBrightness);
124 public int WidthInPixels()
126 return MiniDisplayWidthInPixels(iDevice);
129 public int HeightInPixels()
131 return MiniDisplayHeightInPixels(iDevice);
134 public void SetPixel(int aX, int aY, uint aValue)
136 MiniDisplaySetPixel(iDevice,aX,aY,aValue);
139 public void RequestPowerSupplyStatus()
141 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
144 public void RequestDeviceId()
146 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
149 public void RequestFirmwareRevision()
151 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
154 public void PowerOn()
156 MiniDisplayPowerOn(iDevice);
159 public void PowerOff()
161 MiniDisplayPowerOff(iDevice);
164 public bool SupportPowerOnOff()
166 return MiniDisplaySupportPowerOnOff(iDevice);
169 public void ShowClock()
171 MiniDisplayShowClock(iDevice);
174 public void HideClock()
176 MiniDisplayHideClock(iDevice);
179 public bool SupportClock()
181 return MiniDisplaySupportClock(iDevice);
184 public bool PowerSupplyStatus()
186 bool res = MiniDisplayPowerSupplyStatus(iDevice);
190 public TMiniDisplayRequest AttemptRequestCompletion()
192 return MiniDisplayAttemptRequestCompletion(iDevice);
195 public TMiniDisplayRequest CurrentRequest()
197 return MiniDisplayCurrentRequest(iDevice);
200 public bool IsRequestPending()
202 return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
206 public string Vendor()
208 IntPtr ptr = MiniDisplayVendor(iDevice);
209 string str = Marshal.PtrToStringUni(ptr);
213 public string Product()
215 IntPtr ptr = MiniDisplayProduct(iDevice);
216 string str = Marshal.PtrToStringUni(ptr);
220 public string SerialNumber()
222 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
223 string str = Marshal.PtrToStringUni(ptr);
227 public string DeviceId()
229 IntPtr ptr = MiniDisplayDeviceId(iDevice);
230 string str = Marshal.PtrToStringAnsi(ptr);
234 public string FirmwareRevision()
236 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
237 string str = Marshal.PtrToStringAnsi(ptr);
242 public enum TMiniDisplayType
244 EMiniDisplayAutoDetect, /*Not yet implemented*/
245 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
246 EMiniDisplayFutabaGP1212A01,
247 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
248 EMiniDisplayFutabaGP1212A02
252 public enum TMiniDisplayRequest
254 EMiniDisplayRequestNone,
255 EMiniDisplayRequestDeviceId,
256 EMiniDisplayRequestFirmwareRevision,
257 EMiniDisplayRequestPowerSupplyStatus
260 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
261 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
263 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
264 public static extern void MiniDisplayClose(IntPtr aDevice);
266 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
267 public static extern int MiniDisplayTypeCount();
269 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
270 public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
272 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
273 public static extern void MiniDisplayClear(IntPtr aDevice);
275 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
276 public static extern void MiniDisplayFill(IntPtr aDevice);
278 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
279 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
281 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
282 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
284 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
285 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
287 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
288 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
290 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
291 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
293 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
294 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
296 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
297 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
299 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
300 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
302 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
303 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
305 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
306 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
308 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
309 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
311 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
312 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
314 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
315 [return: MarshalAs(UnmanagedType.I1)]
316 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
318 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
319 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
321 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
322 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
324 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
325 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
327 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
328 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
330 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
331 public static extern void MiniDisplayPowerOn(IntPtr aDevice);
333 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
334 public static extern void MiniDisplayPowerOff(IntPtr aDevice);
336 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
337 [return: MarshalAs(UnmanagedType.I1)]
338 public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
340 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
341 public static extern void MiniDisplayShowClock(IntPtr aDevice);
343 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
344 public static extern void MiniDisplayHideClock(IntPtr aDevice);
346 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
347 [return: MarshalAs(UnmanagedType.I1)]
348 public static extern bool MiniDisplaySupportClock(IntPtr aDevice);