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