Subversion Repositories group.electronics

Rev

Rev 145 | Rev 153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
139 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
 
11
namespace NITNavComm {
12
    public partial class NITCommNavForm : Form {
13
 
14
        private NITNavCommDevice navcomm = null;
15
 
16
        public NITCommNavForm() {
17
            InitializeComponent();
18
 
19
            this.controlStatus(false);
20
        }
21
 
22
        private void controlStatus(bool status) {
23
            cmdSend0.Enabled = status;
24
            cmdSend1.Enabled = status;
25
            cmdUpdate.Enabled = status;
26
            inputTimer.Enabled = status;
27
        }
28
 
29
        public void UpdateDevice() {
30
            this.UpdateDisplay();
31
            this.UpdateInput();
32
        }
33
 
34
        public void UpdateDisplay(byte display) {
35
            byte[] data;
36
            if (display == 0) {
37
                data = navcomm.getFreq(0);
38
                freq0.Value = this.byteArraytoString(ref data, 5);
39
                data = navcomm.getFreq(1);
40
                freq1.Value = this.byteArraytoString(ref data, 5);
41
            } else {
42
                data = navcomm.getFreq(2);
43
                freq2.Value = this.byteArraytoString(ref data, 5);
44
                data = navcomm.getFreq(3);
45
                freq3.Value = this.byteArraytoString(ref data, 5);
46
            }
47
            navcomm.updateDisplay(display);
48
 
49
        }
50
 
51
        public void UpdateDisplay() {
52
            this.UpdateDisplay(0);
53
            this.UpdateDisplay(1);
54
        }
55
 
56
        public void UpdateInput() {
57
            this.UpdateInput(0);
58
        }
59
 
60
        public void UpdateInput(byte display) {
61
            navcomm.updateInput();
62
            cmdSwap0.Checked = navcomm.isSwapSet(0);
63
            cmdFlip0.Checked = navcomm.isFlipSet(0);
64
            txtRot0.Text = navcomm.getRotary(0, 0).ToString("X");
149 pfowler 65
 
66
            cmdSwap1.Checked = navcomm.isSwapSet(1);
67
            cmdFlip1.Checked = navcomm.isFlipSet(1);
68
            txtRot1.Text = navcomm.getRotary(1, 0).ToString("X");
139 pfowler 69
        }
70
 
71
        private string byteArraytoString(ref byte[] data, byte len) {
72
            StringBuilder sb = new StringBuilder();
73
            for (byte i = 0; i < len; i++) {
74
                if (data[i] == 0x0a)
75
                    sb.Append(' ');
76
                else
77
                    sb.Append((byte)(data[i]));
78
            }
79
            return sb.ToString();
80
        }
81
 
82
        public void setDevice(NITNavCommDevice navcomm) {
83
            this.navcomm = navcomm;
84
 
85
            if (!navcomm.isOpen())
86
                navcomm.Open();
87
 
88
            if (navcomm.isOpen())
89
                this.controlStatus(true);
90
        }
91
 
92
        public void SwapFreq(byte display) {
93
            navcomm.swapFreq(display);
94
            this.UpdateDisplay(display);
95
        }
96
 
97
        private void cmdSend0_Click(object sender, EventArgs e) {          
98
            char[] data = txtSend0.Text.ToArray();
99
            byte[] bytes = new byte[5];
100
            for (byte i = 0; i < 5; i++) {
101
                if (data[i] == 'a' || data[i] == ' ')
102
                    bytes[i] = (byte)0x0a;
103
                else
104
                    bytes[i] = (byte)(data[i] - '0');
105
            }
106
            navcomm.setFreq(1, ref bytes);
107
            this.UpdateDisplay(0);
108
        }
109
 
110
        private void cmdSend1_Click(object sender, EventArgs e) {
111
            char[] data = txtSend1.Text.ToArray();
112
            byte[] bytes = new byte[5];
113
            for (byte i = 0; i < 5; i++) {
114
                if (data[i] == 'a' || data[i] == ' ')
115
                    bytes[i] = (byte)0x0a;
116
                else
117
                    bytes[i] = (byte)(data[i] - '0');
118
            }
119
            navcomm.setFreq(3, ref bytes);
120
            this.UpdateDisplay(1);
121
        }
122
 
123
        private void cmdClose_Click(object sender, EventArgs e) {
124
            if (this.navcomm != null && this.navcomm.isOpen())
125
                navcomm.Close();
126
            this.Close();
127
        }
128
 
129
        private void cmdUpdate_Click(object sender, EventArgs e) {
130
            this.UpdateDevice();
131
        }
132
 
133
 
134
        private void cmdSwap0_CheckedChanged(object sender, EventArgs e) {
135
            if (cmdSwap0.Checked)
136
                this.SwapFreq(0);
137
        }
138
 
139
        private void cmdSwap0_Click(object sender, EventArgs e) {
140
            cmdSwap0.Checked = false;
141
        }
142
 
143
 
144
        private void inputTimer_Tick(object sender, EventArgs e) {
145
            this.UpdateInput();
146
        }
147
 
149 pfowler 148
        private void cmdSwap1_CheckedChanged(object sender, EventArgs e) {
149
            if (cmdSwap1.Checked)
150
                this.SwapFreq(1);
151
        }
152
 
153
        private void cmdFlip1_CheckedChanged(object sender, EventArgs e) {
154
 
155
        }
156
 
157
        private void cmdSwap1_Click(object sender, EventArgs e) {
158
            cmdSwap1.Checked = false;
159
        }
160
 
161
        private void txtRot0_Click(object sender, EventArgs e) {
162
            navcomm.resetRotary(0, 0);
163
        }
164
 
165
        private void txtRot1_Click(object sender, EventArgs e) {
166
            navcomm.resetRotary(1, 0);
167
        }
168
 
169
        private void freq0_Click(object sender, EventArgs e) {
170
            byte[] bytes = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a};
171
            navcomm.setFreq(0, ref bytes);
172
            this.UpdateDisplay(0);
173
        }
174
 
175
        private void freq1_Click(object sender, EventArgs e) {
176
            byte[] bytes = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
177
            navcomm.setFreq(1, ref bytes);
178
            this.UpdateDisplay(0);
179
        }
180
 
181
        private void freq2_Click(object sender, EventArgs e) {
182
            byte[] bytes = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
183
            navcomm.setFreq(2, ref bytes);
184
            this.UpdateDisplay(1);
185
        }
186
 
187
        private void freq3_Click(object sender, EventArgs e) {
188
            byte[] bytes = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a };
189
            navcomm.setFreq(3, ref bytes);
190
            this.UpdateDisplay(1);
191
        }
192
 
139 pfowler 193
    }
194
}