Subversion Repositories group.electronics

Rev

Rev 163 | Rev 165 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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