Subversion Repositories group.electronics

Rev

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