More consistent clock and clear support.
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
77 MiniDisplayClose(iDevice);
78 iDevice = IntPtr.Zero;
79 //Broadcast closed event
85 return iDevice != IntPtr.Zero;
90 MiniDisplayClear(iDevice);
95 MiniDisplayFill(iDevice);
98 public void SwapBuffers()
100 MiniDisplaySwapBuffers(iDevice);
103 public int MaxBrightness()
105 return MiniDisplayMaxBrightness(iDevice);
108 public int MinBrightness()
110 return MiniDisplayMinBrightness(iDevice);
113 public void SetBrightness(int aBrightness)
115 if (!IsOpen()) return;
117 MiniDisplaySetBrightness(iDevice, aBrightness);
120 public int WidthInPixels()
122 return MiniDisplayWidthInPixels(iDevice);
125 public int HeightInPixels()
127 return MiniDisplayHeightInPixels(iDevice);
130 public void SetPixel(int aX, int aY, uint aValue)
132 MiniDisplaySetPixel(iDevice,aX,aY,aValue);
135 public void RequestPowerSupplyStatus()
137 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
140 public void RequestDeviceId()
142 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
145 public void RequestFirmwareRevision()
147 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
150 public void PowerOn()
152 MiniDisplayPowerOn(iDevice);
155 public void PowerOff()
157 MiniDisplayPowerOff(iDevice);
160 public bool SupportPowerOnOff()
162 return MiniDisplaySupportPowerOnOff(iDevice);
165 public void ShowClock()
167 MiniDisplayShowClock(iDevice);
170 public void HideClock()
172 MiniDisplayHideClock(iDevice);
175 public bool SupportClock()
177 return MiniDisplaySupportClock(iDevice);
180 public bool PowerSupplyStatus()
182 bool res = MiniDisplayPowerSupplyStatus(iDevice);
186 public TMiniDisplayRequest AttemptRequestCompletion()
188 return MiniDisplayAttemptRequestCompletion(iDevice);
191 public TMiniDisplayRequest CurrentRequest()
193 return MiniDisplayCurrentRequest(iDevice);
196 public bool IsRequestPending()
198 return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
202 public int IconCount(TMiniDisplayIconType aIcon)
204 return MiniDisplayIconCount(iDevice,aIcon);
207 public int IconStatusCount(TMiniDisplayIconType aIcon)
209 return MiniDisplayIconStatusCount(iDevice, aIcon);
212 public void SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus)
214 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, aStatus);
217 public void SetIconOn(TMiniDisplayIconType aIcon, int aIndex)
219 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, IconStatusCount(aIcon) - 1);
222 public void SetIconOff(TMiniDisplayIconType aIcon, int aIndex)
224 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, 0);
228 public void SetAllIconsStatus(int aStatus)
230 foreach (TMiniDisplayIconType icon in Enum.GetValues(typeof(TMiniDisplayIconType)))
232 int count=IconCount(icon);
233 for (int i = 0; i < count; i++)
235 SetIconStatus(icon,i,aStatus);
241 /// Set all elements of an icon to the given status.
243 /// <param name="aIcon"></param>
244 /// <param name="aStatus"></param>
245 public void SetIconStatus(TMiniDisplayIconType aIcon, int aStatus)
247 int iconCount = IconCount(aIcon);
248 for (int i = 0; i < iconCount; i++)
250 SetIconStatus(aIcon, i, aStatus);
255 /// Set all elements of an icon to be either on or off.
257 /// <param name="aIcon"></param>
258 /// <param name="aOn"></param>
259 public void SetIconOnOff(TMiniDisplayIconType aIcon, bool aOn)
272 /// Set all elements of an icon to there maximum status.
274 /// <param name="aIcon"></param>
275 public void SetIconOn(TMiniDisplayIconType aIcon)
277 int iconCount = IconCount(aIcon);
278 for (int i = 0; i < iconCount; i++)
280 SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
285 /// Turn off all elements of an icon.
287 /// <param name="aIcon"></param>
288 public void SetIconOff(TMiniDisplayIconType aIcon)
290 int iconCount = IconCount(aIcon);
291 for (int i = 0; i < iconCount; i++)
293 SetIconStatus(aIcon, i, 0);
299 public string Vendor()
301 IntPtr ptr = MiniDisplayVendor(iDevice);
302 string str = Marshal.PtrToStringUni(ptr);
306 public string Product()
308 IntPtr ptr = MiniDisplayProduct(iDevice);
309 string str = Marshal.PtrToStringUni(ptr);
313 public string SerialNumber()
315 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
316 string str = Marshal.PtrToStringUni(ptr);
320 public string DeviceId()
322 IntPtr ptr = MiniDisplayDeviceId(iDevice);
323 string str = Marshal.PtrToStringAnsi(ptr);
327 public string FirmwareRevision()
329 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
330 string str = Marshal.PtrToStringAnsi(ptr);
335 public enum TMiniDisplayType
337 EMiniDisplayAutoDetect, /*Not yet implemented*/
338 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
339 EMiniDisplayFutabaGP1212A01,
340 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
341 EMiniDisplayFutabaGP1212A02
347 public enum TMiniDisplayRequest
349 EMiniDisplayRequestNone,
350 EMiniDisplayRequestDeviceId,
351 EMiniDisplayRequestFirmwareRevision,
352 EMiniDisplayRequestPowerSupplyStatus
357 /// Define the various type of icons we support.
358 /// For binary compatibility new entries must be added at the end.
360 public enum TMiniDisplayIconType
362 EMiniDisplayIconNetworkSignal=0,
363 EMiniDisplayIconInternet,
364 EMiniDisplayIconEmail,
365 EMiniDisplayIconMute,
366 EMiniDisplayIconVolume,
367 EMiniDisplayIconVolumeLabel,
368 EMiniDisplayIconPlay,
369 EMiniDisplayIconPause,
370 EMiniDisplayIconRecording
373 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
374 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
376 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
377 public static extern void MiniDisplayClose(IntPtr aDevice);
379 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
380 public static extern int MiniDisplayTypeCount();
382 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
383 public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
385 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
386 public static extern void MiniDisplayClear(IntPtr aDevice);
388 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
389 public static extern void MiniDisplayFill(IntPtr aDevice);
391 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
392 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
394 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
395 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
397 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
398 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
400 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
401 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
403 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
404 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
406 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
407 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
409 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
410 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
412 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
413 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
415 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
416 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
418 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
419 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
421 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
422 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
424 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
425 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
427 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
428 [return: MarshalAs(UnmanagedType.I1)]
429 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
431 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
432 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
434 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
435 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
437 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
438 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
440 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
441 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
443 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
444 public static extern void MiniDisplayPowerOn(IntPtr aDevice);
446 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
447 public static extern void MiniDisplayPowerOff(IntPtr aDevice);
449 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
450 [return: MarshalAs(UnmanagedType.I1)]
451 public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
453 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
454 public static extern void MiniDisplayShowClock(IntPtr aDevice);
456 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
457 public static extern void MiniDisplayHideClock(IntPtr aDevice);
459 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
460 [return: MarshalAs(UnmanagedType.I1)]
461 public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
463 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
464 public static extern int MiniDisplayIconCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
466 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
467 public static extern int MiniDisplayIconStatusCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
469 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
470 public static extern void MiniDisplaySetIconStatus(IntPtr aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus);