Subversion Repositories group.electronics

Rev

Rev 163 | Rev 165 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 163 Rev 164
Line 26... Line 26...
26
            // 0 = UFC #, 1 = F1-F12 Keys, 2 = Misc (+ TrackIR)
26
            // 0 = UFC #, 1 = F1-F12 Keys, 2 = Misc (+ TrackIR)
27
            Switch3Pos selSwitch = new Switch3Pos(null, 2, 3);
27
            Switch3Pos selSwitch = new Switch3Pos(null, 2, 3);
28
 
28
 
29
            // Row 1
29
            // Row 1
30
            Dictionary<uint, Command> pad01 = new Dictionary<uint, Command>();
30
            Dictionary<uint, Command> pad01 = new Dictionary<uint, Command>();
31
            pad01.Add(0, new CommandDCS("UFC_01"));
31
            pad01.Add(0, new CommandDCS("UFC_1"));
32
            pad01.Add(1, new CommandVKey(VirtualKeyCode.F1));
32
            pad01.Add(1, new CommandVKey(VirtualKeyCode.F1));
33
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad01), 7));
33
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad01), 7));
34
 
34
 
35
            Dictionary<uint, Command> pad02 = new Dictionary<uint, Command>();
35
            Dictionary<uint, Command> pad02 = new Dictionary<uint, Command>();
36
            pad02.Add(0, new CommandDCS("UFC_02"));
36
            pad02.Add(0, new CommandDCS("UFC_2"));
37
            pad02.Add(1, new CommandVKey(VirtualKeyCode.F2));
37
            pad02.Add(1, new CommandVKey(VirtualKeyCode.F2));
38
            pad02.Add(2, new CommandTrackIRKey(VirtualKeyCode.F7));
38
            pad02.Add(2, new CommandTrackIRKey(VirtualKeyCode.F7));
39
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad02), 6));
39
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad02), 6));
40
 
40
 
41
            Dictionary<uint, Command> pad03 = new Dictionary<uint, Command>();
41
            Dictionary<uint, Command> pad03 = new Dictionary<uint, Command>();
42
            pad03.Add(0, new CommandDCS("UFC_03"));
42
            pad03.Add(0, new CommandDCS("UFC_3"));
43
            pad03.Add(1, new CommandVKey(VirtualKeyCode.F3));
43
            pad03.Add(1, new CommandVKey(VirtualKeyCode.F3));
44
            pad03.Add(2, new CommandTrackIRKey(VirtualKeyCode.F11));
44
            pad03.Add(2, new CommandTrackIRKey(VirtualKeyCode.F11));
45
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad03), 5));
45
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad03), 5));
46
 
46
 
47
            Dictionary<uint, Command> pad04 = new Dictionary<uint,Command>();
47
            Dictionary<uint, Command> pad04 = new Dictionary<uint,Command>();
Line 50... Line 50...
50
            pad04.Add(2, new CommandTrackIRKey(VirtualKeyCode.F9));
50
            pad04.Add(2, new CommandTrackIRKey(VirtualKeyCode.F9));
51
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad04), 4));
51
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad04), 4));
52
 
52
 
53
            // Row 2
53
            // Row 2
54
            Dictionary<uint, Command> pad05 = new Dictionary<uint, Command>();
54
            Dictionary<uint, Command> pad05 = new Dictionary<uint, Command>();
55
            pad05.Add(0, new CommandDCS("UFC_04"));
55
            pad05.Add(0, new CommandDCS("UFC_4"));
56
            pad05.Add(1, new CommandVKey(VirtualKeyCode.F5));
56
            pad05.Add(1, new CommandVKey(VirtualKeyCode.F5));
57
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad05), 11));
57
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad05), 11));
58
 
58
 
59
            Dictionary<uint, Command> pad06 = new Dictionary<uint, Command>();
59
            Dictionary<uint, Command> pad06 = new Dictionary<uint, Command>();
60
            pad06.Add(0, new CommandDCS("UFC_05"));
60
            pad06.Add(0, new CommandDCS("UFC_5"));
61
            pad06.Add(1, new CommandVKey(VirtualKeyCode.F6));
61
            pad06.Add(1, new CommandVKey(VirtualKeyCode.F6));
62
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad06), 10));
62
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad06), 10));
63
 
63
 
64
            Dictionary<uint, Command> pad07 = new Dictionary<uint, Command>();
64
            Dictionary<uint, Command> pad07 = new Dictionary<uint, Command>();
65
            pad07.Add(0, new CommandDCS("UFC_06"));
65
            pad07.Add(0, new CommandDCS("UFC_6"));
66
            pad07.Add(1, new CommandVKey(VirtualKeyCode.F7));
66
            pad07.Add(1, new CommandVKey(VirtualKeyCode.F7));
67
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad07), 9));
67
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad07), 9));
68
 
68
 
69
            Dictionary<uint, Command> pad08 = new Dictionary<uint, Command>();
69
            Dictionary<uint, Command> pad08 = new Dictionary<uint, Command>();
70
            pad08.Add(0, new CommandDCS("UFC_10"));
70
            pad08.Add(0, new CommandDCS("UFC_10"));
Line 76... Line 76...
76
            pad09.Add(0, new CommandDCS("UFC_7"));
76
            pad09.Add(0, new CommandDCS("UFC_7"));
77
            pad09.Add(1, new CommandVKey(VirtualKeyCode.F9));
77
            pad09.Add(1, new CommandVKey(VirtualKeyCode.F9));
78
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad09), 15));
78
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad09), 15));
79
 
79
 
80
            Dictionary<uint, Command> pad10 = new Dictionary<uint, Command>();
80
            Dictionary<uint, Command> pad10 = new Dictionary<uint, Command>();
81
            pad10.Add(0, new CommandDCS("UFC_08"));
81
            pad10.Add(0, new CommandDCS("UFC_8"));
82
            pad10.Add(1, new CommandVKey(VirtualKeyCode.F10));
82
            pad10.Add(1, new CommandVKey(VirtualKeyCode.F10));
83
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad10), 14));
83
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad10), 14));
84
 
84
 
85
            Dictionary<uint, Command> pad11 = new Dictionary<uint, Command>();
85
            Dictionary<uint, Command> pad11 = new Dictionary<uint, Command>();
86
            pad11.Add(0, new CommandDCS("UFC_09"));
86
            pad11.Add(0, new CommandDCS("UFC_9"));
87
            pad11.Add(1, new CommandVKey(VirtualKeyCode.F11));
87
            pad11.Add(1, new CommandVKey(VirtualKeyCode.F11));
88
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad11), 13));
88
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad11), 13));
89
 
89
 
90
            Dictionary<uint, Command> pad12 = new Dictionary<uint, Command>();
90
            Dictionary<uint, Command> pad12 = new Dictionary<uint, Command>();
91
            pad12.Add(0, new CommandDCS("UFC_CLR"));
91
            pad12.Add(0, new CommandDCS("UFC_CLR"));
92
            pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
92
            pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
93
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
93
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
94
 
94
 
95
 
95
 
96
 
-
 
97
            // Enable the mcp23017
96
            // Enable the mcp23017
98
            mcp.WriteGpio(3, 0);
97
            mcp.WriteGpio(3, 0);
99
            Utils.delayms(500);
98
            Utils.delayms(50);
100
            mcp.WriteGpio(3, 1);
99
            mcp.WriteGpio(3, 1);
101
            //this.delayms();
-
 
102
 
100
 
103
            // Set io dir, pullups and rev polarity
-
 
104
            //byte[] data;
-
 
105
            //data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
-
 
106
            //mcp.WriteI2cData(0x40, data, 5);
-
 
107
            //data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
-
 
108
            //mcp.WriteI2cData(0x40, data, 3);
-
 
109
            chip0.SetIODirection(0xff, 0xff);
101
            chip0.SetIODirection(0xff, 0xff);
-
 
102
            chip0.SetIOPolarity(0xff, 0xff);
110
            chip0.SetIOPullups(0xff, 0xff);
103
            chip0.SetIOPullups(0xff, 0xff);
111
 
104
 
112
            this.Refresh();
105
            this.Refresh();
113
            input.prev = input.curr;
106
            input.prev = input.curr;
114
 
107
 
Line 116... Line 109...
116
        }
109
        }
117
        public override int Refresh() {
110
        public override int Refresh() {
118
            byte[] data;
111
            byte[] data;
119
            int rslt = 0;
112
            int rslt = 0;
120
            rslt = chip0.GetIO(out data);
113
            rslt = chip0.GetIO(out data);
121
            //data = new byte[] { 0x12 }; // Select GPIOA register
-
 
122
            //mcp.WriteI2cData(0x40, data, 1);
-
 
123
            //byte[] data = new byte[] { 0x00, 0x00 }; // Read two bytes
-
 
124
            //int rslt = mcp.ReadI2CData(0x41, ref data, 2);
-
 
125
 
114
 
126
            // Join all our buttons into a single inputs
115
            // Join all our buttons into a single inputs
127
            uint gpio = (uint)(1 - mcp.ReadGpio(0));
116
            uint gpio = (uint)(1 - mcp.ReadGpio(0));
128
            input.curr = (uint)gpio << 16;
117
            input.curr = (uint)gpio << 16;
129
            input.curr |= (uint)data[0] << 8;
118
            input.curr |= (uint)data[0] << 8;
Line 136... Line 125...
136
 
125
 
137
            return rslt;
126
            return rslt;
138
        }
127
        }
139
 
128
 
140
        public override int Input() {
129
        public override int Input() {
141
            Console.WriteLine(input.curr.ToString("X"));
130
            //Console.WriteLine(input.curr.ToString("X"));
142
            foreach (Control control in this.controls) {
131
            foreach (Control control in this.controls) {
143
                control.data = this.input;
132
                control.data = this.input;
144
                control.Tick();
133
                control.Tick();
145
            }
134
            }
146
            this.inputChanged = false;
135
            this.inputChanged = false;