Removing JSON type converter from ear manager.
Using bindings for some application settings.
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 using MiniDisplayInterop;
31 namespace SharpDisplayManager
36 /// Provide access to our display hardware through MiniDisplay API.
40 public delegate void OnOpenedHandler(Display aDisplay);
41 public event OnOpenedHandler OnOpened;
43 public delegate void OnClosedHandler(Display aDisplay);
44 public event OnClosedHandler OnClosed;
46 //Our display device handle
50 public static int TypeCount()
52 return MiniDisplay.TypeCount();
55 public static string TypeName(MiniDisplay.Type aType)
57 IntPtr ptr = MiniDisplay.TypeName(aType);
58 string str = Marshal.PtrToStringUni(ptr);
65 iDevice = IntPtr.Zero;
69 public bool Open(MiniDisplay.Type aType)
73 //Already open return an error
77 iDevice = MiniDisplay.Open(aType);
79 bool success = iDevice != IntPtr.Zero;
82 //Broadcast opened event
98 MiniDisplay.Close(iDevice);
99 iDevice = IntPtr.Zero;
100 //Broadcast closed event
106 return iDevice != IntPtr.Zero;
111 MiniDisplay.Clear(iDevice);
116 MiniDisplay.Fill(iDevice);
119 public void SwapBuffers()
121 MiniDisplay.SwapBuffers(iDevice);
124 public int MaxBrightness()
126 return MiniDisplay.MaxBrightness(iDevice);
129 public int MinBrightness()
131 return MiniDisplay.MinBrightness(iDevice);
134 public void SetBrightness(int aBrightness)
136 if (!IsOpen()) return;
138 MiniDisplay.SetBrightness(iDevice, aBrightness);
141 public int WidthInPixels()
143 return MiniDisplay.WidthInPixels(iDevice);
146 public int HeightInPixels()
148 return MiniDisplay.HeightInPixels(iDevice);
151 public void SetPixel(int aX, int aY, uint aValue)
153 MiniDisplay.SetPixel(iDevice,aX,aY,aValue);
156 public void RequestPowerSupplyStatus()
158 MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.PowerSupplyStatus);
161 public void RequestDeviceId()
163 MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.DeviceId);
166 public void RequestFirmwareRevision()
168 MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.FirmwareRevision);
171 public void PowerOn()
173 MiniDisplay.PowerOn(iDevice);
176 public void PowerOff()
178 MiniDisplay.PowerOff(iDevice);
181 public bool SupportPowerOnOff()
183 return MiniDisplay.SupportPowerOnOff(iDevice);
186 public void ShowClock()
188 MiniDisplay.ShowClock(iDevice);
191 public void HideClock()
193 MiniDisplay.HideClock(iDevice);
196 public bool SupportClock()
198 return MiniDisplay.SupportClock(iDevice);
201 public bool PowerSupplyStatus()
203 bool res = MiniDisplay.PowerSupplyStatus(iDevice);
207 public MiniDisplay.Request AttemptRequestCompletion()
209 return MiniDisplay.AttemptRequestCompletion(iDevice);
212 public MiniDisplay.Request CurrentRequest()
214 return MiniDisplay.CurrentRequest(iDevice);
217 public bool IsRequestPending()
219 return CurrentRequest() != MiniDisplay.Request.None;
223 public int IconCount(MiniDisplay.IconType aIcon)
225 return MiniDisplay.IconCount(iDevice,aIcon);
228 public int IconStatusCount(MiniDisplay.IconType aIcon)
230 return MiniDisplay.IconStatusCount(iDevice, aIcon);
233 public void SetIconStatus(MiniDisplay.IconType aIcon, int aIndex, int aStatus)
235 MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, aStatus);
238 public void SetIconOn(MiniDisplay.IconType aIcon, int aIndex)
240 MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, IconStatusCount(aIcon) - 1);
243 public void SetIconOff(MiniDisplay.IconType aIcon, int aIndex)
245 MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, 0);
249 public void SetAllIconsStatus(int aStatus)
251 foreach (MiniDisplay.IconType icon in Enum.GetValues(typeof(MiniDisplay.IconType)))
253 int count=IconCount(icon);
254 for (int i = 0; i < count; i++)
256 SetIconStatus(icon,i,aStatus);
262 /// Set all elements of an icon to the given status.
264 /// <param name="aIcon"></param>
265 /// <param name="aStatus"></param>
266 public void SetIconStatus(MiniDisplay.IconType aIcon, int aStatus)
268 int iconCount = IconCount(aIcon);
269 for (int i = 0; i < iconCount; i++)
271 SetIconStatus(aIcon, i, aStatus);
276 /// Set all elements of an icon to be either on or off.
278 /// <param name="aIcon"></param>
279 /// <param name="aOn"></param>
280 public void SetIconOnOff(MiniDisplay.IconType aIcon, bool aOn)
293 /// Set all elements of an icon to there maximum status.
295 /// <param name="aIcon"></param>
296 public void SetIconOn(MiniDisplay.IconType aIcon)
298 int iconCount = IconCount(aIcon);
299 for (int i = 0; i < iconCount; i++)
301 SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
306 /// Turn off all elements of an icon.
308 /// <param name="aIcon"></param>
309 public void SetIconOff(MiniDisplay.IconType aIcon)
311 int iconCount = IconCount(aIcon);
312 for (int i = 0; i < iconCount; i++)
314 SetIconStatus(aIcon, i, 0);
320 public string Vendor()
322 IntPtr ptr = MiniDisplay.Vendor(iDevice);
323 string str = Marshal.PtrToStringUni(ptr);
327 public string Product()
329 IntPtr ptr = MiniDisplay.Product(iDevice);
330 string str = Marshal.PtrToStringUni(ptr);
334 public string SerialNumber()
336 IntPtr ptr = MiniDisplay.SerialNumber(iDevice);
337 string str = Marshal.PtrToStringUni(ptr);
341 public string DeviceId()
343 IntPtr ptr = MiniDisplay.DeviceId(iDevice);
344 string str = Marshal.PtrToStringAnsi(ptr);
348 public string FirmwareRevision()
350 IntPtr ptr = MiniDisplay.FirmwareRevision(iDevice);
351 string str = Marshal.PtrToStringAnsi(ptr);