Rev 163 | Rev 165 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsInput.Native;
namespace nitdcscore {
public class NitMultiPanel : Panel {
Utils.InputPair input;
private mcp23017 chip0;
public NitMultiPanel(mcp2221 mcp)
: base(mcp) {
input.curr = 0;
input.prev = 0;
this.chip0 = new mcp23017(mcp, 0x20);
this.Init();
}
public override int Init() {
// Choose what function the number pad shall carry out:
// 0 = UFC #, 1 = F1-F12 Keys, 2 = Misc (+ TrackIR)
Switch3Pos selSwitch = new Switch3Pos(null, 2, 3);
// Row 1
Dictionary<uint, Command> pad01 = new Dictionary<uint, Command>();
pad01.Add(0, new CommandDCS("UFC_1"));
pad01.Add(1, new CommandVKey(VirtualKeyCode.F1));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad01), 7));
Dictionary<uint, Command> pad02 = new Dictionary<uint, Command>();
pad02.Add(0, new CommandDCS("UFC_2"));
pad02.Add(1, new CommandVKey(VirtualKeyCode.F2));
pad02.Add(2, new CommandTrackIRKey(VirtualKeyCode.F7));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad02), 6));
Dictionary<uint, Command> pad03 = new Dictionary<uint, Command>();
pad03.Add(0, new CommandDCS("UFC_3"));
pad03.Add(1, new CommandVKey(VirtualKeyCode.F3));
pad03.Add(2, new CommandTrackIRKey(VirtualKeyCode.F11));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad03), 5));
Dictionary<uint, Command> pad04 = new Dictionary<uint,Command>();
pad04.Add(0, new CommandDCS("UFC_ENT"));
pad04.Add(1, new CommandVKey(VirtualKeyCode.F4));
pad04.Add(2, new CommandTrackIRKey(VirtualKeyCode.F9));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad04), 4));
// Row 2
Dictionary<uint, Command> pad05 = new Dictionary<uint, Command>();
pad05.Add(0, new CommandDCS("UFC_4"));
pad05.Add(1, new CommandVKey(VirtualKeyCode.F5));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad05), 11));
Dictionary<uint, Command> pad06 = new Dictionary<uint, Command>();
pad06.Add(0, new CommandDCS("UFC_5"));
pad06.Add(1, new CommandVKey(VirtualKeyCode.F6));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad06), 10));
Dictionary<uint, Command> pad07 = new Dictionary<uint, Command>();
pad07.Add(0, new CommandDCS("UFC_6"));
pad07.Add(1, new CommandVKey(VirtualKeyCode.F7));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad07), 9));
Dictionary<uint, Command> pad08 = new Dictionary<uint, Command>();
pad08.Add(0, new CommandDCS("UFC_10"));
pad08.Add(1, new CommandVKey(VirtualKeyCode.F8));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad08), 8));
// Row 3
Dictionary<uint, Command> pad09 = new Dictionary<uint, Command>();
pad09.Add(0, new CommandDCS("UFC_7"));
pad09.Add(1, new CommandVKey(VirtualKeyCode.F9));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad09), 15));
Dictionary<uint, Command> pad10 = new Dictionary<uint, Command>();
pad10.Add(0, new CommandDCS("UFC_8"));
pad10.Add(1, new CommandVKey(VirtualKeyCode.F10));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad10), 14));
Dictionary<uint, Command> pad11 = new Dictionary<uint, Command>();
pad11.Add(0, new CommandDCS("UFC_9"));
pad11.Add(1, new CommandVKey(VirtualKeyCode.F11));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad11), 13));
Dictionary<uint, Command> pad12 = new Dictionary<uint, Command>();
pad12.Add(0, new CommandDCS("UFC_CLR"));
pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
// Enable the mcp23017
mcp.WriteGpio(3, 0);
Utils.delayms(50);
mcp.WriteGpio(3, 1);
chip0.SetIODirection(0xff, 0xff);
chip0.SetIOPolarity(0xff, 0xff);
chip0.SetIOPullups(0xff, 0xff);
this.Refresh();
input.prev = input.curr;
return 1;
}
public override int Refresh() {
byte[] data;
int rslt = 0;
rslt = chip0.GetIO(out data);
// Join all our buttons into a single inputs
uint gpio = (uint)(1 - mcp.ReadGpio(0));
input.curr = (uint)gpio << 16;
input.curr |= (uint)data[0] << 8;
input.curr |= (uint)data[1];
if (input.curr != input.prev)
this.inputChanged = true;
else
this.inputChanged = false;
return rslt;
}
public override int Input() {
//Console.WriteLine(input.curr.ToString("X"));
foreach (Control control in this.controls) {
control.data = this.input;
control.Tick();
}
this.inputChanged = false;
input.prev = input.curr;
return 1;
}
}
}