Subversion Repositories group.electronics

Rev

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

Rev 162 Rev 163
Line 7... Line 7...
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
        private mcp23017 chip0;
12
 
13
 
13
        public NitMultiPanel(mcp2221 mcp)
14
        public NitMultiPanel(mcp2221 mcp)
14
            : base(mcp) {
15
            : base(mcp) {
15
            input.curr = 0;
16
            input.curr = 0;
16
            input.prev = 0;
17
            input.prev = 0;
17
 
18
 
-
 
19
            this.chip0 = new mcp23017(mcp, 0x20);
-
 
20
 
18
            this.Init();
21
            this.Init();
19
        }
22
        }
20
 
23
 
21
        public override int Init() {
24
        public override int Init() {
22
            // Choose what function the number pad shall carry out:
25
            // Choose what function the number pad shall carry out:
Line 96... Line 99...
96
            Utils.delayms(500);
99
            Utils.delayms(500);
97
            mcp.WriteGpio(3, 1);
100
            mcp.WriteGpio(3, 1);
98
            //this.delayms();
101
            //this.delayms();
99
 
102
 
100
            // Set io dir, pullups and rev polarity
103
            // Set io dir, pullups and rev polarity
101
            byte[] data;
104
            //byte[] data;
102
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
105
            //data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
103
            mcp.WriteI2cData(0x40, data, 5);
106
            //mcp.WriteI2cData(0x40, data, 5);
104
            data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
107
            //data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
105
            mcp.WriteI2cData(0x40, data, 3);
108
            //mcp.WriteI2cData(0x40, data, 3);
-
 
109
            chip0.SetIODirection(0xff, 0xff);
-
 
110
            chip0.SetIOPullups(0xff, 0xff);
106
 
111
 
107
            this.Refresh();
112
            this.Refresh();
108
            input.prev = input.curr;
113
            input.prev = input.curr;
109
 
114
 
110
            return 1;
115
            return 1;
111
        }
116
        }
112
        public override int Refresh() {
117
        public override int Refresh() {
113
            byte[] data;
118
            byte[] data;
-
 
119
            int rslt = 0;
-
 
120
            rslt = chip0.GetIO(out data);
114
            data = new byte[] { 0x12 }; // Select GPIOA register
121
            //data = new byte[] { 0x12 }; // Select GPIOA register
115
            mcp.WriteI2cData(0x40, data, 1);
122
            //mcp.WriteI2cData(0x40, data, 1);
116
 
-
 
117
            data = new byte[] { 0x00, 0x00 }; // Read two bytes
123
            //byte[] data = new byte[] { 0x00, 0x00 }; // Read two bytes
118
            int rslt = mcp.ReadI2CData(0x41, ref data, 2);
124
            //int rslt = mcp.ReadI2CData(0x41, ref data, 2);
119
 
125
 
120
            // Join all our buttons into a single inputs
126
            // Join all our buttons into a single inputs
121
            uint gpio = (uint)(1 - mcp.ReadGpio(0));
127
            uint gpio = (uint)(1 - mcp.ReadGpio(0));
122
            input.curr = (uint)gpio << 16;
128
            input.curr = (uint)gpio << 16;
123
            input.curr |= (uint)data[0] << 8;
129
            input.curr |= (uint)data[0] << 8;
Line 135... Line 141...
135
            Console.WriteLine(input.curr.ToString("X"));
141
            Console.WriteLine(input.curr.ToString("X"));
136
            foreach (Control control in this.controls) {
142
            foreach (Control control in this.controls) {
137
                control.data = this.input;
143
                control.data = this.input;
138
                control.Tick();
144
                control.Tick();
139
            }
145
            }
140
            input.prev = input.curr;
-
 
141
            this.inputChanged = false;
146
            this.inputChanged = false;
-
 
147
 
-
 
148
            input.prev = input.curr;
142
            return 1;
149
            return 1;
143
        }
150
        }
144
    }
151
    }
145
}
152
}