Subversion Repositories group.electronics

Rev

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

Rev 162 Rev 164
Line 61... Line 61...
61
        Utils.InputPair adcInput;
61
        Utils.InputPair adcInput;
62
 
62
 
63
        public uint adc_max;
63
        public uint adc_max;
64
        public uint adc_threshold;
64
        public uint adc_threshold;
65
 
65
 
-
 
66
        private mcp23017[] chips;
-
 
67
 
66
        public Panel_AHFS(mcp2221 mcp) : base(mcp) {
68
        public Panel_AHFS(mcp2221 mcp) : base(mcp) {
-
 
69
            chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x21) };
-
 
70
 
67
            switchInput.curr = 0;
71
            switchInput.curr = 0;
68
            switchInput.prev = 0;
72
            switchInput.prev = 0;
69
            adcInput.curr = 0;
73
            adcInput.curr = 0;
70
            adcInput.prev = 0;
74
            adcInput.prev = 0;
71
            this.adc_max = 930;
75
            this.adc_max = 930;
Line 105... Line 109...
105
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_LINE_CHECK"), 17));
109
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_LINE_CHECK"), 17));
106
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_RCVR_LEVER"), 23));
110
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_RCVR_LEVER"), 23));
107
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_TK_GATE"), 29));
111
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_TK_GATE"), 29));
108
             
112
             
109
            mcp.WriteGpio(3, 0);
113
            mcp.WriteGpio(3, 0);
110
            Utils.delayms(500);
114
            Utils.delayms(10);
111
            // Enable the mcp23017
115
            // Enable the mcp23017
112
            mcp.WriteGpio(3, 1);
116
            mcp.WriteGpio(3, 1);
113
            Utils.delayms();
117
            
114
            // Set io dir, pullups and rev polarity
118
            // Set io dir, pullups and rev polarity
115
            byte[] data;
119
            chips[0].SetIODirection(0xff, 0xff);
116
            // Soldered a couple of inputs wrong, the f0 is to reverse them (fuel boost switches)
-
 
117
            data = new byte[] { 0x00, 0xff, 0xff, 0xf0, 0xff }; // All inputs & polarity
-
 
118
            mcp.WriteI2cData(0x40, data, 5);
120
            chips[0].SetIOPolarity(0xf0, 0xff);
119
            data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
-
 
120
            mcp.WriteI2cData(0x40, data, 3);
121
            chips[0].SetIOPullups(0xff, 0xff);
121
 
122
 
122
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
-
 
123
            mcp.WriteI2cData(0x42, data, 5);
123
            chips[1].SetIODirection(0xff, 0xff);
124
            data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
124
            chips[1].SetIOPolarity(0xff, 0xff);
125
            int rslt = mcp.WriteI2cData(0x42, data, 3);
125
            chips[1].SetIOPullups(0xff, 0xff);
126
 
126
 
127
            // Get the initial ADC value
127
            // Get the initial ADC value
128
            adcInput.prev = adcInput.curr = mcp.ReadADC(1);
128
            adcInput.prev = adcInput.curr = mcp.ReadADC(1);
129
            this.Refresh();
129
            this.Refresh();
130
            switchInput.prev = switchInput.curr;
130
            switchInput.prev = switchInput.curr;
131
 
131
 
132
            return rslt;
132
            return 0;
133
        }
133
        }
134
 
134
 
