Rev 183 | Rev 185 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsInput.Native;
namespace nitdcscore {
public class NitAuxPanel : Panel {
private mcp23017[] chips;
private Oled oled;
public UInt16 ledShadowA = 0x0000;
public NitAuxPanel(mcp2221 mcp) : base(mcp) {
chips = new mcp23017[3] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x21), new mcp23017(mcp, 0x22) };
this.Init();
}
public override int Init() {
// The strings to send for magnetic hold switches
Dictionary<UInt64, String> magSwitch = new Dictionary<ulong,string>();
magSwitch.Add(0, "OFF");
magSwitch.Add(1, "PUSH");
this.addControl(new Switch3Pos(new CommandDCS("FIRE_EXT_DISCH"), 0, 1));
this.addControl(new Switch2Pos(new CommandDCS("FIRE_RENG_PULL"), 2));
this.addControl(new Switch2Pos(new CommandDCS("EXT_STORES_JETTISON"), 3));
this.addControl(new Switch2Pos(new CommandDCS("FIRE_APU_PULL"), 4));
this.addControl(new Switch2Pos(new CommandDCS("FIRE_LENG_PULL"), 5));
this.addControl(new Switch3Pos(new CommandDCS("SEAT_ADJUST"), 6, 7));
this.addControl(new Switch2Pos(new CommandDCSMap("ANTI_SKID_SWITCH", magSwitch), 8));
this.addControl(new Switch3Pos(new CommandDCS("LANDING_LIGHTS"), 9, 10));
this.addControl(new Switch2Pos(new CommandDCS("DOWNLOCK_OVERRIDE"), 11));
this.addControl(new Switch2Pos(new CommandDCS("ENGINE_TEMS_DATA"), 12));
this.addControl(new Switch2Pos(new CommandDCS("GEAR_LEVER"), 14));
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_PITCH_SAS_L", magSwitch), 17));
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_PITCH_SAS_R", magSwitch), 18));
this.addControl(new Switch2Pos(new CommandDCS("SASP_TO_TRIM"), 19));
this.addControl(new Switch3Pos(new CommandDCS("SASP_MONITOR_TEST"), 20, 21));
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_YAW_SAS_R", magSwitch), 22));
this.addControl(new Switch2Pos(new CommandDCSMap("SASP_YAW_SAS_L", magSwitch), 23));
this.addControl(new Potentiometer(new CommandDCS("SASP_YAW_TRIM"), 0));
this.addControl(new Switch2Pos(new CommandDCS("EFCP_FLAPS_EMER_RETR"), 24));
this.addControl(new Switch3Pos(new CommandDCS("EFCP_AILERON_EMER_DISENGAGE"), 26, 25));
this.addControl(new Switch3Pos(new CommandDCS("EFCP_ELEVATOR_EMER_DISENGAGE"), 31, 30));
this.addControl(new Switch2Pos(new CommandDCS("EFCP_SPDBK_EMER_RETR"), 27));
this.addControl(new Switch2Pos(new CommandDCS("EFCP_TRIM_OVERRIDE"), 28));
this.addControl(new Switch2Pos(new CommandDCS("EFCP_MRFCS"), 29));
// Enable the mcp23017
mcp.WriteGpio(3, 0);
Utils.delayms(50);
mcp.WriteGpio(3, 1);
Utils.delayms(50);
chips[0].SetIODirection(0xff, 0xff);
chips[0].SetIOPolarity(0xff, 0xff);
chips[0].SetIOPullups(0xff, 0xff);
chips[1].SetIODirection(0xff, 0xff);
chips[1].SetIOPolarity(0xff, 0xff);
chips[1].SetIOPullups(0xff, 0xff);
chips[2].SetIODirection(0x00, 0x00);
chips[2].SetIOPolarity(0x00, 0x00);
chips[2].SetIOPullups(0x00, 0x00);
this.addLed(new Led(1, 6, 0x1026, 0x1000, 12)); // Left
this.addLed(new Led(1, 4, 0x1026, 0x0800, 11)); // Nose
this.addLed(new Led(1, 2, 0x1026, 0x2000, 13)); // Right
this.addLed(new Led(1, 1, 0x1026, 0x4000, 14)); // Gear Handle
this.addLed(new Led(0, 12, 0x10da, 0x0040, 6)); // L_AILERON_EMER_DISENGAGE
this.addLed(new Led(0, 11, 0x10da, 0x0080, 7)); // R_AILERON_EMER_DISENGAGE
this.addLed(new Led(0, 10, 0x10da, 0x0100, 8)); // L_ELEVATOR_EMER_DISENGAGE
this.addLed(new Led(0, 9, 0x10da, 0x0200, 9)); // R_ELEVATOR_EMER_DISENGAGE
this.addLed(new Led(0, 8, 0x1026, 0x0400, 10)); // TAKE_OFF_TRIM
//Bitmap flap = new Bitmap(nitdcscore.Properties.Resources.flap_bg);
BitImage bi = new BitImage(new Bitmap(nitdcscore.Properties.Resources.flap_bg));
oled = new Oled(Oled.SWITCHCAPVCC, 0x3d, mcp);
oled.init();
oled.buffer = bi.toByteArray();
oled.display();
// Register the flap gauge position address
UInt16 din; // Addr 10A0, Mask FFFF, Max Val FFFF, Shift 0
if (!Globals.BiosOutput.TryGetValue(0x10A0, out din)) {
Globals.BiosOutput.Add(0x10A0, 0x0000);
}
data.axis[0].mapsize = 0xFFFF;
data.axis[0].thres = 3;
this.Refresh();
data.prev = data.buttons;
data.axis[0].prev = data.axis[0].value;
data.changed = false;
return 1;
}
public override int Refresh() {
byte[] bytes;
int rslt = 0;
// Join all our buttons into a single inputs
rslt = chips[1].GetIO(out bytes);
data.buttons = (UInt64)bytes[0] << 24;
data.buttons |= (UInt64)bytes[1] << 16;
rslt = chips[0].GetIO(out bytes);
data.buttons |= (UInt64)bytes[0] << 8;
data.buttons |= (UInt64)bytes[1];
data.axis[0].value = mcp.ReadADC(0); // Y Axis
//ushort tmpval = 0;
//bool changed = data.axis[0].getPosition(ref tmpval);
//tmpval = 0;
if (data.buttons != data.prev || data.axis[0].value != data.axis[0].prev)
data.changed = true;
else
data.changed = false;
UInt16 tmpShadow = this.ledShadowA;
foreach (Led led in this.leds) {
led.Tick(ref ledShadowA);
}
// Only update if leds have changed
if (tmpShadow != this.ledShadowA) {
byte gpa = (byte)ledShadowA;
byte gpb = (byte)(ledShadowA >> 8);
chips[2].SetBank(0, (byte)gpa);
chips[2].SetBank(1, (byte)gpb);
}
return rslt;
}
public override int Input() {
//Console.WriteLine(data.buttons.ToString("X") + " " + data.axis[0].value.ToString());
foreach (Control control in this.controls) {
control.data = this.data;
control.Tick();
}
data.axis[0].prev = data.axis[0].value;
data.prev = data.buttons;
data.changed = false;
return 1;
}
}
}