Subversion Repositories group.electronics

Rev

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

Rev 149 Rev 153
Line 11... Line 11...
11
namespace NITNavComm {
11
namespace NITNavComm {
12
    public class NITNavCommDevice : NITDevice  {
12
    public class NITNavCommDevice : NITDevice  {
13
 
13
 
14
        enum UsbCommands : byte {
14
        enum UsbCommands : byte {
15
            CMD_LATCH_DISPLAY = 20,
15
            CMD_LATCH_DISPLAY = 20,
16
            CMD_SET_DISPLAY0 = 21
16
            CMD_SET_DISPLAY = 21,
17
        };
17
        };
18
 
18
 
19
        private byte[,] display { get; set; }
19
        private byte[,] display { get; set; }
20
        private byte[] buttons {get; set; }
20
        private byte[] buttons {get; set; }
21
        private sbyte[,] rotary;
21
        private sbyte[,] rotary;
Line 48... Line 48...
48
 
48
 
49
        new public bool Close() {
49
        new public bool Close() {
50
            byte[] blank = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
50
            byte[] blank = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
51
            for (byte i = 0; i < 4; i++)
51
            for (byte i = 0; i < 4; i++)
52
                setFreq(i, ref blank);
52
                setFreq(i, ref blank);
53
            this.updateDisplay();
53
            this.UpdateDisplay();
54
            return base.Close();
54
            return base.Close();
55
        }
55
        }
56
 
56
 
57
        public byte[] getFreq(byte freq) {
57
        public byte[] getFreq(byte freq) {
58
            byte[] ret = new byte[5];
58
            byte[] ret = new byte[5];
Line 96... Line 96...
96
                        display[1, i + 5] = data[i];
96
                        display[1, i + 5] = data[i];
97
                    break;
97
                    break;
98
            }
98
            }
99
        }
99
        }
100
 
100
 
-
 
101
        public void setNavComFreqs(MainForm.NavCom_Data data) {
-
 
102
            byte[] freq0 = this.charArrayToBytes(data.Freq0.ToString().ToCharArray());
-
 
103
            byte[] freq1 = this.charArrayToBytes(data.Freq1.ToString().ToCharArray());
-
 
104
            byte[] freq2 = this.charArrayToBytes(data.Freq2.ToString().ToCharArray());
-
 
105
            byte[] freq3 = this.charArrayToBytes(data.Freq3.ToString().ToCharArray());
-
 
106
 
-
 
107
            this.setFreq(0, ref freq0);
-
 
108
            this.setFreq(1, ref freq1);
-
 
109
            this.setFreq(2, ref freq2);
-
 
110
            this.setFreq(3, ref freq3);
-
 
111
 
-
 
112
            this.UpdateDisplay();
-
 
113
        }
-
 
114
 
-
 
115
        private byte[] charArrayToBytes(char[] digits) {
-
 
116
            byte[] bytes = new byte[5];
-
 
117
            for (byte i = 0; i < 5; i++) {
-
 
118
                bytes[i] = (byte)(digits[i] - '0');
-
 
119
            }
-
 
120
            return bytes;
-
 
121
        }
-
 
122
 
-
 
123
        public void setDisplay(byte dis, ref byte[] data) {
-
 
124
            for (byte i = 0; i < data.Length; i++) {
-
 
125
                display[dis, i] = data[i];
-
 
126
            }
-
 
127
        }
-
 
128
 
101
        private void sendDigit(byte dis, byte dig, byte val, byte dp) {
129
        private void sendDigit(byte dis, byte dig, byte val, byte dp) {
102
            ushort wxValue = (ushort)(dis <<8);
130
            ushort wxValue = (ushort)(dis <<8);
103
            wxValue |= dig;
131
            wxValue |= dig;
104
            ushort wxIndex = (ushort)(dp << 8);
132
            ushort wxIndex = (ushort)(dp << 8);
105
            wxIndex |= val;
133
            wxIndex |= val;
106
 
134
 
107
            base.SendCommand(21, (short)wxValue, (short)wxIndex);
135
            base.SendCommand(21, (short)wxValue, (short)wxIndex);
108
        }
136
        }
109
 
137
 
110
        private void sendLatch(byte dis) {
138
        private void sendLatch(byte dis) {
-
 
139
            if (!this.isOpen())
-
 
140
                return;
-
 
141
 
111
            base.SendCommand(20, (short)dis, 0);
142
            base.SendCommand(20, (short)dis, 0);
112
        }
143
        }
113
 
144
 
114
        public void updateInput() {
145
        public void updateInput() {
115
            //this.updateInput(0);
-
 
116
            //this.updateInput(1);
-
 
117
            byte[] data = new byte[8];
146
            byte[] data = new byte[8];
118
            int transferred;
147
            int transferred;
119
            base.SendCommand(30, 0, 0, data, out transferred);
148
            base.SendCommand(30, 0, 0, data, out transferred);
120
            this.buttons[0] = data[0];
149
            this.buttons[0] = data[0];
121
            this.rotary[0, 0] += (sbyte)data[1];
150
            this.rotary[0, 0] += (sbyte)data[1];
Line 141... Line 170...
141
 
170
 
142
        public void resetRotary(byte display, byte rotary) {
171
        public void resetRotary(byte display, byte rotary) {
143
            this.rotary[display, rotary] = 0x00;
172
            this.rotary[display, rotary] = 0x00;
144
        }
173
        }
145
 
174
 
146
        public void updateDisplay() {
175
        public void UpdateDisplay() {
-
 
176
            this.sendData(0);
-
 
177
            this.sendData(1);
147
            this.updateDisplay(0);
178
            this.latchDisplay(0);
148
            this.updateDisplay(1);
179
            this.latchDisplay(1);
-
 
180
        }
-
 
181
 
-
 
182
        public void UpdateDisplay(byte dis) {
-
 
183
            this.sendData(dis);
-
 
184
            this.latchDisplay(dis);
149
        }
185
        }
150
 
186
 
151
        public void updateDisplay(byte dis) {
187
        private void sendData(byte dis) {
152
            for (byte i = 0; i < 10; i++) {
188
            for (byte i = 0; i < 10; i++) {
153
                this.sendDigit(dis, i, display[dis,i], 0);
189
                this.sendDigit(dis, i, display[dis, i], 0);
-
 
190
            }            
154
            }
191
        }
-
 
192
 
-
 
193
        private void latchDisplay(byte dis) {
155
            this.sendLatch(dis);
194
            this.sendLatch(dis);
156
        }
195
        }
157
 
196
 
158
        public void swapFreq(byte display) {
197
        public void swapFreq(byte display) {
159
            if (display == 0) {
198
            if (display == 0) {