160 |
pfowler |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.Threading.Tasks;
|
162 |
pfowler |
6 |
using WindowsInput.Native;
|
160 |
pfowler |
7 |
|
|
|
8 |
namespace nitdcscore {
|
|
|
9 |
public interface IPanel {
|
|
|
10 |
int Init();
|
|
|
11 |
int Refresh();
|
|
|
12 |
int Input();
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
public abstract class Panel : IPanel {
|
|
|
16 |
protected mcp2221 mcp;
|
|
|
17 |
public int id { get; set; }
|
|
|
18 |
public String name { get; set; }
|
|
|
19 |
public String serialno { get; set; }
|
|
|
20 |
|
161 |
pfowler |
21 |
public List<Control> controls = new List<Control>();
|
|
|
22 |
|
|
|
23 |
public Boolean inputChanged { get; set; }
|
|
|
24 |
|
|
|
25 |
|
160 |
pfowler |
26 |
private Boolean enabled;
|
|
|
27 |
public Boolean Enabled {
|
|
|
28 |
get {
|
|
|
29 |
return enabled;
|
|
|
30 |
}
|
|
|
31 |
set {
|
161 |
pfowler |
32 |
this.enabled = value;
|
160 |
pfowler |
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
161 |
pfowler |
36 |
public Panel(mcp2221 mcp) {
|
160 |
pfowler |
37 |
this.mcp = mcp;
|
161 |
pfowler |
38 |
this.mcp.usbi2c.Settings.GetConnectionStatus();
|
160 |
pfowler |
39 |
this.id = this.mcp.usbi2c.Management.GetSelectedDevNum();
|
|
|
40 |
this.name = this.mcp.usbi2c.Settings.GetUsbStringDescriptor();
|
161 |
pfowler |
41 |
|
|
|
42 |
this.inputChanged = false;
|
160 |
pfowler |
43 |
}
|
|
|
44 |
|
|
|
45 |
public virtual int Init() {
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
return 1;
|
|
|
49 |
}
|
|
|
50 |
public abstract int Refresh();
|
|
|
51 |
public abstract int Input();
|
161 |
pfowler |
52 |
|
|
|
53 |
public void addControl(Control control) {
|
|
|
54 |
this.controls.Add(control);
|
|
|
55 |
}
|
160 |
pfowler |
56 |
}
|
|
|
57 |
|
161 |
pfowler |
58 |
|
|
|
59 |
public class Panel_AHFS : Panel {
|
|
|
60 |
Utils.InputPair switchInput;
|
|
|
61 |
Utils.InputPair adcInput;
|
|
|
62 |
|
|
|
63 |
public uint adc_max;
|
|
|
64 |
public uint adc_threshold;
|
|
|
65 |
|
164 |
pfowler |
66 |
private mcp23017[] chips;
|
|
|
67 |
|
161 |
pfowler |
68 |
public Panel_AHFS(mcp2221 mcp) : base(mcp) {
|
164 |
pfowler |
69 |
chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x21) };
|
|
|
70 |
|
161 |
pfowler |
71 |
switchInput.curr = 0;
|
|
|
72 |
switchInput.prev = 0;
|
|
|
73 |
adcInput.curr = 0;
|
|
|
74 |
adcInput.prev = 0;
|
|
|
75 |
this.adc_max = 930;
|
|
|
76 |
this.adc_threshold = 15;
|
|
|
77 |
|
|
|
78 |
this.Init();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public override int Init() {
|
162 |
pfowler |
82 |
//AHCP
|
161 |
pfowler |
83 |
this.addControl(new Switch3Pos(new CommandDCS("AHCP_MASTER_ARM"), 8, 9)); // Train - Safe - Arm
|
|
|
84 |
this.addControl(new Switch3Pos(new CommandDCS("AHCP_GUNPAC"), 10, 11)); // Gunarm - Safe - Arm
|
|
|
85 |
this.addControl(new Switch3Pos(new CommandDCS("AHCP_LASER_ARM"), 12, 13)); // Train - Safe - Arm
|
|
|
86 |
this.addControl(new Switch2Pos(new CommandDCS("AHCP_TGP"), 14)); // Off - On
|
|
|
87 |
this.addControl(new Switch3Pos(new CommandDCS("AHCP_ALT_SCE"), 0, 1)); // Radar - Delta - Baro
|
|
|
88 |
this.addControl(new Switch2Pos(new CommandDCS("AHCP_HUD_DAYNIGHT"), 2)); // Night - Day
|
|
|
89 |
this.addControl(new Switch2Pos(new CommandDCS("AHCP_HUD_MODE"), 15)); // Stby - Norm
|
|
|
90 |
this.addControl(new Switch2Pos(new CommandDCS("AHCP_CICU"), 3)); // Off - On
|
|
|
91 |
this.addControl(new Switch2Pos(new CommandDCS("AHCP_JTRS"), 4)); // Off - On
|
|
|
92 |
this.addControl(new Switch3Pos(new CommandDCS("AHCP_IFFCC"), 6, 5)); // Off - Test - On
|
162 |
pfowler |
93 |
//this.addControl(new Switch2Pos(new CommandDCS("HARS_FAST_ERECT"), 7)); // Off - On
|
|
|
94 |
this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F9), 7));
|
161 |
pfowler |
95 |
|
162 |
pfowler |
96 |
// Fuel System
|
|
|
97 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_AMPL"), 16));
|
|
|
98 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_MAIN_L"), 24));
|
|
|
99 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_MAIN_R"), 25));
|
|
|
100 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_WING_L"), 26));
|
|
|
101 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_WING_R"),27 ));
|
|
|
102 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_CROSSFEED"), 28));
|
|
|
103 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_EXT_TANKS_FUS"), 30));
|
|
|
104 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_EXT_TANKS_WING"), 31));
|
|
|
105 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_MAIN_L"), 20, true));
|
|
|
106 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_MAIN_R"), 21, true));
|
|
|
107 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_WING_L"), 18, true));
|
|
|
108 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_WING_R"), 19, true));
|
|
|
109 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_LINE_CHECK"), 17));
|
|
|
110 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_RCVR_LEVER"), 23));
|
|
|
111 |
this.addControl(new Switch2Pos(new CommandDCS("FSCP_TK_GATE"), 29));
|
161 |
pfowler |
112 |
|
|
|
113 |
mcp.WriteGpio(3, 0);
|
164 |
pfowler |
114 |
Utils.delayms(10);
|
161 |
pfowler |
115 |
// Enable the mcp23017
|
|
|
116 |
mcp.WriteGpio(3, 1);
|
164 |
pfowler |
117 |
|
161 |
pfowler |
118 |
// Set io dir, pullups and rev polarity
|
164 |
pfowler |
119 |
chips[0].SetIODirection(0xff, 0xff);
|
|
|
120 |
chips[0].SetIOPolarity(0xf0, 0xff);
|
|
|
121 |
chips[0].SetIOPullups(0xff, 0xff);
|
161 |
pfowler |
122 |
|
164 |
pfowler |
123 |
chips[1].SetIODirection(0xff, 0xff);
|
|
|
124 |
chips[1].SetIOPolarity(0xff, 0xff);
|
|
|
125 |
chips[1].SetIOPullups(0xff, 0xff);
|
161 |
pfowler |
126 |
|
|
|
127 |
// Get the initial ADC value
|
|
|
128 |
adcInput.prev = adcInput.curr = mcp.ReadADC(1);
|
|
|
129 |
this.Refresh();
|
|
|
130 |
switchInput.prev = switchInput.curr;
|
|
|
131 |
|
164 |
pfowler |
132 |
return 0;
|
161 |
pfowler |
133 |
}
|
|
|
134 |
|
|
|
135 |
public override int Refresh() {
|
|
|
136 |
|
|
|
137 |
byte[] data;
|
164 |
pfowler |
138 |
int rslt = 0;
|
|
|
139 |
rslt = chips[0].GetIO(out data);
|
161 |
pfowler |
140 |
|
|
|
141 |
switchInput.curr = (uint)data[0] << 24;
|
|
|
142 |
switchInput.curr |= (uint)data[1] << 16;
|
164 |
pfowler |
143 |
|
|
|
144 |
rslt = chips[1].GetIO(out data);
|
161 |
pfowler |
145 |
|
|
|
146 |
switchInput.curr |= (uint)data[0] << 8;
|
|
|
147 |
switchInput.curr |= (uint)data[1];
|
|
|
148 |
|
|
|
149 |
/*
|
|
|
150 |
// Do the Refueling light adc
|
|
|
151 |
devices[devid].cur_adc = mcp.ReadADC(1);
|
|
|
152 |
|
|
|
153 |
if (devices[devid].cur_adc > devices[devid].max_adc)
|
|
|
154 |
devices[devid].max_adc = devices[devid].cur_adc;
|
|
|
155 |
|
|
|
156 |
ushort lowerval = 0;
|
|
|
157 |
if (devices[devid].prev_adc >= devices[devid].adc_thres)
|
|
|
158 |
lowerval = (ushort)(devices[devid].prev_adc - devices[devid].adc_thres);
|
|
|
159 |
|
|
|
160 |
ushort upperval = devices[devid].max_adc;
|
|
|
161 |
if (devices[devid].prev_adc <= upperval - devices[devid].adc_thres)
|
|
|
162 |
upperval = (ushort)(devices[devid].prev_adc + devices[devid].adc_thres);
|
|
|
163 |
|
|
|
164 |
//Console.WriteLine("ADC: " + devices[devid].cur_adc + " Max: " + devices[devid].max_adc + " Low: " + lowerval + " High: " + upperval);
|
|
|
165 |
|
|
|
166 |
if ((devices[devid].cur_adc < lowerval) || (devices[devid].cur_adc >= upperval)) {
|
|
|
167 |
// Cover our min/max ranges within threshold
|
|
|
168 |
if (devices[devid].cur_adc < devices[devid].adc_thres)
|
|
|
169 |
devices[devid].cur_adc = 0;
|
|
|
170 |
if (devices[devid].cur_adc > devices[devid].max_adc - devices[devid].adc_thres)
|
|
|
171 |
devices[devid].cur_adc = devices[devid].max_adc;
|
|
|
172 |
|
|
|
173 |
devices[devid].prev_adc = devices[devid].cur_adc;
|
|
|
174 |
|
|
|
175 |
ushort refuellight = map_ushort(devices[devid].cur_adc, 0, devices[devid].max_adc, 0, 0xffff);
|
|
|
176 |
Globals.bios.SendData("ALCP_RCVR_LTS " + refuellight.ToString() + "\n");
|
|
|
177 |
Console.WriteLine("ALCP_RCVR_LTS " + ":" + refuellight.ToString() + "(" + devices[devid].cur_adc + ")");
|
|
|
178 |
}
|
|
|
179 |
* */
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
if ((switchInput.curr != switchInput.prev) || (adcInput.prev != adcInput.curr))
|
|
|
183 |
this.inputChanged = true;
|
|
|
184 |
else
|
|
|
185 |
this.inputChanged = false;
|
|
|
186 |
|
|
|
187 |
return 1;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public override int Input() {
|
164 |
pfowler |
191 |
|
161 |
pfowler |
192 |
foreach (Control control in this.controls) {
|
|
|
193 |
control.data = this.switchInput;
|
|
|
194 |
control.Tick();
|
|
|
195 |
}
|
|
|
196 |
switchInput.prev = switchInput.curr;
|
|
|
197 |
adcInput.prev = adcInput.curr;
|
|
|
198 |
this.inputChanged = false;
|
|
|
199 |
return 1;
|
|
|
200 |
}
|
160 |
pfowler |
201 |
}
|
|
|
202 |
|
|
|
203 |
public class Panel_AAP : Panel {
|
|
|
204 |
|
161 |
pfowler |
205 |
Utils.InputPair input;
|
164 |
pfowler |
206 |
private mcp23017 chip0;
|
160 |
pfowler |
207 |
|
161 |
pfowler |
208 |
public Panel_AAP(mcp2221 mcp) : base(mcp) {
|
160 |
pfowler |
209 |
input.curr = 0;
|
|
|
210 |
input.prev = 0;
|
|
|
211 |
|
164 |
pfowler |
212 |
chip0 = new mcp23017(mcp, 0x20);
|
|
|
213 |
|
161 |
pfowler |
214 |
this.Init();
|
160 |
pfowler |
215 |
}
|
|
|
216 |
|
|
|
217 |
public override int Init() {
|
162 |
pfowler |
218 |
this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F9), 16));
|
|
|
219 |
this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F11), 17));
|
|
|
220 |
this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F7), 12));
|
|
|
221 |
this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.SPACE), 13));
|
|
|
222 |
this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.RETURN), 14));
|
|
|
223 |
this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.VOLUME_MUTE), 15));
|
161 |
pfowler |
224 |
this.addControl(new Switch2Pos(new CommandDCS("AAP_CDUPWR"), 11));
|
|
|
225 |
this.addControl(new Switch2Pos(new CommandDCS("AAP_EGIPWR"), 10));
|
|
|
226 |
this.addControl(new Switch3Pos(new CommandDCS("AAP_STEER"), 9, 8));
|
|
|
227 |
this.addControl(new Selector(new CommandDCS("AAP_STEERPT"), new int[] { 4, 5, 6 }));
|
|
|
228 |
this.addControl(new Selector(new CommandDCS("AAP_PAGE"), new int[] { 0, 1, 2, 3 }));
|
|
|
229 |
|
160 |
pfowler |
230 |
// Enable the mcp23017
|
|
|
231 |
mcp.WriteGpio(3, 0);
|
164 |
pfowler |
232 |
Utils.delayms(10);
|
160 |
pfowler |
233 |
mcp.WriteGpio(3, 1);
|
|
|
234 |
|
|
|
235 |
// Set io dir, pullups and rev polarity
|
164 |
pfowler |
236 |
chip0.SetIODirection(0xff, 0xff);
|
|
|
237 |
chip0.SetIOPolarity(0xff, 0xff);
|
|
|
238 |
chip0.SetIOPullups(0xff, 0xff);
|
160 |
pfowler |
239 |
|
161 |
pfowler |
240 |
this.Refresh();
|
|
|
241 |
input.prev = input.curr;
|
160 |
pfowler |
242 |
|
|
|
243 |
return 1;
|
|
|
244 |
}
|
|
|
245 |
public override int Refresh() {
|
161 |
pfowler |
246 |
byte[] data;
|
164 |
pfowler |
247 |
int rslt = 0;
|
|
|
248 |
rslt = chip0.GetIO(out data);
|
160 |
pfowler |
249 |
|
161 |
pfowler |
250 |
// Join all our buttons into a single inputs
|
|
|
251 |
uint gpio = (uint)((1 - mcp.ReadGpio(0)) | ((1 - mcp.ReadGpio(1)) << 1));
|
|
|
252 |
input.curr = (uint)gpio << 16;
|
|
|
253 |
input.curr |= (uint)data[0] << 8;
|
|
|
254 |
input.curr |= (uint)data[1];
|
|
|
255 |
|
|
|
256 |
if (input.curr != input.prev)
|
|
|
257 |
this.inputChanged = true;
|
|
|
258 |
else
|
|
|
259 |
this.inputChanged = false;
|
|
|
260 |
|
|
|
261 |
return rslt;
|
160 |
pfowler |
262 |
}
|
|
|
263 |
|
|
|
264 |
public override int Input() {
|
162 |
pfowler |
265 |
//Console.WriteLine(input.curr.ToString("X"));
|
161 |
pfowler |
266 |
foreach (Control control in this.controls) {
|
|
|
267 |
control.data = this.input;
|
|
|
268 |
control.Tick();
|
|
|
269 |
}
|
|
|
270 |
input.prev = input.curr;
|
|
|
271 |
this.inputChanged = false;
|
160 |
pfowler |
272 |
return 1;
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
}
|