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 |
|
167 |
pfowler |
11 |
//Utils.InputPair input;
|
165 |
pfowler |
12 |
|
166 |
pfowler |
13 |
private mcp23017[] chips;
|
162 |
pfowler |
14 |
|
166 |
pfowler |
15 |
public NitMultiPanel(mcp2221 mcp) : base(mcp) {
|
|
|
16 |
chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x24) };
|
167 |
pfowler |
17 |
//input.curr = 0;
|
|
|
18 |
//input.prev = 0;
|
162 |
pfowler |
19 |
|
167 |
pfowler |
20 |
data.buttons = 0;
|
|
|
21 |
data.prev = 0;
|
165 |
pfowler |
22 |
|
167 |
pfowler |
23 |
data.axis[0].mapsize = 0xffff;
|
|
|
24 |
data.axis[0].thres = 15;
|
|
|
25 |
|
|
|
26 |
data.axis[1].mapsize = 0xffff;
|
|
|
27 |
data.axis[1].thres = 15;
|
|
|
28 |
|
162 |
pfowler |
29 |
this.Init();
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public override int Init() {
|
|
|
33 |
// Choose what function the number pad shall carry out:
|
|
|
34 |
// 0 = UFC #, 1 = F1-F12 Keys, 2 = Misc (+ TrackIR)
|
|
|
35 |
Switch3Pos selSwitch = new Switch3Pos(null, 2, 3);
|
|
|
36 |
|
|
|
37 |
// Row 1
|
|
|
38 |
Dictionary<uint, Command> pad01 = new Dictionary<uint, Command>();
|
164 |
pfowler |
39 |
pad01.Add(0, new CommandDCS("UFC_1"));
|
162 |
pfowler |
40 |
pad01.Add(1, new CommandVKey(VirtualKeyCode.F1));
|
|
|
41 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad01), 7));
|
|
|
42 |
|
|
|
43 |
Dictionary<uint, Command> pad02 = new Dictionary<uint, Command>();
|
164 |
pfowler |
44 |
pad02.Add(0, new CommandDCS("UFC_2"));
|
162 |
pfowler |
45 |
pad02.Add(1, new CommandVKey(VirtualKeyCode.F2));
|
|
|
46 |
pad02.Add(2, new CommandTrackIRKey(VirtualKeyCode.F7));
|
|
|
47 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad02), 6));
|
|
|
48 |
|
|
|
49 |
Dictionary<uint, Command> pad03 = new Dictionary<uint, Command>();
|
164 |
pfowler |
50 |
pad03.Add(0, new CommandDCS("UFC_3"));
|
162 |
pfowler |
51 |
pad03.Add(1, new CommandVKey(VirtualKeyCode.F3));
|
|
|
52 |
pad03.Add(2, new CommandTrackIRKey(VirtualKeyCode.F11));
|
|
|
53 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad03), 5));
|
|
|
54 |
|
|
|
55 |
Dictionary<uint, Command> pad04 = new Dictionary<uint,Command>();
|
|
|
56 |
pad04.Add(0, new CommandDCS("UFC_ENT"));
|
|
|
57 |
pad04.Add(1, new CommandVKey(VirtualKeyCode.F4));
|
|
|
58 |
pad04.Add(2, new CommandTrackIRKey(VirtualKeyCode.F9));
|
|
|
59 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad04), 4));
|
|
|
60 |
|
|
|
61 |
// Row 2
|
|
|
62 |
Dictionary<uint, Command> pad05 = new Dictionary<uint, Command>();
|
164 |
pfowler |
63 |
pad05.Add(0, new CommandDCS("UFC_4"));
|
162 |
pfowler |
64 |
pad05.Add(1, new CommandVKey(VirtualKeyCode.F5));
|
|
|
65 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad05), 11));
|
|
|
66 |
|
|
|
67 |
Dictionary<uint, Command> pad06 = new Dictionary<uint, Command>();
|
164 |
pfowler |
68 |
pad06.Add(0, new CommandDCS("UFC_5"));
|
162 |
pfowler |
69 |
pad06.Add(1, new CommandVKey(VirtualKeyCode.F6));
|
|
|
70 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad06), 10));
|
|
|
71 |
|
|
|
72 |
Dictionary<uint, Command> pad07 = new Dictionary<uint, Command>();
|
164 |
pfowler |
73 |
pad07.Add(0, new CommandDCS("UFC_6"));
|
162 |
pfowler |
74 |
pad07.Add(1, new CommandVKey(VirtualKeyCode.F7));
|
|
|
75 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad07), 9));
|
|
|
76 |
|
|
|
77 |
Dictionary<uint, Command> pad08 = new Dictionary<uint, Command>();
|
|
|
78 |
pad08.Add(0, new CommandDCS("UFC_10"));
|
|
|
79 |
pad08.Add(1, new CommandVKey(VirtualKeyCode.F8));
|
|
|
80 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad08), 8));
|
|
|
81 |
|
|
|
82 |
// Row 3
|
|
|
83 |
Dictionary<uint, Command> pad09 = new Dictionary<uint, Command>();
|
|
|
84 |
pad09.Add(0, new CommandDCS("UFC_7"));
|
|
|
85 |
pad09.Add(1, new CommandVKey(VirtualKeyCode.F9));
|
|
|
86 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad09), 15));
|
|
|
87 |
|
|
|
88 |
Dictionary<uint, Command> pad10 = new Dictionary<uint, Command>();
|
164 |
pfowler |
89 |
pad10.Add(0, new CommandDCS("UFC_8"));
|
162 |
pfowler |
90 |
pad10.Add(1, new CommandVKey(VirtualKeyCode.F10));
|
|
|
91 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad10), 14));
|
|
|
92 |
|
|
|
93 |
Dictionary<uint, Command> pad11 = new Dictionary<uint, Command>();
|
164 |
pfowler |
94 |
pad11.Add(0, new CommandDCS("UFC_9"));
|
162 |
pfowler |
95 |
pad11.Add(1, new CommandVKey(VirtualKeyCode.F11));
|
|
|
96 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad11), 13));
|
|
|
97 |
|
|
|
98 |
Dictionary<uint, Command> pad12 = new Dictionary<uint, Command>();
|
|
|
99 |
pad12.Add(0, new CommandDCS("UFC_CLR"));
|
|
|
100 |
pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
|
|
|
101 |
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
|
|
|
102 |
|
165 |
pfowler |
103 |
// Joystick Press - Mapped to mouse button 1
|
166 |
pfowler |
104 |
this.addControl(new Switch2Pos(new CommandMouseButton(CommandMouseButton.MB_LEFT), 32));
|
162 |
pfowler |
105 |
|
165 |
pfowler |
106 |
|
166 |
pfowler |
107 |
// NMSP
|
|
|
108 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_EGI_BTN"), 16));
|
|
|
109 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_HARS_BTN"), 17));
|
|
|
110 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ILS_BTN"), 18));
|
|
|
111 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_TCN_BTN"), 19));
|
|
|
112 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ANCHR_BTN"), 20));
|
|
|
113 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_STEERPT_BTN"), 21));
|
|
|
114 |
this.addControl(new Switch2Pos(new CommandDCS("NMSP_ABLE_STOW"), 22, true));
|
|
|
115 |
|
|
|
116 |
|
162 |
pfowler |
117 |
// Enable the mcp23017
|
|
|
118 |
mcp.WriteGpio(3, 0);
|
164 |
pfowler |
119 |
Utils.delayms(50);
|
162 |
pfowler |
120 |
mcp.WriteGpio(3, 1);
|
166 |
pfowler |
121 |
Utils.delayms(50);
|
162 |
pfowler |
122 |
|
166 |
pfowler |
123 |
chips[0].SetIODirection(0xff, 0xff);
|
|
|
124 |
chips[0].SetIOPolarity(0xff, 0xff);
|
|
|
125 |
chips[0].SetIOPullups(0xff, 0xff);
|
162 |
pfowler |
126 |
|
166 |
pfowler |
127 |
chips[1].SetIODirection(0x00, 0xff);
|
|
|
128 |
chips[1].SetIOPolarity(0x00, 0xff);
|
|
|
129 |
chips[1].SetIOPullups(0x00, 0xff);
|
|
|
130 |
|
162 |
pfowler |
131 |
this.Refresh();
|
167 |
pfowler |
132 |
//input.prev = input.curr;
|
162 |
pfowler |
133 |
|
167 |
pfowler |
134 |
data.prev = data.buttons;
|
|
|
135 |
data.axis[0].prev = data.axis[0].value;
|
|
|
136 |
data.axis[1].prev = data.axis[1].value;
|
|
|
137 |
|
|
|
138 |
|
162 |
pfowler |
139 |
return 1;
|
|
|
140 |
}
|
|
|
141 |
public override int Refresh() {
|
167 |
pfowler |
142 |
byte[] bytes;
|
163 |
pfowler |
143 |
int rslt = 0;
|
162 |
pfowler |
144 |
|
|
|
145 |
// Join all our buttons into a single inputs
|
166 |
pfowler |
146 |
UInt64 gpio = (UInt64)(1 - mcp.ReadGpio(0));
|
167 |
pfowler |
147 |
data.buttons = (UInt64)gpio << 32;
|
162 |
pfowler |
148 |
|
167 |
pfowler |
149 |
rslt = chips[1].GetIO(out bytes);
|
|
|
150 |
data.buttons |= (UInt64)bytes[0] << 24;
|
|
|
151 |
data.buttons |= (UInt64)bytes[1] << 16;
|
166 |
pfowler |
152 |
|
167 |
pfowler |
153 |
rslt = chips[0].GetIO(out bytes);
|
|
|
154 |
data.buttons |= (UInt64)bytes[0] << 8;
|
|
|
155 |
data.buttons |= (UInt64)bytes[1];
|
165 |
pfowler |
156 |
|
167 |
pfowler |
157 |
data.axis[0].value = mcp.ReadADC(0);
|
|
|
158 |
data.axis[1].value = mcp.ReadADC(1);
|
165 |
pfowler |
159 |
|
167 |
pfowler |
160 |
|
|
|
161 |
if (data.buttons != data.prev)
|
|
|
162 |
data.changed = true;
|
162 |
pfowler |
163 |
else
|
167 |
pfowler |
164 |
data.changed = false;
|
162 |
pfowler |
165 |
|
|
|
166 |
return rslt;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public override int Input() {
|
166 |
pfowler |
170 |
//Console.WriteLine(input.curr.ToString("X"));
|
162 |
pfowler |
171 |
foreach (Control control in this.controls) {
|
167 |
pfowler |
172 |
control.data = this.data;
|
162 |
pfowler |
173 |
control.Tick();
|
|
|
174 |
}
|
167 |
pfowler |
175 |
data.changed = false;
|
163 |
pfowler |
176 |
|
167 |
pfowler |
177 |
data.prev = data.buttons;
|
162 |
pfowler |
178 |
return 1;
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
}
|