Making App tab the last one again.
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 int IconCount(TMiniDisplayIconType aIcon)
208 return MiniDisplayIconCount(iDevice,aIcon);
211 public int IconStatusCount(TMiniDisplayIconType aIcon)
213 return MiniDisplayIconStatusCount(iDevice, aIcon);
216 public void SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus)
218 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, aStatus);
221 public void SetIconOn(TMiniDisplayIconType aIcon, int aIndex)
223 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, IconStatusCount(aIcon) - 1);
226 public void SetIconOff(TMiniDisplayIconType aIcon, int aIndex)
228 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, 0);
232 public void SetAllIconsStatus(int aStatus)
234 foreach (TMiniDisplayIconType icon in Enum.GetValues(typeof(TMiniDisplayIconType)))
236 int count=IconCount(icon);
237 for (int i = 0; i < count; i++)
239 SetIconStatus(icon,i,aStatus);
246 /// Set all elements of an icon to the given status.
248 /// <param name="aIcon"></param>
249 /// <param name="aStatus"></param>
250 public void SetIconStatus(TMiniDisplayIconType aIcon, int aStatus)
252 int iconCount = IconCount(aIcon);
253 for (int i = 0; i < iconCount; i++)
255 SetIconStatus(aIcon, i, aStatus);
260 /// Set all elements of an icon to be either on or off.
262 /// <param name="aIcon"></param>
263 /// <param name="aOn"></param>
264 public void SetIconOnOff(TMiniDisplayIconType aIcon, bool aOn)
277 /// Set all elements of an icon to there maximum status.
279 /// <param name="aIcon"></param>
280 public void SetIconOn(TMiniDisplayIconType aIcon)
282 int iconCount = IconCount(aIcon);
283 for (int i = 0; i < iconCount; i++)
285 SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
290 /// Turn off all elements of an icon.
292 /// <param name="aIcon"></param>
293 public void SetIconOff(TMiniDisplayIconType aIcon)
295 int iconCount = IconCount(aIcon);
296 for (int i = 0; i < iconCount; i++)
298 SetIconStatus(aIcon, i, 0);
304 public string Vendor()
306 IntPtr ptr = MiniDisplayVendor(iDevice);
307 string str = Marshal.PtrToStringUni(ptr);
311 public string Product()
313 IntPtr ptr = MiniDisplayProduct(iDevice);
314 string str = Marshal.PtrToStringUni(ptr);
318 public string SerialNumber()
320 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
321 string str = Marshal.PtrToStringUni(ptr);
325 public string DeviceId()
327 IntPtr ptr = MiniDisplayDeviceId(iDevice);
328 string str = Marshal.PtrToStringAnsi(ptr);
332 public string FirmwareRevision()
334 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
335 string str = Marshal.PtrToStringAnsi(ptr);
340 public enum TMiniDisplayType
342 EMiniDisplayAutoDetect, /*Not yet implemented*/
343 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
344 EMiniDisplayFutabaGP1212A01,
345 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
346 EMiniDisplayFutabaGP1212A02
352 public enum TMiniDisplayRequest
354 EMiniDisplayRequestNone,
355 EMiniDisplayRequestDeviceId,
356 EMiniDisplayRequestFirmwareRevision,
357 EMiniDisplayRequestPowerSupplyStatus
362 /// Define the various type of icons we support.
363 /// For binary compatibility new entries must be added at the end.
365 public enum TMiniDisplayIconType
367 EMiniDisplayIconNetworkSignal=0,
368 EMiniDisplayIconInternet,
369 EMiniDisplayIconEmail,
370 EMiniDisplayIconMute,
371 EMiniDisplayIconVolume,
372 EMiniDisplayIconVolumeLabel,
373 EMiniDisplayIconPlay,
374 EMiniDisplayIconPause,
375 EMiniDisplayIconRecording
378 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
379 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
381 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
382 public static extern void MiniDisplayClose(IntPtr aDevice);
384 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
385 public static extern int MiniDisplayTypeCount();
387 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
388 public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
390 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
391 public static extern void MiniDisplayClear(IntPtr aDevice);
393 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
394 public static extern void MiniDisplayFill(IntPtr aDevice);
396 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
397 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
399 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
400 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
402 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
403 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
405 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
406 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
408 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
409 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
411 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
412 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
414 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
415 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
417 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
418 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
420 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
421 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
423 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
424 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
426 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
427 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
429 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
430 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
432 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
433 [return: MarshalAs(UnmanagedType.I1)]
434 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
436 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
437 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
439 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
440 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
442 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
443 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
445 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
446 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
448 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
449 public static extern void MiniDisplayPowerOn(IntPtr aDevice);
451 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
452 public static extern void MiniDisplayPowerOff(IntPtr aDevice);
454 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
455 [return: MarshalAs(UnmanagedType.I1)]
456 public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
458 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
459 public static extern void MiniDisplayShowClock(IntPtr aDevice);
461 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
462 public static extern void MiniDisplayHideClock(IntPtr aDevice);
464 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
465 [return: MarshalAs(UnmanagedType.I1)]
466 public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
468 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
469 public static extern int MiniDisplayIconCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
471 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
472 public static extern int MiniDisplayIconStatusCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
474 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
475 public static extern void MiniDisplaySetIconStatus(IntPtr aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus);