Subversion Repositories group.electronics

Rev

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

Rev 165 Rev 166
Line 11... Line 11...
11
        Utils.InputPair input;
11
        Utils.InputPair input;
12
 
12
 
13
        Utils.InputPair js_x;
13
        Utils.InputPair js_x;
14
        Utils.InputPair js_y;
14
        Utils.InputPair js_y;
15
 
15
 
16
        private mcp23017 chip0;
16
        private mcp23017[] chips;
17
 
17
 
18
        public NitMultiPanel(mcp2221 mcp)
18
        public NitMultiPanel(mcp2221 mcp) : base(mcp) {
19
            : base(mcp) {
19
            chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x24) };
20
            input.curr = 0;
20
            input.curr = 0;
21
            input.prev = 0;
21
            input.prev = 0;
22
 
22
 
23
            js_x.curr = js_x.prev = 0;
23
            js_x.curr = js_x.prev = 0;
24
            js_y.curr = js_y.prev = 0;
24
            js_y.curr = js_y.prev = 0;
25
 
25
 
26
            this.chip0 = new mcp23017(mcp, 0x20);
-
 
27
 
-
 
28
            this.Init();
26
            this.Init();
29
        }
27
        }
30
 
28
 
31
        public override int Init() {
29
        public override int Init() {
32
            // Choose what function the number pad shall carry out:
30
            // Choose what function the number pad shall carry out:
Line 98... Line 96...
98
            pad12.Add(0, new CommandDCS("UFC_CLR"));
96
            pad12.Add(0, new CommandDCS("UFC_CLR"));
99
            pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
97
            pad12.Add(1, new CommandVKey(VirtualKeyCode.F12));
100
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
98
            this.addControl(new Switch2Pos(new CommandIf(selSwitch, pad12), 12));
101
 
99
 
102
            // Joystick Press - Mapped to mouse button 1
100
            // Joystick Press - Mapped to mouse button 1
103
            this.addControl(new Switch2Pos(new CommandMouseButton(CommandMouseButton.MB_LEFT), 16));
101
            this.addControl(new Switch2Pos(new CommandMouseButton(CommandMouseButton.MB_LEFT), 32));
-
 
102
 
-
 
103
 
-
 
104
            // NMSP
-
 
105
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_EGI_BTN"), 16));
-
 
106
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_HARS_BTN"), 17));
-
 
107
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_ILS_BTN"), 18));
-
 
108
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_TCN_BTN"), 19));
-
 
109
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_ANCHR_BTN"), 20));
-
 
110
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_STEERPT_BTN"), 21));
-
 
111
            this.addControl(new Switch2Pos(new CommandDCS("NMSP_ABLE_STOW"), 22, true));
104
 
112
 
105
 
113
 
106
            // Enable the mcp23017
114
            // Enable the mcp23017
107
            mcp.WriteGpio(3, 0);
115
            mcp.WriteGpio(3, 0);
108
            Utils.delayms(50);
116
            Utils.delayms(50);
109
            mcp.WriteGpio(3, 1);
117
            mcp.WriteGpio(3, 1);
-
 
118
            Utils.delayms(50);
110
 
119
 
111
            chip0.SetIODirection(0xff, 0xff);
120
            chips[0].SetIODirection(0xff, 0xff);
112
            chip0.SetIOPolarity(0xff, 0xff);
121
            chips[0].SetIOPolarity(0xff, 0xff);
113
            chip0.SetIOPullups(0xff, 0xff);
122
            chips[0].SetIOPullups(0xff, 0xff);
-
 
123
 
-
 
124
            chips[1].SetIODirection(0x00, 0xff);
-
 
125
            chips[1].SetIOPolarity(0x00, 0xff);
-
 
126
            chips[1].SetIOPullups(0x00, 0xff);
114
 
127
 
115
            this.Refresh();
128
            this.Refresh();
116
            input.prev = input.curr;
129
            input.prev = input.curr;
117
 
130
 
118
            return 1;
131
            return 1;
119
        }
132
        }
120
        public override int Refresh() {
133
        public override int Refresh() {
121
            byte[] data;
134
            byte[] data;
122
            int rslt = 0;
135
            int rslt = 0;
123
            rslt = chip0.GetIO(out data);
-
 
124
 
136
 
125
            // Join all our buttons into a single inputs
137
            // Join all our buttons into a single inputs
126
            uint gpio = (uint)(1 - mcp.ReadGpio(0));
138
            UInt64 gpio = (UInt64)(1 - mcp.ReadGpio(0));
127
            input.curr = (uint)gpio << 16;
139
            input.curr = (UInt64)gpio << 32;
-
 
140
            
-
 
141
            rslt = chips[1].GetIO(out data);
-
 
142
            input.curr |= (UInt64)data[0] << 24;
-
 
143
            input.curr |= (UInt64)data[1] << 16;
-
 
144
 
-
 
145
            rslt = chips[0].GetIO(out data);
128
            input.curr |= (uint)data[0] << 8;
146
            input.curr |= (UInt64)data[0] << 8;
129
            input.curr |= (uint)data[1];
147
            input.curr |= (UInt64)data[1];
130
 
148
 
131
            js_y.curr = mcp.ReadADC(0);
149
            js_y.curr = mcp.ReadADC(0);
132
            js_x.curr = mcp.ReadADC(1);
150
            js_x.curr = mcp.ReadADC(1);
133
            
151
        
134
 
152
 
135
            //Console.WriteLine(js_x.curr.ToString() + ":" + js_y.curr.ToString());
153
            //Console.WriteLine(js_x.curr.ToString() + ":" + js_y.curr.ToString());
136
 
154
 
137
            if (input.curr != input.prev)
155
            if (input.curr != input.prev)
138
                this.inputChanged = true;
156
                this.inputChanged = true;
Line 141... Line 159...
141
 
159
 
142
            return rslt;
160
            return rslt;
143
        }
161
        }
144
 
162
 
145
        public override int Input() {
163
        public override int Input() {
146
            Console.WriteLine(input.curr.ToString("X"));
164
            //Console.WriteLine(input.curr.ToString("X"));
147
            foreach (Control control in this.controls) {
165
            foreach (Control control in this.controls) {
148
                control.data = this.input;
166
                control.data = this.input;
149
                control.Tick();
167
                control.Tick();
150
            }
168
            }
151
            this.inputChanged = false;
169
            this.inputChanged = false;