sl@3: 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: sl@3: namespace SharpDisplayManager sl@3: { sl@46: sl@44: /// sl@44: /// Provide access to our display hardware through MiniDisplay API. sl@44: /// sl@46: public class Display sl@3: { sl@3: sl@3: //Constructor sl@3: public Display() sl@3: { sl@3: iDevice = IntPtr.Zero; sl@3: } sl@3: sl@3: // sl@39: public bool Open(TMiniDisplayType aType) sl@3: { sl@3: if (iDevice == IntPtr.Zero) sl@3: { sl@39: iDevice = MiniDisplayOpen(aType); sl@3: } sl@3: return iDevice != IntPtr.Zero; sl@3: } sl@3: sl@3: public void Close() sl@3: { sl@3: MiniDisplayClose(iDevice); sl@3: iDevice = IntPtr.Zero; 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: { sl@3: MiniDisplayClear(iDevice); sl@3: } sl@3: sl@3: public void Fill() sl@3: { sl@3: MiniDisplayFill(iDevice); sl@3: } sl@3: sl@3: public void SwapBuffers() sl@3: { sl@3: MiniDisplaySwapBuffers(iDevice); sl@3: } sl@3: sl@3: public int MaxBrightness() sl@3: { sl@3: return MiniDisplayMaxBrightness(iDevice); sl@3: } sl@3: sl@3: public int MinBrightness() sl@3: { sl@3: return MiniDisplayMinBrightness(iDevice); sl@3: } sl@3: sl@3: public void SetBrightness(int aBrightness) sl@3: { sl@3: if (!IsOpen()) return; sl@3: sl@3: MiniDisplaySetBrightness(iDevice, aBrightness); sl@3: } sl@3: sl@4: public int WidthInPixels() sl@4: { sl@4: return MiniDisplayWidthInPixels(iDevice); sl@4: } sl@4: sl@4: public int HeightInPixels() sl@4: { sl@4: return MiniDisplayHeightInPixels(iDevice); sl@4: } sl@4: sl@4: public void SetPixel(int aX, int aY, int aValue) sl@4: { sl@4: MiniDisplaySetPixel(iDevice,aX,aY,aValue); sl@4: } sl@4: sl@12: public void RequestPowerSupplyStatus() sl@12: { sl@44: MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus); sl@12: } sl@12: sl@12: public void RequestDeviceId() sl@12: { sl@44: MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId); sl@12: } sl@12: sl@12: public void RequestFirmwareRevision() sl@12: { sl@44: MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision); sl@12: } sl@12: sl@52: public void PowerOn() sl@52: { sl@52: MiniDisplayPowerOn(iDevice); sl@52: } sl@52: sl@52: public void PowerOff() sl@52: { sl@52: MiniDisplayPowerOff(iDevice); sl@52: } sl@52: sl@52: public bool SupportPowerOnOff() sl@52: { sl@52: return MiniDisplaySupportPowerOnOff(iDevice); sl@52: } sl@52: sl@53: public void ShowClock() sl@53: { sl@53: MiniDisplayShowClock(iDevice); sl@53: } sl@53: sl@53: public void HideClock() sl@53: { sl@53: MiniDisplayHideClock(iDevice); sl@53: } sl@53: sl@53: public bool SupportClock() sl@53: { sl@53: return MiniDisplaySupportClock(iDevice); sl@53: } sl@53: sl@12: public bool PowerSupplyStatus() sl@12: { sl@12: bool res = MiniDisplayPowerSupplyStatus(iDevice); sl@12: return res; sl@12: } sl@12: sl@12: public TMiniDisplayRequest AttemptRequestCompletion() sl@12: { sl@12: return MiniDisplayAttemptRequestCompletion(iDevice); sl@12: } sl@12: sl@12: public TMiniDisplayRequest CurrentRequest() sl@12: { sl@12: return MiniDisplayCurrentRequest(iDevice); sl@12: } sl@12: sl@12: public bool IsRequestPending() sl@12: { sl@12: return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone; sl@12: } sl@12: sl@12: sl@10: public string Vendor() sl@10: { sl@10: IntPtr ptr = MiniDisplayVendor(iDevice); sl@10: string str = Marshal.PtrToStringUni(ptr); sl@10: return str; sl@10: } sl@4: sl@10: public string Product() sl@10: { sl@10: IntPtr ptr = MiniDisplayProduct(iDevice); sl@10: string str = Marshal.PtrToStringUni(ptr); sl@10: return str; sl@10: } sl@10: sl@10: public string SerialNumber() sl@10: { sl@10: IntPtr ptr = MiniDisplaySerialNumber(iDevice); sl@10: string str = Marshal.PtrToStringUni(ptr); sl@10: return str; sl@10: } sl@4: sl@12: public string DeviceId() sl@12: { sl@12: IntPtr ptr = MiniDisplayDeviceId(iDevice); sl@12: string str = Marshal.PtrToStringAnsi(ptr); sl@12: return str; sl@12: } sl@12: sl@12: public string FirmwareRevision() sl@12: { sl@12: IntPtr ptr = MiniDisplayFirmwareRevision(iDevice); sl@12: string str = Marshal.PtrToStringAnsi(ptr); sl@12: return str; sl@12: } sl@12: sl@3: //Our display device handle sl@3: IntPtr iDevice; sl@3: sl@46: sl@46: //[Serializable] sl@39: public enum TMiniDisplayType sl@39: { sl@39: EMiniDisplayAutoDetect, /*Not yet implemented*/ sl@46: //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")] sl@39: EMiniDisplayFutabaGP1212A01, sl@46: //[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")] sl@39: EMiniDisplayFutabaGP1212A02 sl@39: }; sl@39: sl@39: sl@10: public enum TMiniDisplayRequest sl@10: { sl@10: EMiniDisplayRequestNone, sl@10: EMiniDisplayRequestDeviceId, sl@10: EMiniDisplayRequestFirmwareRevision, sl@10: EMiniDisplayRequestPowerSupplyStatus sl@39: }; sl@10: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@39: public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern void MiniDisplayClose(IntPtr aDevice); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern void MiniDisplayClear(IntPtr aDevice); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern void MiniDisplayFill(IntPtr aDevice); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern void MiniDisplaySwapBuffers(IntPtr aDevice); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern int MiniDisplayMinBrightness(IntPtr aDevice); sl@3: sl@3: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@3: public static extern int MiniDisplayMaxBrightness(IntPtr aDevice); sl@3: sl@4: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern int MiniDisplayWidthInPixels(IntPtr aDevice); sl@4: sl@4: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern int MiniDisplayHeightInPixels(IntPtr aDevice); sl@4: sl@4: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@4: public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue); sl@4: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern IntPtr MiniDisplayVendor(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern IntPtr MiniDisplayProduct(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@12: [return: MarshalAs(UnmanagedType.I1)] sl@10: public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@44: public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice); sl@10: sl@10: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@10: public static extern void MiniDisplayCancelRequest(IntPtr aDevice); sl@10: sl@52: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@52: public static extern void MiniDisplayPowerOn(IntPtr aDevice); sl@52: sl@52: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@52: public static extern void MiniDisplayPowerOff(IntPtr aDevice); sl@52: sl@52: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@52: [return: MarshalAs(UnmanagedType.I1)] sl@52: public static extern bool MiniDisplaySupportPowerOnOff(IntPtr aDevice); sl@10: sl@53: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@53: public static extern void MiniDisplayShowClock(IntPtr aDevice); sl@53: sl@53: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@53: public static extern void MiniDisplayHideClock(IntPtr aDevice); sl@53: sl@53: [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] sl@53: [return: MarshalAs(UnmanagedType.I1)] sl@53: public static extern bool MiniDisplaySupportClock(IntPtr aDevice); sl@53: sl@53: sl@3: } sl@3: }