MDM166AA: Adding support for volume label.
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 SetAllIconsStatus(int aStatus)
223 foreach (TMiniDisplayIconType icon in Enum.GetValues(typeof(TMiniDisplayIconType)))
225 int count=IconCount(icon);
226 for (int i = 0; i < count; i++)
228 SetIconStatus(icon,i,aStatus);
237 /// <param name="aIcon"></param>
238 /// <param name="aStatus"></param>
239 public void SetIconStatus(TMiniDisplayIconType aIcon, int aStatus)
241 int iconCount = IconCount(aIcon);
242 for (int i = 0; i < iconCount; i++)
244 SetIconStatus(aIcon, i, aStatus);
251 /// <param name="aIcon"></param>
252 public void SetIconOn(TMiniDisplayIconType aIcon)
254 int iconCount = IconCount(aIcon);
255 for (int i = 0; i < iconCount; i++)
257 SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
264 /// <param name="aIcon"></param>
265 public void SetIconOff(TMiniDisplayIconType aIcon)
267 int iconCount = IconCount(aIcon);
268 for (int i = 0; i < iconCount; i++)
270 SetIconStatus(aIcon, i, 0);
276 public string Vendor()
278 IntPtr ptr = MiniDisplayVendor(iDevice);
279 string str = Marshal.PtrToStringUni(ptr);
283 public string Product()
285 IntPtr ptr = MiniDisplayProduct(iDevice);
286 string str = Marshal.PtrToStringUni(ptr);
290 public string SerialNumber()
292 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
293 string str = Marshal.PtrToStringUni(ptr);
297 public string DeviceId()
299 IntPtr ptr = MiniDisplayDeviceId(iDevice);
300 string str = Marshal.PtrToStringAnsi(ptr);
304 public string FirmwareRevision()
306 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
307 string str = Marshal.PtrToStringAnsi(ptr);
312 public enum TMiniDisplayType
314 EMiniDisplayAutoDetect, /*Not yet implemented*/
315 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
316 EMiniDisplayFutabaGP1212A01,
317 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
318 EMiniDisplayFutabaGP1212A02
324 public enum TMiniDisplayRequest
326 EMiniDisplayRequestNone,
327 EMiniDisplayRequestDeviceId,
328 EMiniDisplayRequestFirmwareRevision,
329 EMiniDisplayRequestPowerSupplyStatus
334 /// Define the various type of icons we support.
335 /// For binary compatibility new entries must be added at the end.
337 public enum TMiniDisplayIconType
339 EMiniDisplayIconNetwork=0,
340 EMiniDisplayIconEmail,
341 EMiniDisplayIconMute,
342 EMiniDisplayIconVolume,
343 EMiniDisplayIconVolumeLabel,
344 EMiniDisplayIconPlay,
345 EMiniDisplayIconPause,
346 EMiniDisplayIconRecording
349 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
350 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
352 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
353 public static extern void MiniDisplayClose(IntPtr aDevice);
355 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
356 public static extern int MiniDisplayTypeCount();
358 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
359 public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
361 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
362 public static extern void MiniDisplayClear(IntPtr aDevice);
364 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
365 public static extern void MiniDisplayFill(IntPtr aDevice);
367 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
368 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
370 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
371 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
373 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
374 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
376 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
377 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
379 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
380 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
382 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
383 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
385 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
386 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
388 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
389 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
391 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
392 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
394 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
395 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
397 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
398 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
400 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
401 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
403 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
404 [return: MarshalAs(UnmanagedType.I1)]
405 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
407 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
408 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
410 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
411 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
413 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
414 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
416 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
417 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
419 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
420 public static extern void MiniDisplayPowerOn(IntPtr aDevice);
422 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
423 public static extern void MiniDisplayPowerOff(IntPtr aDevice);
425 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
426 [return: MarshalAs(UnmanagedType.I1)]
427 public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
429 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
430 public static extern void MiniDisplayShowClock(IntPtr aDevice);
432 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
433 public static extern void MiniDisplayHideClock(IntPtr aDevice);
435 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
436 [return: MarshalAs(UnmanagedType.I1)]
437 public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
439 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
440 public static extern int MiniDisplayIconCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
442 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
443 public static extern int MiniDisplayIconStatusCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
445 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
446 public static extern void MiniDisplaySetIconStatus(IntPtr aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus);