162 |
pfowler |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.Threading.Tasks;
|
|
|
6 |
using WindowsInput.Native;
|
|
|
7 |
|
|
|
8 |
namespace nitdcscore {
|
|
|
9 |
public class NitMultiPanel : Panel {
|
|
|
10 |
|
166 |
pfowler |
11 |
private mcp23017[] chips;
|
173 |
pfowler |
12 |
public byte ledShadow = 0x00;
|
172 |
pfowler |
13 |
|
166 |
pfowler |
14 |
public NitMultiPanel(mcp2221 mcp) : base(mcp) {
|
|
|
15 |
chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x24) };
|
162 |
pfowler |
16 |
|
|
|
17 |
this.Init();
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public override int Init() {
|
|
|
21 |
// Choose what function the number pad shall carry out:
|
|
|
22 |
// 0 = UFC #, 1 = F1-F12 Keys, 2 = Misc (+ TrackIR)
|
|
|
23 |
Switch3Pos selSwitch = new Switch3Pos(null, 2, 3);
|
|
|
24 |
|
|
|
25 |
// Row 1
|
|
|
26 |
Dictionary<uint, Command> pad01 = new Dictionary<uint, Command>();
|
164 |
pfowler |
27 |
pad01.Add(0, new CommandDCS("UFC_1"));
|
176 |
pfowler |
28 |
pad01.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F1));
|
162 |
pfowler |
29 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad01), 7));
|
|
|
30 |
|
|
|
31 |
Dictionary<uint, Command> pad02 = new Dictionary<uint, Command>();
|
164 |
pfowler |
32 |
pad02.Add(0, new CommandDCS("UFC_2"));
|
176 |
pfowler |
33 |
pad02.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F2));
|
177 |
pfowler |
34 |
pad02.Add(2, new CommandTrackIRKey(VirtualKeyCode.F7));
|
162 |
pfowler |
35 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad02), 6));
|
|
|
36 |
|
|
|
37 |
Dictionary<uint, Command> pad03 = new Dictionary<uint, Command>();
|
164 |
pfowler |
38 |
pad03.Add(0, new CommandDCS("UFC_3"));
|
176 |
pfowler |
39 |
pad03.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F3));
|
177 |
pfowler |
40 |
pad03.Add(2, new CommandTrackIRKey(VirtualKeyCode.F11));
|
162 |
pfowler |
41 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad03), 5));
|
|
|
42 |
|
|
|
43 |
Dictionary<uint, Command> pad04 = new Dictionary<uint,Command>();
|
|
|
44 |
pad04.Add(0, new CommandDCS("UFC_ENT"));
|
176 |
pfowler |
45 |
pad04.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F4));
|
177 |
pfowler |
46 |
pad04.Add(2, new CommandTrackIRKey(VirtualKeyCode.F9));
|
162 |
pfowler |
47 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad04), 4));
|
|
|
48 |
|
|
|
49 |
// Row 2
|
|
|
50 |
Dictionary<uint, Command> pad05 = new Dictionary<uint, Command>();
|
164 |
pfowler |
51 |
pad05.Add(0, new CommandDCS("UFC_4"));
|
176 |
pfowler |
52 |
pad05.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F5));
|
162 |
pfowler |
53 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad05), 11));
|
|
|
54 |
|
|
|
55 |
Dictionary<uint, Command> pad06 = new Dictionary<uint, Command>();
|
164 |
pfowler |
56 |
pad06.Add(0, new CommandDCS("UFC_5"));
|
176 |
pfowler |
57 |
pad06.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F6));
|
162 |
pfowler |
58 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad06), 10));
|
|
|
59 |
|
|
|
60 |
Dictionary<uint, Command> pad07 = new Dictionary<uint, Command>();
|
164 |
pfowler |
61 |
pad07.Add(0, new CommandDCS("UFC_6"));
|
176 |
pfowler |
62 |
pad07.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F7));
|
162 |
pfowler |
63 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad07), 9));
|
|
|
64 |
|
|
|
65 |
Dictionary<uint, Command> pad08 = new Dictionary<uint, Command>();
|
|
|
66 |
pad08.Add(0, new CommandDCS("UFC_10"));
|
176 |
pfowler |
67 |
pad08.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F8));
|
162 |
pfowler |
68 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad08), 8));
|
|
|
69 |
|
|
|
70 |
// Row 3
|
|
|
71 |
Dictionary<uint, Command> pad09 = new Dictionary<uint, Command>();
|
|
|
72 |
pad09.Add(0, new CommandDCS("UFC_7"));
|
176 |
pfowler |
73 |
pad09.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F9));
|
162 |
pfowler |
74 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad09), 15));
|
|
|
75 |
|
|
|
76 |
Dictionary<uint, Command> pad10 = new Dictionary<uint, Command>();
|
164 |
pfowler |
77 |
pad10.Add(0, new CommandDCS("UFC_8"));
|
176 |
pfowler |
78 |
pad10.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F10));
|
162 |
pfowler |
79 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad10), 14));
|
|
|
80 |
|
|
|
81 |
Dictionary<uint, Command> pad11 = new Dictionary<uint, Command>();
|
164 |
pfowler |
82 |
pad11.Add(0, new CommandDCS("UFC_9"));
|
176 |
pfowler |
83 |
pad11.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F11));
|
162 |
pfowler |
84 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad11), 13));
|
|
|
85 |
|
|
|
86 |
Dictionary<uint, Command> pad12 = new Dictionary<uint, Command>();
|
|
|
87 |
pad12.Add(0, new CommandDCS("UFC_CLR"));
|
176 |
pfowler |
88 |
pad12.Add(1, new CommandVKey(OSInput.VirtualKeyCodes.VK_F12));
|
162 |
pfowler |
89 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
|
|
|
90 |
|
166 |
pfowler |
91 |
// NMSP
|
|
|
92 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_EGI_BTN"), 16));
|
|
|
93 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_HARS_BTN"), 17));
|
|
|
94 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ILS_BTN"), 18));
|
|
|
95 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_TCN_BTN"), 19));
|
|
|
96 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ANCHR_BTN"), 20));
|
|
|
97 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_STEERPT_BTN"), 21));
|
|
|
98 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ABLE_STOW"), 22, true));
|
|
|
99 |
|
|
|
100 |
|
178 |
pfowler |
101 |
// Joystick
|
180 |
pfowler |
102 |
Switch3Pos joySwitch = new Switch3Pos(null, 0, 1);
|
|
|
103 |
|
|
|
104 |
Dictionary<uint, Command> joyx = new Dictionary<uint, Command>();
|
|
|
105 |
joyx.Add(0, new CommandVJSAxis(1, HID_USAGES.HID_USAGE_X));
|
|
|
106 |
this.addControl(new Potentiometer(new CommandIf(joySwitch, joyx), 1));
|
|
|
107 |
|
|
|
108 |
Dictionary<uint, Command> joyy = new Dictionary<uint, Command>();
|
|
|
109 |
joyy.Add(0, new CommandVJSAxis(1, HID_USAGES.HID_USAGE_Y));
|
|
|
110 |
this.addControl(new Potentiometer(new CommandIf(joySwitch, joyy), 0));
|
|
|
111 |
|
|
|
112 |
//this.addControl(new Potentiometer(new CommandVJSAxis(1, HID_USAGES.HID_USAGE_Y), 0)); // X 0x00 - 0x8000
|
|
|
113 |
//this.addControl(new Potentiometer(new CommandVJSAxis(1, HID_USAGES.HID_USAGE_X), 1)); // Y 0x00 - 0x8000
|
171 |
pfowler |
114 |
this.addControl(new Switch2Pos(new CommandMouseButton(CommandMouseButton.MB_LEFT), 32));
|
|
|
115 |
|
162 |
pfowler |
116 |
// Enable the mcp23017
|
|
|
117 |
mcp.WriteGpio(3, 0);
|
164 |
pfowler |
118 |
Utils.delayms(50);
|
162 |
pfowler |
119 |
mcp.WriteGpio(3, 1);
|
166 |
pfowler |
120 |
Utils.delayms(50);
|
162 |
pfowler |
121 |
|
166 |
pfowler |
122 |
chips[0].SetIODirection(0xff, 0xff);
|
|
|
123 |
chips[0].SetIOPolarity(0xff, 0xff);
|
|
|
124 |
chips[0].SetIOPullups(0xff, 0xff);
|
162 |
pfowler |
125 |
|
166 |
pfowler |
126 |
chips[1].SetIODirection(0x00, 0xff);
|
|
|
127 |
chips[1].SetIOPolarity(0x00, 0xff);
|
|
|
128 |
chips[1].SetIOPullups(0x00, 0xff);
|
|
|
129 |
|
172 |
pfowler |
130 |
this.addLed(new Led(0, 1, 0x1112, 0x0002, 1)); // NMSP_ANCHR_LED
|
|
|
131 |
this.addLed(new Led(0, 4, 0x1110, 0x0800, 11)); // NMSP_EGI_LED
|
|
|
132 |
this.addLed(new Led(0, 6, 0x11bc, 0x0004, 2)); // NMSP_FM_LED
|
|
|
133 |
this.addLed(new Led(0, 5, 0x1110, 0x0200, 9)); // NMSP_HARS_LEF
|
|
|
134 |
this.addLed(new Led(0, 3, 0x1112, 0x0020, 5)); // NMSP_ILS_LED
|
|
|
135 |
this.addLed(new Led(0, 0, 0x1110, 0x8000, 15)); // NMSP_STEERPT_LED
|
|
|
136 |
this.addLed(new Led(0, 2, 0x1112, 0x0008, 3)); // NMSP_TCN_LED
|
|
|
137 |
this.addLed(new Led(0, 7, 0x11bc, 0x0002, 1)); // NMSP_UHF_LED
|
171 |
pfowler |
138 |
|
173 |
pfowler |
139 |
//this.addLed(new Led(0, 6, 0x1012, 0x0800, 11)); // MASTER_CAUTION
|
180 |
pfowler |
140 |
// Center the vjoy axis
|
|
|
141 |
Globals.vjoy.SetAxis(0x4000, 1, HID_USAGES.HID_USAGE_X);
|
|
|
142 |
Globals.vjoy.SetAxis(0x4000, 1, HID_USAGES.HID_USAGE_Y);
|
|
|
143 |
|
178 |
pfowler |
144 |
data.axis[0].mapsize = 0x8000;
|
|
|
145 |
data.axis[1].mapsize = 0x8000;
|
187 |
pfowler |
146 |
data.axis[0].thres = 10;
|
|
|
147 |
data.axis[1].thres = 10;
|
180 |
pfowler |
148 |
|
162 |
pfowler |
149 |
this.Refresh();
|
167 |
pfowler |
150 |
data.prev = data.buttons;
|
|
|
151 |
data.axis[0].prev = data.axis[0].value;
|
|
|
152 |
data.axis[1].prev = data.axis[1].value;
|
171 |
pfowler |
153 |
data.changed = false;
|
167 |
pfowler |
154 |
|
162 |
pfowler |
155 |
return 1;
|
|
|
156 |
}
|
|
|
157 |
public override int Refresh() {
|
167 |
pfowler |
158 |
byte[] bytes;
|
163 |
pfowler |
159 |
int rslt = 0;
|
162 |
pfowler |
160 |
|
|
|
161 |
// Join all our buttons into a single inputs
|
166 |
pfowler |
162 |
UInt64 gpio = (UInt64)(1 - mcp.ReadGpio(0));
|
167 |
pfowler |
163 |
data.buttons = (UInt64)gpio << 32;
|
162 |
pfowler |
164 |
|
167 |
pfowler |
165 |
rslt = chips[1].GetIO(out bytes);
|
|
|
166 |
data.buttons |= (UInt64)bytes[0] << 24;
|
|
|
167 |
data.buttons |= (UInt64)bytes[1] << 16;
|
166 |
pfowler |
168 |
|
167 |
pfowler |
169 |
rslt = chips[0].GetIO(out bytes);
|
|
|
170 |
data.buttons |= (UInt64)bytes[0] << 8;
|
|
|
171 |
data.buttons |= (UInt64)bytes[1];
|
165 |
pfowler |
172 |
|
180 |
pfowler |
173 |
data.axis[0].value = mcp.ReadADC(0); // Y Axis
|
|
|
174 |
data.axis[1].value = mcp.ReadADC(1); // X Axis
|
165 |
pfowler |
175 |
|
167 |
pfowler |
176 |
|
180 |
pfowler |
177 |
if (data.buttons != data.prev
|
|
|
178 |
|| (data.axis[0].prev != data.axis[0].value)
|
|
|
179 |
|| (data.axis[1].prev != data.axis[1].value))
|
167 |
pfowler |
180 |
data.changed = true;
|
162 |
pfowler |
181 |
else
|
167 |
pfowler |
182 |
data.changed = false;
|
162 |
pfowler |
183 |
|
173 |
pfowler |
184 |
byte tmpShadow = this.ledShadow;
|
172 |
pfowler |
185 |
foreach (Led led in this.leds) {
|
173 |
pfowler |
186 |
led.Tick(ref ledShadow);
|
172 |
pfowler |
187 |
}
|
|
|
188 |
|
173 |
pfowler |
189 |
// Only update if leds have changed
|
|
|
190 |
if (tmpShadow != this.ledShadow)
|
|
|
191 |
chips[1].SetBank(0, ledShadow);
|
|
|
192 |
|
|
|
193 |
|
162 |
pfowler |
194 |
return rslt;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public override int Input() {
|
180 |
pfowler |
198 |
//Console.WriteLine(data.buttons.ToString("X"));
|
162 |
pfowler |
199 |
foreach (Control control in this.controls) {
|
167 |
pfowler |
200 |
control.data = this.data;
|
162 |
pfowler |
201 |
control.Tick();
|
|
|
202 |
}
|
180 |
pfowler |
203 |
|
|
|
204 |
data.axis[0].prev = data.axis[0].value;
|
|
|
205 |
data.axis[1].prev = data.axis[1].value;
|
|
|
206 |
data.prev = data.buttons;
|
167 |
pfowler |
207 |
data.changed = false;
|
162 |
pfowler |
208 |
return 1;
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
}
|