-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinproc.cs
303 lines (245 loc) · 8.78 KB
/
pinproc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// The MIT License
//
// Copyright (c) 2010 Adam Preble
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// C# wrapper for libpinproc (http://github.com/preble/libpinproc)
// Initial version written 10/31/2010 by Adam Preble
//
// To compile and run with Mono:
//
// gmcs pinproc.cs testmain.cs
// mono pinproc.exe
//
using System;
using System.Runtime.InteropServices;
namespace pinproc
{
public enum LogLevel {
Verbose = 0,
Info = 1,
Warning = 2,
Error = 3
};
public enum MachineType {
Invalid = 0,
Custom = 1,
WPCAlphanumeric = 2,
WPC = 3,
WPC95 = 4,
SternWhitestar = 5,
SternSAM = 6
};
public enum Result { Success = 1, Failure = 0 };
public enum EventType {
Invalid = 0,
SwitchClosedDebounced = 1,
SwitchOpenDebounced = 2,
SwitchClosedNondebounced = 3,
SwitchOpenNondebounced = 4,
DMDFrameDisplayed = 5
};
[StructLayout(LayoutKind.Sequential),Serializable]
public struct DriverGlobalConfig {
public bool EnableOutputs;
public bool GlobalPolarity;
public bool UseClear;
public bool StrobeStartSelect;
public byte StarStrobeTime;
public byte MatrixRowEnableIndex1;
public byte MatrixRowEnableIndex0;
public bool ActiveLowMatrixRows;
public bool EncodeEnables;
public bool TickleSternWatchdog;
public bool WatchdogExpired;
public bool WatchdogEnable;
public UInt16 WatchdogResetTime;
};
[StructLayout(LayoutKind.Sequential),Serializable]
public struct DriverGroupConfig {
public byte GroupNum;
public UInt16 SlowTime;
public byte EnableIndex;
public byte RowActivateIndex;
public byte RowEnableSelect;
public bool Matrixed;
public bool Polarity;
public bool Active;
public bool DisableStrobeAfter;
};
[StructLayout(LayoutKind.Sequential, Size=28),Serializable]
public struct DriverState {
public UInt16 DriverNum;
public byte OutputDriveTime;
public bool Polarity;
public bool State;
public bool WaitForFirstTimeSlot;
public UInt32 Timeslots;
public byte PatterOnTime;
public byte PatterOffTime;
public bool PatterEnable;
public override string ToString() { return string.Format("DriverState num={0}", DriverNum); }
};
// Status: Tested good.
[StructLayout(LayoutKind.Sequential, Size=12),Serializable]
public struct Event {
public EventType Type;
public UInt32 Value;
public UInt32 Time;
public override string ToString() { return string.Format("Event type={0} value={1}", Type, Value); }
};
[StructLayout(LayoutKind.Sequential),Serializable]
public struct SwitchConfig {
public bool Clear;
public bool HostEventsEnable;
public bool UseColumn9;
public bool UseColumn8;
public byte DirectMatrixScanLoopTime;
public byte PulsesBeforeCheckingRX;
public byte InactivePulsesAfterBurst;
public byte PulsesPerBurst;
public byte PulseHalfPeriodTime;
};
[StructLayout(LayoutKind.Sequential),Serializable]
public struct SwitchRule {
public bool ReloadActive;
public bool NotifyHost;
};
// Status: Partial test passed (only checked DeHighCycles)
[StructLayout(LayoutKind.Sequential, Size=60),Serializable]
public struct DMDConfig {
public byte NumRows;
public UInt16 NumColumns;
public byte NumSubFrames;
public byte NumFrameBuffers;
public bool AutoIncBufferWrPtr;
public bool EnableFrameEvents;
public bool Enable;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmanagedType.U1, SizeConst = 8)]
public Byte[] RclkLowCycles;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmanagedType.U1, SizeConst = 8)]
public Byte[] LatchHighCycles;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmanagedType.U2, SizeConst = 8)]
public UInt16[] DeHighCycles;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=UnmanagedType.U1, SizeConst = 8)]
public Byte[] DotclkHalfPeriod;
public DMDConfig(int columns, int rows)
{
this.AutoIncBufferWrPtr = true;
this.NumRows = (byte)rows;
this.NumColumns = (UInt16)columns;
this.NumSubFrames = 4;
this.NumFrameBuffers = 3;
this.Enable = true;
this.EnableFrameEvents = true;
this.RclkLowCycles = new byte[8];
this.LatchHighCycles = new byte[8];
this.DeHighCycles = new UInt16[8];
this.DotclkHalfPeriod = new byte[8];
for (int i = 0; i < 8; i++)
{
this.RclkLowCycles[i] = 15;
this.LatchHighCycles[i] = 15;
this.DotclkHalfPeriod[i] = 1;
}
// 60 fps timing:
this.DeHighCycles[0] = 90;
this.DeHighCycles[1] = 190;
this.DeHighCycles[2] = 50;
this.DeHighCycles[3] = 377;
}
};
/// <summary>
/// Container for libpinproc (via P/Invoke) methods.
/// </summary>
public abstract class PinProc
{
// General Methods //
// Status: Presumed good
[DllImport("libpinproc")]
public static extern void PRLogSetLevel(LogLevel level);
// Status: Good
[DllImport("libpinproc")]
public static extern string PRGetLastErrorText();
// Status: Good
[DllImport("libpinproc")]
public static extern IntPtr PRCreate(MachineType machineType);
// Status: Good
[DllImport("libpinproc")]
public static extern void PRDelete(IntPtr handle);
// Staus: Presumed good
[DllImport("libpinproc")]
public static extern Result PRReset(IntPtr handle, UInt32 flags);
// Status: Good
[DllImport("libpinproc")]
public static extern Result PRFlushWriteData(IntPtr handle);
// Driver Methods //
// Status: Presumed good
[DllImport("libpinproc")]
public static extern Result PRDriverWatchdogTickle(IntPtr handle);
// Status: Soft tested
[DllImport("libpinproc")]
public static extern Result PRDriverGetState(IntPtr handle, byte driverNum, ref DriverState driverState);
// Status: Soft tested
[DllImport("libpinproc")]
public static extern Result PRDriverUpdateState(IntPtr handle, ref DriverState driverState);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern Result PRDriverUpdateGlobalConfig(IntPtr handle, ref DriverGlobalConfig driverGlobalConfig);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern void PRDriverStateDisable(ref DriverState state);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern void PRDriverStatePulse(ref DriverState state, byte milliseconds);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern void PRDriverStateSchedule(ref DriverState state, UInt32 schedule, byte cycleSeconds, bool now);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern void PRDriverStatePatter(ref DriverState state, UInt16 millisecondsOn, UInt16 millisecondsOff, UInt16 originalOnTime);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern void PRDriverStatePulsedPatter(ref DriverState state, UInt16 millisecondsOn, UInt16 millisecondsOff, UInt16 patterTime);
// Status: Good
[DllImport("libpinproc")]
public static extern UInt16 PRDecode(MachineType machineType, string str);
// Switch & Event Methods //
// Status: Good
[DllImport("libpinproc")]
public static extern int PRGetEvents(IntPtr handle, [In, Out] Event[] events, int maxEvents);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern Result PRSwitchUpdateConfig(IntPtr handle, ref SwitchConfig switchConfig);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern Result PRSwitchUpdateRule(IntPtr handle, byte switchNum, EventType eventType, ref SwitchRule rule, DriverState[] linkedDrivers, int numDrivers);
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern Result PRSwitchGetStates(IntPtr handle, [In, Out] EventType[] switchStates, UInt16 numSwitches);
// DMD Methods //
// Status: UNTESTED
[DllImport("libpinproc")]
public static extern Result PRDMDDraw(IntPtr handle, byte[] dots);
// Status: Good
[DllImport("libpinproc")]
public static extern Result PRDMDUpdateConfig(IntPtr handle, ref DMDConfig config);
}
}