sl@3
|
1 |
using System;
|
sl@3
|
2 |
using System.Collections.Generic;
|
sl@3
|
3 |
using System.Linq;
|
sl@3
|
4 |
using System.Text;
|
sl@3
|
5 |
using System.Threading.Tasks;
|
sl@3
|
6 |
//
|
sl@3
|
7 |
using System.Runtime.InteropServices;
|
sl@46
|
8 |
//using System.Runtime.Serialization;
|
sl@3
|
9 |
|
sl@3
|
10 |
namespace SharpDisplayManager
|
sl@3
|
11 |
{
|
sl@46
|
12 |
|
sl@44
|
13 |
/// <summary>
|
sl@44
|
14 |
/// Provide access to our display hardware through MiniDisplay API.
|
sl@44
|
15 |
/// </summary>
|
sl@46
|
16 |
public class Display
|
sl@3
|
17 |
{
|
sl@3
|
18 |
|
sl@3
|
19 |
//Constructor
|
sl@3
|
20 |
public Display()
|
sl@3
|
21 |
{
|
sl@3
|
22 |
iDevice = IntPtr.Zero;
|
sl@3
|
23 |
}
|
sl@3
|
24 |
|
sl@3
|
25 |
//
|
sl@39
|
26 |
public bool Open(TMiniDisplayType aType)
|
sl@3
|
27 |
{
|
sl@3
|
28 |
if (iDevice == IntPtr.Zero)
|
sl@3
|
29 |
{
|
sl@39
|
30 |
iDevice = MiniDisplayOpen(aType);
|
sl@3
|
31 |
}
|
sl@3
|
32 |
return iDevice != IntPtr.Zero;
|
sl@3
|
33 |
}
|
sl@3
|
34 |
|
sl@3
|
35 |
public void Close()
|
sl@3
|
36 |
{
|
sl@3
|
37 |
MiniDisplayClose(iDevice);
|
sl@3
|
38 |
iDevice = IntPtr.Zero;
|
sl@3
|
39 |
}
|
sl@3
|
40 |
|
sl@3
|
41 |
public bool IsOpen()
|
sl@3
|
42 |
{
|
sl@3
|
43 |
return iDevice != IntPtr.Zero;
|
sl@3
|
44 |
}
|
sl@3
|
45 |
|
sl@3
|
46 |
public void Clear()
|
sl@3
|
47 |
{
|
sl@3
|
48 |
MiniDisplayClear(iDevice);
|
sl@3
|
49 |
}
|
sl@3
|
50 |
|
sl@3
|
51 |
public void Fill()
|
sl@3
|
52 |
{
|
sl@3
|
53 |
MiniDisplayFill(iDevice);
|
sl@3
|
54 |
}
|
sl@3
|
55 |
|
sl@3
|
56 |
public void SwapBuffers()
|
sl@3
|
57 |
{
|
sl@3
|
58 |
MiniDisplaySwapBuffers(iDevice);
|
sl@3
|
59 |
}
|
sl@3
|
60 |
|
sl@3
|
61 |
public int MaxBrightness()
|
sl@3
|
62 |
{
|
sl@3
|
63 |
return MiniDisplayMaxBrightness(iDevice);
|
sl@3
|
64 |
}
|
sl@3
|
65 |
|
sl@3
|
66 |
public int MinBrightness()
|
sl@3
|
67 |
{
|
sl@3
|
68 |
return MiniDisplayMinBrightness(iDevice);
|
sl@3
|
69 |
}
|
sl@3
|
70 |
|
sl@3
|
71 |
public void SetBrightness(int aBrightness)
|
sl@3
|
72 |
{
|
sl@3
|
73 |
if (!IsOpen()) return;
|
sl@3
|
74 |
|
sl@3
|
75 |
MiniDisplaySetBrightness(iDevice, aBrightness);
|
sl@3
|
76 |
}
|
sl@3
|
77 |
|
sl@4
|
78 |
public int WidthInPixels()
|
sl@4
|
79 |
{
|
sl@4
|
80 |
return MiniDisplayWidthInPixels(iDevice);
|
sl@4
|
81 |
}
|
sl@4
|
82 |
|
sl@4
|
83 |
public int HeightInPixels()
|
sl@4
|
84 |
{
|
sl@4
|
85 |
return MiniDisplayHeightInPixels(iDevice);
|
sl@4
|
86 |
}
|
sl@4
|
87 |
|
sl@4
|
88 |
public void SetPixel(int aX, int aY, int aValue)
|
sl@4
|
89 |
{
|
sl@4
|
90 |
MiniDisplaySetPixel(iDevice,aX,aY,aValue);
|
sl@4
|
91 |
}
|
sl@4
|
92 |
|
sl@12
|
93 |
public void RequestPowerSupplyStatus()
|
sl@12
|
94 |
{
|
sl@44
|
95 |
MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus);
|
sl@12
|
96 |
}
|
sl@12
|
97 |
|
sl@12
|
98 |
public void RequestDeviceId()
|
sl@12
|
99 |
{
|
sl@44
|
100 |
MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestDeviceId);
|
sl@12
|
101 |
}
|
sl@12
|
102 |
|
sl@12
|
103 |
public void RequestFirmwareRevision()
|
sl@12
|
104 |
{
|
sl@44
|
105 |
MiniDisplayRequest(iDevice, TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision);
|
sl@12
|
106 |
}
|
sl@12
|
107 |
|
sl@12
|
108 |
public bool PowerSupplyStatus()
|
sl@12
|
109 |
{
|
sl@12
|
110 |
bool res = MiniDisplayPowerSupplyStatus(iDevice);
|
sl@12
|
111 |
return res;
|
sl@12
|
112 |
}
|
sl@12
|
113 |
|
sl@12
|
114 |
public TMiniDisplayRequest AttemptRequestCompletion()
|
sl@12
|
115 |
{
|
sl@12
|
116 |
return MiniDisplayAttemptRequestCompletion(iDevice);
|
sl@12
|
117 |
}
|
sl@12
|
118 |
|
sl@12
|
119 |
public TMiniDisplayRequest CurrentRequest()
|
sl@12
|
120 |
{
|
sl@12
|
121 |
return MiniDisplayCurrentRequest(iDevice);
|
sl@12
|
122 |
}
|
sl@12
|
123 |
|
sl@12
|
124 |
public bool IsRequestPending()
|
sl@12
|
125 |
{
|
sl@12
|
126 |
return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
|
sl@12
|
127 |
}
|
sl@12
|
128 |
|
sl@12
|
129 |
|
sl@10
|
130 |
public string Vendor()
|
sl@10
|
131 |
{
|
sl@10
|
132 |
IntPtr ptr = MiniDisplayVendor(iDevice);
|
sl@10
|
133 |
string str = Marshal.PtrToStringUni(ptr);
|
sl@10
|
134 |
return str;
|
sl@10
|
135 |
}
|
sl@4
|
136 |
|
sl@10
|
137 |
public string Product()
|
sl@10
|
138 |
{
|
sl@10
|
139 |
IntPtr ptr = MiniDisplayProduct(iDevice);
|
sl@10
|
140 |
string str = Marshal.PtrToStringUni(ptr);
|
sl@10
|
141 |
return str;
|
sl@10
|
142 |
}
|
sl@10
|
143 |
|
sl@10
|
144 |
public string SerialNumber()
|
sl@10
|
145 |
{
|
sl@10
|
146 |
IntPtr ptr = MiniDisplaySerialNumber(iDevice);
|
sl@10
|
147 |
string str = Marshal.PtrToStringUni(ptr);
|
sl@10
|
148 |
return str;
|
sl@10
|
149 |
}
|
sl@4
|
150 |
|
sl@12
|
151 |
public string DeviceId()
|
sl@12
|
152 |
{
|
sl@12
|
153 |
IntPtr ptr = MiniDisplayDeviceId(iDevice);
|
sl@12
|
154 |
string str = Marshal.PtrToStringAnsi(ptr);
|
sl@12
|
155 |
return str;
|
sl@12
|
156 |
}
|
sl@12
|
157 |
|
sl@12
|
158 |
public string FirmwareRevision()
|
sl@12
|
159 |
{
|
sl@12
|
160 |
IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
|
sl@12
|
161 |
string str = Marshal.PtrToStringAnsi(ptr);
|
sl@12
|
162 |
return str;
|
sl@12
|
163 |
}
|
sl@12
|
164 |
|
sl@3
|
165 |
//Our display device handle
|
sl@3
|
166 |
IntPtr iDevice;
|
sl@3
|
167 |
|
sl@46
|
168 |
|
sl@46
|
169 |
//[Serializable]
|
sl@39
|
170 |
public enum TMiniDisplayType
|
sl@39
|
171 |
{
|
sl@39
|
172 |
EMiniDisplayAutoDetect, /*Not yet implemented*/
|
sl@46
|
173 |
//[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
|
sl@39
|
174 |
EMiniDisplayFutabaGP1212A01,
|
sl@46
|
175 |
//[EnumMember(Value = "EMiniDisplayFutabaGP1212A01")]
|
sl@39
|
176 |
EMiniDisplayFutabaGP1212A02
|
sl@39
|
177 |
};
|
sl@39
|
178 |
|
sl@39
|
179 |
|
sl@10
|
180 |
public enum TMiniDisplayRequest
|
sl@10
|
181 |
{
|
sl@10
|
182 |
EMiniDisplayRequestNone,
|
sl@10
|
183 |
EMiniDisplayRequestDeviceId,
|
sl@10
|
184 |
EMiniDisplayRequestFirmwareRevision,
|
sl@10
|
185 |
EMiniDisplayRequestPowerSupplyStatus
|
sl@39
|
186 |
};
|
sl@10
|
187 |
|
sl@3
|
188 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@39
|
189 |
public static extern IntPtr MiniDisplayOpen(TMiniDisplayType aType);
|
sl@3
|
190 |
|
sl@3
|
191 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
192 |
public static extern void MiniDisplayClose(IntPtr aDevice);
|
sl@3
|
193 |
|
sl@3
|
194 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
195 |
public static extern void MiniDisplayClear(IntPtr aDevice);
|
sl@3
|
196 |
|
sl@3
|
197 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
198 |
public static extern void MiniDisplayFill(IntPtr aDevice);
|
sl@3
|
199 |
|
sl@3
|
200 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
201 |
public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
|
sl@3
|
202 |
|
sl@3
|
203 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
204 |
public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
|
sl@3
|
205 |
|
sl@3
|
206 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
207 |
public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
|
sl@3
|
208 |
|
sl@3
|
209 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@3
|
210 |
public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
|
sl@3
|
211 |
|
sl@4
|
212 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@4
|
213 |
public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
|
sl@4
|
214 |
|
sl@4
|
215 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@4
|
216 |
public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
|
sl@4
|
217 |
|
sl@4
|
218 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@4
|
219 |
public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
|
sl@4
|
220 |
|
sl@10
|
221 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
222 |
public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
|
sl@10
|
223 |
|
sl@10
|
224 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
225 |
public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
|
sl@10
|
226 |
|
sl@10
|
227 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
228 |
public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
|
sl@10
|
229 |
|
sl@10
|
230 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
231 |
public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
|
sl@10
|
232 |
|
sl@10
|
233 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
234 |
public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
|
sl@10
|
235 |
|
sl@10
|
236 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@12
|
237 |
[return: MarshalAs(UnmanagedType.I1)]
|
sl@10
|
238 |
public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
|
sl@10
|
239 |
|
sl@10
|
240 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@44
|
241 |
public static extern void MiniDisplayRequest(IntPtr aDevice, TMiniDisplayRequest aRequest);
|
sl@10
|
242 |
|
sl@10
|
243 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
244 |
public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
|
sl@10
|
245 |
|
sl@10
|
246 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
247 |
public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
|
sl@10
|
248 |
|
sl@10
|
249 |
[DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
sl@10
|
250 |
public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
|
sl@10
|
251 |
|
sl@10
|
252 |
|
sl@3
|
253 |
}
|
sl@3
|
254 |
}
|