Subversion Repositories group.electronics

Rev

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

Rev 166 Rev 167
Line 6... Line 6...
6
using WindowsInput.Native;
6
using WindowsInput.Native;
7
 
7
 
8
namespace nitdcscore {
8
namespace nitdcscore {
9
    public class NitMultiPanel : Panel {
9
    public class NitMultiPanel : Panel {
10
 
10
 
11
        Utils.InputPair input;
11
        //Utils.InputPair input;
12
 
-
 
13
        Utils.InputPair js_x;
-
 
14
        Utils.InputPair js_y;
-
 
15
 
12
 
16
        private mcp23017[] chips;
13
        private mcp23017[] chips;
17
 
14
 
18
        public NitMultiPanel(mcp2221 mcp) : base(mcp) {
15
        public NitMultiPanel(mcp2221 mcp) : base(mcp) {
19
            chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x24) };
16
            chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x24) };
20
            input.curr = 0;
17
            //input.curr = 0;
21
            input.prev = 0;
18
            //input.prev = 0;
-
 
19
 
-
 
20
            data.buttons = 0;
-
 
21
            data.prev = 0;
22
 
22
 
-
 
23
            data.axis[0].mapsize = 0xffff;
23
            js_x.curr = js_x.prev = 0;
24
            data.axis[0].thres = 15;
-
 
25
 
-
 
26
            data.axis[1].mapsize = 0xffff;
24
            js_y.curr = js_y.prev = 0;
27
            data.axis[1].thres = 15;
25
 
28
 
26
            this.Init();
29
            this.Init();
27
        }
30
        }
28
 
31
 
29
        public override int Init() {
32
        public override int Init() {
Line 124... Line 127...
124
            chips[1].SetIODirection(0x00, 0xff);
127
            chips[1].SetIODirection(0x00, 0xff);
125
            chips[1].SetIOPolarity(0x00, 0xff);
128
            chips[1].SetIOPolarity(0x00, 0xff);
126
            chips[1].SetIOPullups(0x00, 0xff);
129
            chips[1].SetIOPullups(0x00, 0xff);
127
 
130
 
128
            this.Refresh();
131
            this.Refresh();
129
            input.prev = input.curr;
132
            //input.prev = input.curr;
-
 
133
 
-
 
134
            data.prev = data.buttons;
-
 
135
            data.axis[0].prev = data.axis[0].value;
-
 
136
            data.axis[1].prev = data.axis[1].value;
-
 
137
 
130
 
138
 
131
            return 1;
139
            return 1;
132
        }
140
        }
133
        public override int Refresh() {
141
        public override int Refresh() {
134
            byte[] data;
142
            byte[] bytes;
135
            int rslt = 0;
143
            int rslt = 0;
136
 
144
 
137
            // Join all our buttons into a single inputs
145
            // Join all our buttons into a single inputs
138
            UInt64 gpio = (UInt64)(1 - mcp.ReadGpio(0));
146
            UInt64 gpio = (UInt64)(1 - mcp.ReadGpio(0));
139
            input.curr = (UInt64)gpio << 32;
147
            data.buttons = (UInt64)gpio << 32;
140
            
148
 
141
            rslt = chips[1].GetIO(out data);
149
            rslt = chips[1].GetIO(out bytes);
142
            input.curr |= (UInt64)data[0] << 24;
150
            data.buttons |= (UInt64)bytes[0] << 24;
143
            input.curr |= (UInt64)data[1] << 16;
151
            data.buttons |= (UInt64)bytes[1] << 16;
144
 
152
 
145
            rslt = chips[0].GetIO(out data);
153
            rslt = chips[0].GetIO(out bytes);
146
            input.curr |= (UInt64)data[0] << 8;
154
            data.buttons |= (UInt64)bytes[0] << 8;
147
            input.curr |= (UInt64)data[1];
155
            data.buttons |= (UInt64)bytes[1];
148
 
156
 
149
            js_y.curr = mcp.ReadADC(0);
157
            data.axis[0].value = mcp.ReadADC(0);
150
            js_x.curr = mcp.ReadADC(1);
158
            data.axis[1].value = mcp.ReadADC(1);
151
        
-
 
152
 
159
 
153
            //Console.WriteLine(js_x.curr.ToString() + ":" + js_y.curr.ToString());
-
 
154
 
160
 
155
            if (input.curr != input.prev)
161
            if (data.buttons != data.prev)
156
                this.inputChanged = true;
162
                data.changed = true;
157
            else
163
            else
158
                this.inputChanged = false;
164
                data.changed = false;
159
 
165
 
160
            return rslt;
166
            return rslt;
161
        }
167
        }
162
 
168
 
163
        public override int Input() {
169
        public override int Input() {
164
            //Console.WriteLine(input.curr.ToString("X"));
170
            //Console.WriteLine(input.curr.ToString("X"));
165
            foreach (Control control in this.controls) {
171
            foreach (Control control in this.controls) {
166
                control.data = this.input;
172
                control.data = this.data;
167
                control.Tick();
173
                control.Tick();
168
            }
174
            }
169
            this.inputChanged = false;
175
            data.changed = false;
170
 
176
 
171
            input.prev = input.curr;
177
            data.prev = data.buttons;
172
            return 1;
178
            return 1;
173
        }
179
        }
174
    }
180
    }
175
}
181
}