Adding missing source file.
Updating SharpLibHid.
Now Green Start works better when app in background.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
24 using System.Threading.Tasks;
26 using System.Runtime.InteropServices;
27 //using System.Runtime.Serialization;
29 namespace SharpDisplayManager
34 /// Provide access to our display hardware through MiniDisplay API.
38 public delegate void OnOpenedHandler(Display aDisplay);
39 public event OnOpenedHandler OnOpened;
41 public delegate void OnClosedHandler(Display aDisplay);
42 public event OnClosedHandler OnClosed;
44 //Our display device handle
48 public static int TypeCount()
50 return MiniDisplayTypeCount();
53 public static string TypeName(TMiniDisplayType aType)
55 IntPtr ptr = MiniDisplayTypeName(aType);
56 string str = Marshal.PtrToStringUni(ptr);
63 iDevice = IntPtr.Zero;
67 public bool Open(TMiniDisplayType aType)
71 //Already open return an error
75 iDevice = MiniDisplayOpen(aType);
77 bool success = iDevice != IntPtr.Zero;
80 //Broadcast opened event
96 MiniDisplayClose(iDevice);
97 iDevice = IntPtr.Zero;
98 //Broadcast closed event
104 return iDevice != IntPtr.Zero;
109 MiniDisplayClear(iDevice);
114 MiniDisplayFill(iDevice);
117 public void SwapBuffers()
119 MiniDisplaySwapBuffers(iDevice);
122 public int MaxBrightness()
124 return MiniDisplayMaxBrightness(iDevice);
127 public int MinBrightness()
129 return MiniDisplayMinBrightness(iDevice);
132 public void SetBrightness(int aBrightness)
134 if (!IsOpen()) return;
136 MiniDisplaySetBrightness(iDevice, aBrightness);
139 public int WidthInPixels()
141 return MiniDisplayWidthInPixels(iDevice);
144 public int HeightInPixels()
146 return MiniDisplayHeightInPixels(iDevice);
149 public void SetPixel(int aX, int aY, uint aValue)
151 MiniDisplaySetPixel(iDevice,aX,aY,aValue);
154 public void RequestPowerSupplyStatus()
156 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
159 public void RequestDeviceId()
161 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
164 public void RequestFirmwareRevision()
166 MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
169 public void PowerOn()
171 MiniDisplayPowerOn(iDevice);
174 public void PowerOff()
176 MiniDisplayPowerOff(iDevice);
179 public bool SupportPowerOnOff()
181 return MiniDisplaySupportPowerOnOff(iDevice);
184 public void ShowClock()
186 MiniDisplayShowClock(iDevice);
189 public void HideClock()
191 MiniDisplayHideClock(iDevice);
194 public bool SupportClock()
196 return MiniDisplaySupportClock(iDevice);
199 public bool PowerSupplyStatus()
201 bool res = MiniDisplayPowerSupplyStatus(iDevice);
205 public TMiniDisplayRequest AttemptRequestCompletion()
207 return MiniDisplayAttemptRequestCompletion(iDevice);
210 public TMiniDisplayRequest CurrentRequest()
212 return MiniDisplayCurrentRequest(iDevice);
215 public bool IsRequestPending()
217 return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
221 public int IconCount(TMiniDisplayIconType aIcon)
223 return MiniDisplayIconCount(iDevice,aIcon);
226 public int IconStatusCount(TMiniDisplayIconType aIcon)
228 return MiniDisplayIconStatusCount(iDevice, aIcon);
231 public void SetIconStatus(TMiniDisplayIconType aIcon, int aIndex, int aStatus)
233 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, aStatus);
236 public void SetIconOn(TMiniDisplayIconType aIcon, int aIndex)
238 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, IconStatusCount(aIcon) - 1);
241 public void SetIconOff(TMiniDisplayIconType aIcon, int aIndex)
243 MiniDisplaySetIconStatus(iDevice, aIcon, aIndex, 0);
247 public void SetAllIconsStatus(int aStatus)
249 foreach (TMiniDisplayIconType icon in Enum.GetValues(typeof(TMiniDisplayIconType)))
251 int count=IconCount(icon);
252 for (int i = 0; i < count; i++)
254 SetIconStatus(icon,i,aStatus);
260 /// Set all elements of an icon to the given status.
262 /// <param name="aIcon"></param>
263 /// <param name="aStatus"></param>
264 public void SetIconStatus(TMiniDisplayIconType aIcon, int aStatus)
266 int iconCount = IconCount(aIcon);
267 for (int i = 0; i < iconCount; i++)
269 SetIconStatus(aIcon, i, aStatus);
274 /// Set all elements of an icon to be either on or off.
276 /// <param name="aIcon"></param>
277 /// <param name="aOn"></param>
278 public void SetIconOnOff(TMiniDisplayIconType aIcon, bool aOn)
291 /// Set all elements of an icon to there maximum status.
293 /// <param name="aIcon"></param>
294 public void SetIconOn(TMiniDisplayIconType aIcon)
296 int iconCount = IconCount(aIcon);
297 for (int i = 0; i < iconCount; i++)
299 SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
304 /// Turn off all elements of an icon.
306 /// <param name="aIcon"></param>
307 public void SetIconOff(TMiniDisplayIconType aIcon)
309 int iconCount = IconCount(aIcon);
310 for (int i = 0; i < iconCount; i++)
312 SetIconStatus(aIcon, i, 0);
318 public string Vendor()
320 IntPtr ptr = MiniDisplayVendor(iDevice);
321 string str = Marshal.PtrToStringUni(ptr);
325 public string Product()
327 IntPtr ptr = MiniDisplayProduct(iDevice);
328 string str = Marshal.PtrToStringUni(ptr);
332 public string SerialNumber()
334 IntPtr ptr = MiniDisplaySerialNumber(iDevice);
335 string str = Marshal.PtrToStringUni(ptr);
339 public string DeviceId()
341 IntPtr ptr = MiniDisplayDeviceId(iDevice);
342 string str = Marshal.PtrToStringAnsi(ptr);
346 public string FirmwareRevision()
348 IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
349 string str = Marshal.PtrToStringAnsi(ptr);
354 public enum TMiniDisplayType
356 EMiniDisplayAutoDetect, /*Not yet implemented*/
357 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
358 EMiniDisplayFutabaGP1212A01,
359 //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
360 EMiniDisplayFutabaGP1212A02
366 public enum TMiniDisplayRequest
368 EMiniDisplayRequestNone,
369 EMiniDisplayRequestDeviceId,
370 EMiniDisplayRequestFirmwareRevision,
371 EMiniDisplayRequestPowerSupplyStatus
376 /// Define the various type of icons we support.
377 /// For binary compatibility new entries must be added at the end.
379 public enum TMiniDisplayIconType
381 EMiniDisplayIconNetworkSignal=0,
382 EMiniDisplayIconInternet,
383 EMiniDisplayIconEmail,
384 EMiniDisplayIconMute,
385 EMiniDisplayIconVolume,
386 EMiniDisplayIconVolumeLabel,
387 EMiniDisplayIconPlay,
388 EMiniDisplayIconPause,
389 EMiniDisplayIconRecording
392 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
393 public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
395 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
396 public static extern void MiniDisplayClose(IntPtr aDevice);
398 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
399 public static extern int MiniDisplayTypeCount();
401 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
402 public static extern IntPtr MiniDisplayTypeName(TMiniDisplayType aType);
404 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
405 public static extern void MiniDisplayClear(IntPtr aDevice);
407 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
408 public static extern void MiniDisplayFill(IntPtr aDevice);
410 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
411 public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
413 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
414 public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
416 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
417 public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
419 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
420 public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
422 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
423 public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
425 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
426 public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
428 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
429 public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, uint aValue);
431 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
432 public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
434 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
435 public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
437 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
438 public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
440 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
441 public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
443 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
444 public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
446 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
447 [return: MarshalAs(UnmanagedType.I1)]
448 public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
450 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
451 public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
453 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
454 public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
456 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
457 public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
459 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
460 public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
462 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
463 public static extern void MiniDisplayPowerOn(IntPtr aDevice);
465 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
466 public static extern void MiniDisplayPowerOff(IntPtr aDevice);
468 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
469 [return: MarshalAs(UnmanagedType.I1)]
470 public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice);
472 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
473 public static extern void MiniDisplayShowClock(IntPtr aDevice);
475 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
476 public static extern void MiniDisplayHideClock(IntPtr aDevice);
478 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
479 [return: MarshalAs(UnmanagedType.I1)]
480 public static extern bool MiniDisplaySupportClock(IntPtr aDevice);
482 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
483 public static extern int MiniDisplayIconCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
485 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
486 public static extern int MiniDisplayIconStatusCount(IntPtr aDevice, TMiniDisplayIconType aIcon);
488 [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
489 public static extern void MiniDisplaySetIconStatus(IntPtr aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus);