StephaneLenclud@123: //
StephaneLenclud@123: // Copyright (C) 2014-2015 Stéphane Lenclud.
StephaneLenclud@123: //
StephaneLenclud@123: // This file is part of SharpDisplayManager.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is free software: you can redistribute it and/or modify
StephaneLenclud@123: // it under the terms of the GNU General Public License as published by
StephaneLenclud@123: // the Free Software Foundation, either version 3 of the License, or
StephaneLenclud@123: // (at your option) any later version.
StephaneLenclud@123: //
StephaneLenclud@123: // SharpDisplayManager is distributed in the hope that it will be useful,
StephaneLenclud@123: // but WITHOUT ANY WARRANTY; without even the implied warranty of
StephaneLenclud@123: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
StephaneLenclud@123: // GNU General Public License for more details.
StephaneLenclud@123: //
StephaneLenclud@123: // You should have received a copy of the GNU General Public License
StephaneLenclud@123: // along with SharpDisplayManager. If not, see .
StephaneLenclud@123: //
StephaneLenclud@123:
StephaneLenclud@123: using System;
sl@3: using System.Collections.Generic;
sl@3: using System.Linq;
sl@3: using System.Text;
sl@3: using System.Threading.Tasks;
sl@3: //
sl@3: using System.Runtime.InteropServices;
sl@46: //using System.Runtime.Serialization;
sl@3:
StephaneLenclud@135: using MiniDisplayInterop;
StephaneLenclud@135:
sl@3: namespace SharpDisplayManager
sl@3: {
sl@46:
StephaneLenclud@104:
sl@44: ///
sl@44: /// Provide access to our display hardware through MiniDisplay API.
sl@44: ///
sl@46: public class Display
sl@3: {
StephaneLenclud@104: public delegate void OnOpenedHandler(Display aDisplay);
StephaneLenclud@104: public event OnOpenedHandler OnOpened;
StephaneLenclud@104:
StephaneLenclud@104: public delegate void OnClosedHandler(Display aDisplay);
StephaneLenclud@104: public event OnClosedHandler OnClosed;
StephaneLenclud@104:
StephaneLenclud@104: //Our display device handle
StephaneLenclud@104: IntPtr iDevice;
StephaneLenclud@104:
StephaneLenclud@104: //static functions
StephaneLenclud@104: public static int TypeCount()
StephaneLenclud@104: {
StephaneLenclud@135: return MiniDisplay.TypeCount();
StephaneLenclud@104: }
StephaneLenclud@104:
StephaneLenclud@135: public static string TypeName(MiniDisplay.Type aType)
StephaneLenclud@104: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.TypeName(aType);
StephaneLenclud@104: string str = Marshal.PtrToStringUni(ptr);
StephaneLenclud@104: return str;
StephaneLenclud@104: }
sl@3:
sl@3: //Constructor
sl@3: public Display()
sl@3: {
sl@3: iDevice = IntPtr.Zero;
sl@3: }
sl@3:
sl@3: //
StephaneLenclud@135: public bool Open(MiniDisplay.Type aType)
sl@3: {
StephaneLenclud@104: if (IsOpen())
StephaneLenclud@104: {
StephaneLenclud@104: //Already open return an error
StephaneLenclud@104: return false;
StephaneLenclud@104: }
StephaneLenclud@104:
StephaneLenclud@135: iDevice = MiniDisplay.Open(aType);
StephaneLenclud@104:
StephaneLenclud@104: bool success = iDevice != IntPtr.Zero;
StephaneLenclud@104: if (success)
StephaneLenclud@104: {
StephaneLenclud@104: //Broadcast opened event
StephaneLenclud@104: OnOpened(this);
StephaneLenclud@104: }
StephaneLenclud@104:
StephaneLenclud@104: return success;
sl@3: }
sl@3:
sl@3: public void Close()
sl@3: {
StephaneLenclud@104: if (!IsOpen())
StephaneLenclud@104: {
StephaneLenclud@104: //Pointless
StephaneLenclud@104: return;
StephaneLenclud@104: }
StephaneLenclud@104:
StephaneLenclud@105: //
StephaneLenclud@135: MiniDisplay.Close(iDevice);
sl@3: iDevice = IntPtr.Zero;
StephaneLenclud@104: //Broadcast closed event
StephaneLenclud@104: OnClosed(this);
sl@3: }
sl@3:
sl@3: public bool IsOpen()
sl@3: {
sl@3: return iDevice != IntPtr.Zero;
sl@3: }
sl@3:
sl@3: public void Clear()
sl@3: {
StephaneLenclud@135: MiniDisplay.Clear(iDevice);
sl@3: }
sl@3:
sl@3: public void Fill()
sl@3: {
StephaneLenclud@135: MiniDisplay.Fill(iDevice);
sl@3: }
sl@3:
sl@3: public void SwapBuffers()
sl@3: {
StephaneLenclud@135: MiniDisplay.SwapBuffers(iDevice);
sl@3: }
sl@3:
sl@3: public int MaxBrightness()
sl@3: {
StephaneLenclud@135: return MiniDisplay.MaxBrightness(iDevice);
sl@3: }
sl@3:
sl@3: public int MinBrightness()
sl@3: {
StephaneLenclud@135: return MiniDisplay.MinBrightness(iDevice);
sl@3: }
sl@3:
sl@3: public void SetBrightness(int aBrightness)
sl@3: {
sl@3: if (!IsOpen()) return;
sl@3:
StephaneLenclud@135: MiniDisplay.SetBrightness(iDevice, aBrightness);
sl@3: }
sl@3:
sl@4: public int WidthInPixels()
sl@4: {
StephaneLenclud@135: return MiniDisplay.WidthInPixels(iDevice);
sl@4: }
sl@4:
sl@4: public int HeightInPixels()
sl@4: {
StephaneLenclud@135: return MiniDisplay.HeightInPixels(iDevice);
sl@4: }
sl@4:
sl@57: public void SetPixel(int aX, int aY, uint aValue)
sl@4: {
StephaneLenclud@135: MiniDisplay.SetPixel(iDevice,aX,aY,aValue);
sl@4: }
sl@4:
sl@12: public void RequestPowerSupplyStatus()
sl@12: {
StephaneLenclud@135: MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.PowerSupplyStatus);
sl@12: }
sl@12:
sl@12: public void RequestDeviceId()
sl@12: {
StephaneLenclud@135: MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.DeviceId);
sl@12: }
sl@12:
sl@12: public void RequestFirmwareRevision()
sl@12: {
StephaneLenclud@135: MiniDisplay.SendRequest(iDevice, MiniDisplay.Request.FirmwareRevision);
sl@12: }
sl@12:
sl@52: public void PowerOn()
sl@52: {
StephaneLenclud@135: MiniDisplay.PowerOn(iDevice);
sl@52: }
sl@52:
sl@52: public void PowerOff()
sl@52: {
StephaneLenclud@135: MiniDisplay.PowerOff(iDevice);
sl@52: }
sl@52:
sl@52: public bool SupportPowerOnOff()
sl@52: {
StephaneLenclud@135: return MiniDisplay.SupportPowerOnOff(iDevice);
sl@52: }
sl@52:
sl@53: public void ShowClock()
sl@53: {
StephaneLenclud@135: MiniDisplay.ShowClock(iDevice);
sl@53: }
sl@53:
sl@53: public void HideClock()
sl@53: {
StephaneLenclud@135: MiniDisplay.HideClock(iDevice);
sl@53: }
sl@53:
sl@53: public bool SupportClock()
sl@53: {
StephaneLenclud@135: return MiniDisplay.SupportClock(iDevice);
sl@53: }
sl@53:
sl@12: public bool PowerSupplyStatus()
sl@12: {
StephaneLenclud@135: bool res = MiniDisplay.PowerSupplyStatus(iDevice);
sl@12: return res;
sl@12: }
sl@12:
StephaneLenclud@135: public MiniDisplay.Request AttemptRequestCompletion()
sl@12: {
StephaneLenclud@135: return MiniDisplay.AttemptRequestCompletion(iDevice);
sl@12: }
sl@12:
StephaneLenclud@135: public MiniDisplay.Request CurrentRequest()
sl@12: {
StephaneLenclud@135: return MiniDisplay.CurrentRequest(iDevice);
sl@12: }
sl@12:
sl@12: public bool IsRequestPending()
sl@12: {
StephaneLenclud@135: return CurrentRequest() != MiniDisplay.Request.None;
sl@12: }
sl@12:
StephaneLenclud@108: //
StephaneLenclud@135: public int IconCount(MiniDisplay.IconType aIcon)
StephaneLenclud@108: {
StephaneLenclud@135: return MiniDisplay.IconCount(iDevice,aIcon);
StephaneLenclud@108: }
StephaneLenclud@108:
StephaneLenclud@135: public int IconStatusCount(MiniDisplay.IconType aIcon)
StephaneLenclud@108: {
StephaneLenclud@135: return MiniDisplay.IconStatusCount(iDevice, aIcon);
StephaneLenclud@108: }
StephaneLenclud@108:
StephaneLenclud@135: public void SetIconStatus(MiniDisplay.IconType aIcon, int aIndex, int aStatus)
StephaneLenclud@108: {
StephaneLenclud@135: MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, aStatus);
StephaneLenclud@108: }
StephaneLenclud@108:
StephaneLenclud@135: public void SetIconOn(MiniDisplay.IconType aIcon, int aIndex)
StephaneLenclud@118: {
StephaneLenclud@135: MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, IconStatusCount(aIcon) - 1);
StephaneLenclud@118: }
StephaneLenclud@118:
StephaneLenclud@135: public void SetIconOff(MiniDisplay.IconType aIcon, int aIndex)
StephaneLenclud@118: {
StephaneLenclud@135: MiniDisplay.SetIconStatus(iDevice, aIcon, aIndex, 0);
StephaneLenclud@118: }
StephaneLenclud@118:
StephaneLenclud@118:
StephaneLenclud@109: public void SetAllIconsStatus(int aStatus)
StephaneLenclud@108: {
StephaneLenclud@135: foreach (MiniDisplay.IconType icon in Enum.GetValues(typeof(MiniDisplay.IconType)))
StephaneLenclud@109: {
StephaneLenclud@109: int count=IconCount(icon);
StephaneLenclud@109: for (int i = 0; i < count; i++)
StephaneLenclud@109: {
StephaneLenclud@109: SetIconStatus(icon,i,aStatus);
StephaneLenclud@109: }
StephaneLenclud@109: }
StephaneLenclud@108: }
StephaneLenclud@108:
StephaneLenclud@115: ///
StephaneLenclud@116: /// Set all elements of an icon to the given status.
StephaneLenclud@115: ///
StephaneLenclud@115: ///
StephaneLenclud@115: ///
StephaneLenclud@135: public void SetIconStatus(MiniDisplay.IconType aIcon, int aStatus)
StephaneLenclud@115: {
StephaneLenclud@115: int iconCount = IconCount(aIcon);
StephaneLenclud@115: for (int i = 0; i < iconCount; i++)
StephaneLenclud@115: {
StephaneLenclud@115: SetIconStatus(aIcon, i, aStatus);
StephaneLenclud@115: }
StephaneLenclud@115: }
StephaneLenclud@115:
StephaneLenclud@115: ///
StephaneLenclud@116: /// Set all elements of an icon to be either on or off.
StephaneLenclud@116: ///
StephaneLenclud@116: ///
StephaneLenclud@116: ///
StephaneLenclud@135: public void SetIconOnOff(MiniDisplay.IconType aIcon, bool aOn)
StephaneLenclud@116: {
StephaneLenclud@116: if (aOn)
StephaneLenclud@116: {
StephaneLenclud@116: SetIconOn(aIcon);
StephaneLenclud@116: }
StephaneLenclud@116: else
StephaneLenclud@116: {
StephaneLenclud@116: SetIconOff(aIcon);
StephaneLenclud@116: }
StephaneLenclud@116: }
StephaneLenclud@116:
StephaneLenclud@116: ///
StephaneLenclud@116: /// Set all elements of an icon to there maximum status.
StephaneLenclud@115: ///
StephaneLenclud@115: ///
StephaneLenclud@135: public void SetIconOn(MiniDisplay.IconType aIcon)
StephaneLenclud@115: {
StephaneLenclud@115: int iconCount = IconCount(aIcon);
StephaneLenclud@115: for (int i = 0; i < iconCount; i++)
StephaneLenclud@115: {
StephaneLenclud@115: SetIconStatus(aIcon, i, IconStatusCount(aIcon) - 1);
StephaneLenclud@115: }
StephaneLenclud@115: }
StephaneLenclud@115:
StephaneLenclud@115: ///
StephaneLenclud@116: /// Turn off all elements of an icon.
StephaneLenclud@115: ///
StephaneLenclud@115: ///
StephaneLenclud@135: public void SetIconOff(MiniDisplay.IconType aIcon)
StephaneLenclud@115: {
StephaneLenclud@115: int iconCount = IconCount(aIcon);
StephaneLenclud@115: for (int i = 0; i < iconCount; i++)
StephaneLenclud@115: {
StephaneLenclud@115: SetIconStatus(aIcon, i, 0);
StephaneLenclud@115: }
StephaneLenclud@115: }
StephaneLenclud@115:
StephaneLenclud@108:
sl@12:
sl@10: public string Vendor()
sl@10: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.Vendor(iDevice);
sl@10: string str = Marshal.PtrToStringUni(ptr);
sl@10: return str;
sl@10: }
sl@4:
sl@10: public string Product()
sl@10: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.Product(iDevice);
sl@10: string str = Marshal.PtrToStringUni(ptr);
sl@10: return str;
sl@10: }
sl@10:
sl@10: public string SerialNumber()
sl@10: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.SerialNumber(iDevice);
sl@10: string str = Marshal.PtrToStringUni(ptr);
sl@10: return str;
sl@10: }
sl@4:
sl@12: public string DeviceId()
sl@12: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.DeviceId(iDevice);
sl@12: string str = Marshal.PtrToStringAnsi(ptr);
sl@12: return str;
sl@12: }
sl@12:
sl@12: public string FirmwareRevision()
sl@12: {
StephaneLenclud@135: IntPtr ptr = MiniDisplay.FirmwareRevision(iDevice);
sl@12: string str = Marshal.PtrToStringAnsi(ptr);
sl@12: return str;
sl@12: }
sl@12:
sl@53:
sl@3: }
sl@3: }