Subversion Repositories group.electronics

Rev

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

Rev 159 Rev 160
Line 21... Line 21...
21
        public int id;
21
        public int id;
22
        public string name;
22
        public string name;
23
        public string function;
23
        public string function;
24
    }
24
    }
25
 
25
 
26
 
-
 
27
 
-
 
28
 
-
 
29
 
-
 
30
    public class mcp2221 {
26
    public class mcp2221 {
31
        DcsBios bios = new DcsBios();
27
        DcsBios bios = new DcsBios();
32
        MchpUsbI2c usbi2c = new MchpUsbI2c();
28
        public MchpUsbI2c usbi2c = new MchpUsbI2c();
33
        public Boolean hasAHFS { get; set; }
29
        public Boolean hasAHFS { get; set; }
34
        public Boolean hasAAP { get; set; }
30
        public Boolean hasAAP { get; set; }
35
 
31
 
36
        int idx { get; set; }
32
        int idx { get; set; }
37
        int devcount { get; set; }
33
        int devcount { get; set; }
38
        long dummy = 0;
-
 
39
 
34
 
40
        public uint speed { get; set; }
35
        public uint speed { get; set; }
41
 
36
 
42
        Timer refresh = new Timer();
37
        Timer refresh = new Timer();
43
        Timer delay = new Timer();
38
        Timer delay = new Timer();
Line 55... Line 50...
55
            refresh.Interval = 70;
50
            refresh.Interval = 70;
56
            refresh.AutoReset = true;
51
            refresh.AutoReset = true;
57
            refresh.Elapsed += refresh_Elapsed;
52
            refresh.Elapsed += refresh_Elapsed;
58
            refresh.Enabled = false;
53
            refresh.Enabled = false;
59
 
54
 
60
            delay.Interval = 5;
55
            
61
            delay.AutoReset = false;
-
 
62
            delay.Elapsed += delay_Elapsed;
-
 
63
            delay.Enabled = false;
-
 
64
 
56
 
65
            bios.InitUDP();
57
            bios.InitUDP();
66
 
58
 
67
            usbi2c.Settings.GetConnectionStatus();
59
            usbi2c.Settings.GetConnectionStatus();
68
            devcount = usbi2c.Management.GetDevCount();
60
            devcount = usbi2c.Management.GetDevCount();
Line 111... Line 103...
111
                this.enabled = true;
103
                this.enabled = true;
112
                refresh.Enabled = true;
104
                refresh.Enabled = true;
113
            }
105
            }
114
        }
106
        }
115
 
107
 
116
        void delay_Elapsed(object sender, ElapsedEventArgs e) {
-
 
117
            delay.Enabled = false;
-
 
118
        }
-
 
119
 
108
 
120
        void delayms(double ms = 100) {
-
 
121
            delay.Interval = ms;
-
 
122
            delay.Enabled = true;
-
 
123
            dummy = 0;
-
 
124
            while (delay.Enabled) { dummy++; }
-
 
125
        }
-
 
126
 
109
 
127
        void refresh_Elapsed(object sender, ElapsedEventArgs e) {
110
        void refresh_Elapsed(object sender, ElapsedEventArgs e) {
128
            if (!Enabled)
111
            if (!Enabled)
129
                return;
112
                return;
130
            devdata dev = devices[idx];
113
            devdata dev = devices[idx];
Line 145... Line 128...
145
        }
128
        }
146
 
129
 
147
        public void init_aap(int devid) {
130
        public void init_aap(int devid) {
148
            // Enable the mcp23017
131
            // Enable the mcp23017
149
            WriteGpio(3, 0);
132
            WriteGpio(3, 0);
150
            this.delayms(500);
133
            Utils.delayms(500);
151
            this.WriteGpio(3, 1);
134
            this.WriteGpio(3, 1);
152
            this.delayms();
135
            Utils.delayms();
153
 
136
 
154
            // Set io dir, pullups and rev polarity
137
            // Set io dir, pullups and rev polarity
155
            byte[] data;
138
            byte[] data;
156
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
139
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
157
            WriteI2cData(0x40, data, 5);
140
            WriteI2cData(0x40, data, 5);
Line 203... Line 186...
203
 
186
 
204
        }
187
        }
205
 
188
 
206
        public void init_ahfs(int devid) {
189
        public void init_ahfs(int devid) {
207
            WriteGpio(3, 0);
190
            WriteGpio(3, 0);
208
            this.delayms(500);
191
            Utils.delayms(500);
209
            // Enable the mcp23017
192
            // Enable the mcp23017
210
            WriteGpio(3, 1);
193
            WriteGpio(3, 1);
211
            this.delayms();
194
            Utils.delayms();
212
            // Set io dir, pullups and rev polarity
195
            // Set io dir, pullups and rev polarity
213
            byte[] data;
196
            byte[] data;
214
            // Soldered a couple of inputs wrong, the f0 is to reverse them (fuel boost switches)
197
            // Soldered a couple of inputs wrong, the f0 is to reverse them (fuel boost switches)
215
            data = new byte[] { 0x00, 0xff, 0xff, 0xf0, 0xff }; // All inputs & polarity
198
            data = new byte[] { 0x00, 0xff, 0xff, 0xf0, 0xff }; // All inputs & polarity
216
            WriteI2cData(0x40, data, 5);
199
            WriteI2cData(0x40, data, 5);