181 |
pfowler |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
184 |
pfowler |
3 |
using System.Drawing;
|
181 |
pfowler |
4 |
using System.Linq;
|
|
|
5 |
using System.Text;
|
|
|
6 |
using System.Threading.Tasks;
|
|
|
7 |
using WindowsInput.Native;
|
|
|
8 |
|
|
|
9 |
namespace nitdcscore {
|
|
|
10 |
public class NitAuxPanel : Panel {
|
|
|
11 |
|
|
|
12 |
private mcp23017[] chips;
|
183 |
pfowler |
13 |
private Oled oled;
|
181 |
pfowler |
14 |
public UInt16 ledShadowA = 0x0000;
|
|
|
15 |
|
|
|
16 |
public NitAuxPanel(mcp2221 mcp) : base(mcp) {
|
|
|
17 |
chips = new mcp23017[3] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x21), new mcp23017(mcp, 0x22) };
|
|
|
18 |
|
|
|
19 |
this.Init();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public override int Init() {
|
|
|
23 |
|
|
|
24 |
// The strings to send for magnetic hold switches
|
|
|
25 |
Dictionary<UInt64, String> magSwitch = new Dictionary<ulong,string>();
|
|
|
26 |
magSwitch.Add(0, "OFF");
|
|
|
27 |
magSwitch.Add(1, "PUSH");
|
|
|
28 |
|
|
|
29 |
this.addControl(new Switch3Pos(new CommandDCS("FIRE_EXT_DISCH"), 0, 1));
|
|
|
30 |
this.addControl(new Switch2Pos(new CommandDCS("FIRE_RENG_PULL"), 2));
|
|
|
31 |
this.addControl(new Switch2Pos(new CommandDCS("EXT_STORES_JETTISON"), 3));
|
|
|
32 |
this.addControl(new Switch2Pos(new CommandDCS("FIRE_APU_PULL"), 4));
|
|
|
33 |
this.addControl(new Switch2Pos(new CommandDCS("FIRE_LENG_PULL"), 5));
|
|
|
34 |
this.addControl(new Switch3Pos(new CommandDCS("SEAT_ADJUST"), 6, 7));
|
|
|
35 |
|
|
|
36 |
this.addControl(new Switch2Pos(new CommandDCSMap("ANTI_SKID_SWITCH", magSwitch), 8));
|
|
|
37 |
this.addControl(new Switch3Pos(new CommandDCS("LANDING_LIGHTS"), 9, 10));
|
|
|
38 |
this.addControl(new Switch2Pos(new CommandDCS("DOWNLOCK_OVERRIDE"), 11));
|
|
|
39 |
this.addControl(new Switch2Pos(new CommandDCS("ENGINE_TEMS_DATA"), 12));
|
|
|
40 |
this.addControl(new Switch2Pos(new CommandDCS("GEAR_LEVER"), 14));
|
|
|
41 |
|
|
|
42 |
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_PITCH_SAS_L", magSwitch), 17));
|
|
|
43 |
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_PITCH_SAS_R", magSwitch), 18));
|
|
|
44 |
this.addControl(new Switch2Pos(new CommandDCS("SASP_TO_TRIM"), 19));
|
|
|
45 |
this.addControl(new Switch3Pos(new CommandDCS("SASP_MONITOR_TEST"), 20, 21));
|
|
|
46 |
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_YAW_SAS_R", magSwitch), 22));
|
|
|
47 |
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_YAW_SAS_L", magSwitch), 23));
|
|
|
48 |
this.addControl(new Potentiometer(new CommandDCS("SASP_YAW_TRIM"), 0));
|
|
|
49 |
|
|
|
50 |
this.addControl(new Switch2Pos(new CommandDCS("EFCP_FLAPS_EMER_RETR"), 24));
|
|
|
51 |
this.addControl(new Switch3Pos(new CommandDCS("EFCP_AILERON_EMER_DISENGAGE"), 26, 25));
|
|
|
52 |
this.addControl(new Switch3Pos(new CommandDCS("EFCP_ELEVATOR_EMER_DISENGAGE"), 31, 30));
|
|
|
53 |
this.addControl(new Switch2Pos(new CommandDCS("EFCP_SPDBK_EMER_RETR"), 27));
|
|
|
54 |
this.addControl(new Switch2Pos(new CommandDCS("EFCP_TRIM_OVERRIDE"), 28));
|
|
|
55 |
this.addControl(new Switch2Pos(new CommandDCS("EFCP_MRFCS"), 29));
|
|
|
56 |
|
|
|
57 |
// Enable the mcp23017
|
|
|
58 |
mcp.WriteGpio(3, 0);
|
|
|
59 |
Utils.delayms(50);
|
|
|
60 |
mcp.WriteGpio(3, 1);
|
|
|
61 |
Utils.delayms(50);
|
|
|
62 |
|
|
|
63 |
chips[0].SetIODirection(0xff, 0xff);
|
|
|
64 |
chips[0].SetIOPolarity(0xff, 0xff);
|
|
|
65 |
chips[0].SetIOPullups(0xff, 0xff);
|
|
|
66 |
|
|
|
67 |
chips[1].SetIODirection(0xff, 0xff);
|
|
|
68 |
chips[1].SetIOPolarity(0xff, 0xff);
|
|
|
69 |
chips[1].SetIOPullups(0xff, 0xff);
|
|
|
70 |
|
|
|
71 |
chips[2].SetIODirection(0x00, 0x00);
|
|
|
72 |
chips[2].SetIOPolarity(0x00, 0x00);
|
|
|
73 |
chips[2].SetIOPullups(0x00, 0x00);
|
|
|
74 |
|
|
|
75 |
this.addLed(new Led(1, 6, 0x1026, 0x1000, 12)); // Left
|
|
|
76 |
this.addLed(new Led(1, 4, 0x1026, 0x0800, 11)); // Nose
|
|
|
77 |
this.addLed(new Led(1, 2, 0x1026, 0x2000, 13)); // Right
|
|
|
78 |
this.addLed(new Led(1, 1, 0x1026, 0x4000, 14)); // Gear Handle
|
|
|
79 |
|
|
|
80 |
this.addLed(new Led(0, 12, 0x10da, 0x0040, 6)); // L_AILERON_EMER_DISENGAGE
|
|
|
81 |
this.addLed(new Led(0, 11, 0x10da, 0x0080, 7)); // R_AILERON_EMER_DISENGAGE
|
|
|
82 |
this.addLed(new Led(0, 10, 0x10da, 0x0100, 8)); // L_ELEVATOR_EMER_DISENGAGE
|
|
|
83 |
this.addLed(new Led(0, 9, 0x10da, 0x0200, 9)); // R_ELEVATOR_EMER_DISENGAGE
|
|
|
84 |
this.addLed(new Led(0, 8, 0x1026, 0x0400, 10)); // TAKE_OFF_TRIM
|
|
|
85 |
|
184 |
pfowler |
86 |
|
|
|
87 |
|
|
|
88 |
//Bitmap flap = new Bitmap(nitdcscore.Properties.Resources.flap_bg);
|
|
|
89 |
BitImage bi = new BitImage(new Bitmap(nitdcscore.Properties.Resources.flap_bg));
|
|
|
90 |
|
|
|
91 |
oled = new Oled(Oled.SWITCHCAPVCC, 0x3d, mcp);
|
183 |
pfowler |
92 |
oled.init();
|
184 |
pfowler |
93 |
oled.buffer = bi.toByteArray();
|
|
|
94 |
oled.display();
|
181 |
pfowler |
95 |
|
183 |
pfowler |
96 |
// Register the flap gauge position address
|
|
|
97 |
UInt16 din; // Addr 10A0, Mask FFFF, Max Val FFFF, Shift 0
|
|
|
98 |
if (!Globals.BiosOutput.TryGetValue(0x10A0, out din)) {
|
|
|
99 |
Globals.BiosOutput.Add(0x10A0, 0x0000);
|
|
|
100 |
}
|
|
|
101 |
|
181 |
pfowler |
102 |
data.axis[0].mapsize = 0xFFFF;
|
|
|
103 |
data.axis[0].thres = 3;
|
|
|
104 |
|
|
|
105 |
this.Refresh();
|
|
|
106 |
data.prev = data.buttons;
|
|
|
107 |
data.axis[0].prev = data.axis[0].value;
|
|
|
108 |
data.changed = false;
|
|
|
109 |
|
|
|
110 |
return 1;
|
|
|
111 |
}
|
|
|
112 |
public override int Refresh() {
|
|
|
113 |
byte[] bytes;
|
|
|
114 |
int rslt = 0;
|
|
|
115 |
|
|
|
116 |
// Join all our buttons into a single inputs
|
|
|
117 |
|
|
|
118 |
rslt = chips[1].GetIO(out bytes);
|
|
|
119 |
data.buttons = (UInt64)bytes[0] << 24;
|
|
|
120 |
data.buttons |= (UInt64)bytes[1] << 16;
|
|
|
121 |
|
|
|
122 |
rslt = chips[0].GetIO(out bytes);
|
|
|
123 |
data.buttons |= (UInt64)bytes[0] << 8;
|
|
|
124 |
data.buttons |= (UInt64)bytes[1];
|
|
|
125 |
|
|
|
126 |
data.axis[0].value = mcp.ReadADC(0); // Y Axis
|
|
|
127 |
|
|
|
128 |
//ushort tmpval = 0;
|
|
|
129 |
//bool changed = data.axis[0].getPosition(ref tmpval);
|
|
|
130 |
//tmpval = 0;
|
|
|
131 |
if (data.buttons != data.prev || data.axis[0].value != data.axis[0].prev)
|
|
|
132 |
data.changed = true;
|
|
|
133 |
else
|
|
|
134 |
data.changed = false;
|
|
|
135 |
|
|
|
136 |
UInt16 tmpShadow = this.ledShadowA;
|
|
|
137 |
foreach (Led led in this.leds) {
|
|
|
138 |
led.Tick(ref ledShadowA);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// Only update if leds have changed
|
|
|
142 |
if (tmpShadow != this.ledShadowA) {
|
|
|
143 |
byte gpa = (byte)ledShadowA;
|
|
|
144 |
byte gpb = (byte)(ledShadowA >> 8);
|
|
|
145 |
|
|
|
146 |
chips[2].SetBank(0, (byte)gpa);
|
|
|
147 |
chips[2].SetBank(1, (byte)gpb);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
return rslt;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
public override int Input() {
|
|
|
155 |
//Console.WriteLine(data.buttons.ToString("X") + " " + data.axis[0].value.ToString());
|
|
|
156 |
foreach (Control control in this.controls) {
|
|
|
157 |
control.data = this.data;
|
|
|
158 |
control.Tick();
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
data.axis[0].prev = data.axis[0].value;
|
|
|
162 |
data.prev = data.buttons;
|
|
|
163 |
data.changed = false;
|
|
|
164 |
return 1;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|