135
        public override int Refresh() {
135
        public override int Refresh() {
136
 
136
 
137
            byte[] data;
137
            byte[] data;
138
            data = new byte[] { 0x12 }; // Select GPIOA register
-
 
139
            mcp.WriteI2cData(0x40, data, 1);
-
 
140
            
138
            int rslt = 0;
141
            data = new byte[] { 0x00, 0x00 }; // Read two bytes
-
 
142
            mcp.ReadI2CData(0x41, ref data, 2);
139
            rslt = chips[0].GetIO(out data);
143
            
140
            
144
            switchInput.curr = (uint)data[0] << 24;
141
            switchInput.curr = (uint)data[0] << 24;
145
            switchInput.curr |= (uint)data[1] << 16;
142
            switchInput.curr |= (uint)data[1] << 16;
146
            
143
 
147
            data = new byte[] { 0x12 }; // Select GPIOA register
-
 
148
            mcp.WriteI2cData(0x42, data, 1);
144
            rslt = chips[1].GetIO(out data);
149
            
-
 
150
            data = new byte[] { 0x00, 0x00 }; // Read two bytes
-
 
151
            mcp.ReadI2CData(0x43, ref data, 2);
-
 
152
            
145
            
153
            switchInput.curr |= (uint)data[0] << 8;
146
            switchInput.curr |= (uint)data[0] << 8;
154
            switchInput.curr |= (uint)data[1];
147
            switchInput.curr |= (uint)data[1];
155
 
148
 
156
            /*
149
            /*
Line 193... Line 186...
193
 
186
 
194
            return 1;
187
            return 1;
195
        }
188
        }
196
 
189
 
197
        public override int Input() {
190
        public override int Input() {
-
 
191
            
198
            foreach (Control control in this.controls) {
192
            foreach (Control control in this.controls) {
199
                control.data = this.switchInput;
193
                control.data = this.switchInput;
200
                control.Tick();
194
                control.Tick();
201
            }
195
            }
202
            switchInput.prev = switchInput.curr;
196
            switchInput.prev = switchInput.curr;
Line 207... Line 201...
207
    }
201
    }
208
 
202
 
209
    public class Panel_AAP : Panel {
203
    public class Panel_AAP : Panel {
210
 
204
 
211
        Utils.InputPair input;
205
        Utils.InputPair input;
-
 
206
        private mcp23017 chip0;
212
 
207
 
213
        public Panel_AAP(mcp2221 mcp) : base(mcp) {
208
        public Panel_AAP(mcp2221 mcp) : base(mcp) {
214
            input.curr = 0;
209
            input.curr = 0;
215
            input.prev = 0;
210
            input.prev = 0;
216
 
211
 
-
 
212
            chip0 = new mcp23017(mcp, 0x20);
-
 
213
 
217
            this.Init();
214
            this.Init();
218
        }
215
        }
219
 
216
 
220
        public override int Init() {
217
        public override int Init() {
221
            this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F9), 16));
218
            this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F9), 16));
Line 230... Line 227...
230
            this.addControl(new Selector(new CommandDCS("AAP_STEERPT"), new int[] { 4, 5, 6 }));
227
            this.addControl(new Selector(new CommandDCS("AAP_STEERPT"), new int[] { 4, 5, 6 }));
231
            this.addControl(new Selector(new CommandDCS("AAP_PAGE"), new int[] { 0, 1, 2, 3 }));
228
            this.addControl(new Selector(new CommandDCS("AAP_PAGE"), new int[] { 0, 1, 2, 3 }));
232
 
229
 
233
            // Enable the mcp23017
230
            // Enable the mcp23017
234
            mcp.WriteGpio(3, 0);
231
            mcp.WriteGpio(3, 0);
235
            Utils.delayms(500);
232
            Utils.delayms(10);
236
            mcp.WriteGpio(3, 1);
233
            mcp.WriteGpio(3, 1);
237
            //this.delayms();
-
 
238
 
234
 
239
            // Set io dir, pullups and rev polarity
235
            // Set io dir, pullups and rev polarity
240
            byte[] data;
236
            chip0.SetIODirection(0xff, 0xff);
241
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
-
 
242
            mcp.WriteI2cData(0x40, data, 5);
237
            chip0.SetIOPolarity(0xff, 0xff);
243
            data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
-
 
244
            mcp.WriteI2cData(0x40, data, 3);
238
            chip0.SetIOPullups(0xff, 0xff);
245
 
239
 
246
            this.Refresh();
240
            this.Refresh();
247
            input.prev = input.curr;
241
            input.prev = input.curr;
248
 
242
 
249
            return 1;
243
            return 1;
250
        }
244
        }
251
        public override int Refresh() {
245
        public override int Refresh() {
252
            byte[] data;
246
            byte[] data;
253
            data = new byte[] { 0x12 }; // Select GPIOA register
-
 
254
            mcp.WriteI2cData(0x40, data, 1);
247
            int rslt = 0;
255
 
-
 
256
            data = new byte[] { 0x00, 0x00 }; // Read two bytes
-
 
257
            int rslt = mcp.ReadI2CData(0x41, ref data, 2);
248
            rslt = chip0.GetIO(out data);
258
 
249
 
259
            // Join all our buttons into a single inputs
250
            // Join all our buttons into a single inputs
260
            uint gpio = (uint)((1 - mcp.ReadGpio(0)) | ((1 - mcp.ReadGpio(1)) << 1));
251
            uint gpio = (uint)((1 - mcp.ReadGpio(0)) | ((1 - mcp.ReadGpio(1)) << 1));
261
            input.curr = (uint)gpio << 16;
252
            input.curr = (uint)gpio << 16;
262
            input.curr |= (uint)data[0] << 8;
253
            input.curr |= (uint)data[0] << 8;