forked from curlyboi/WinTelive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmFreq.cs
233 lines (199 loc) · 7.51 KB
/
frmFreq.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using wintelive;
namespace wintelive
{
public partial class frmFreq : Form
{
public frmFreq()
{
InitializeComponent();
}
public void bindFreqs()
{
BindingSource bs = new BindingSource(telive.freqs.OrderBy(w => w.dl_freq), null);
grdFreqs.DataSource = bs;
}
public void rebindFreqs()
{
int rScroll = grdFreqs.FirstDisplayedScrollingRowIndex;
int rSel = -1;
if (grdFreqs.SelectedRows.Count > 0)
rSel = grdFreqs.SelectedRows[0].Index;
bindFreqs();
if (rSel != -1)
{
rSel = Math.Min(rSel, grdFreqs.Rows.Count - 1);
grdFreqs.Rows[rSel].Selected = true;
}
rScroll = Math.Min(rScroll, grdFreqs.Rows.Count - 1);
grdFreqs.FirstDisplayedScrollingRowIndex = rScroll;
}
public void bindUSIs()
{
BindingSource bs = new BindingSource(telive.usis.OrderBy(w => w.id), null);
grdUSIs.DataSource = bs;
}
public void bindRXs()
{
BindingSource bs = new BindingSource(telive.rxs.OrderBy(w => w.id), null);
grdRXs.DataSource = bs;
}
private void frmFreq_Load(object sender, EventArgs e)
{
bindFreqs();
bindRXs();
bindUSIs();
tmrRefresh.Enabled = true;
}
private void grdRXs_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
ushort rxid = 0;
if (e.RowIndex != -1)
{
rxid = (ushort)grdRXs[0, e.RowIndex].Value;
}
switch (e.ColumnIndex)
{
case 2:
frmTune ft = new frmTune(rxid, 0);
ft.Show();
break;
case 5:
frmMode fm = new frmMode(rxid);
fm.Show();
break;
}
}
private void grdFreqs_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
double nfreq = (double)grdFreqs[2, e.RowIndex].Value;
telive.receiver rx = telive.rxs.FirstOrDefault(w => w.mode == telive.rx_mode.OFF);
ushort rxid = (rx != null ? rx.id : (ushort)0);
frmTune ft = new frmTune(rxid, nfreq);
ft.Show();
}
private void txtBase_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
double nfreq = double.Parse(txtBase.Text);
if (!telive.baseSetSafe(nfreq))
{
MessageBox.Show("Baseband frequency could not be changed!", "Baseband change", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
e.Handled = true;
e.SuppressKeyPress = true;
}
}
private void chkLockBase_CheckedChanged(object sender, EventArgs e)
{
txtBase.Enabled = !chkLockBase.Checked;
}
private void lblBasefreq_Doubleclick(object sender, EventArgs e)
{
DialogResult drs = MessageBox.Show("Center baseband frequency?", "Center baseband", MessageBoxButtons.YesNo);
if (drs == DialogResult.Yes)
{
telive.baseCenter();
}
}
private void btnTuneNew_Click(object sender, EventArgs e)
{
telive.tuneAllFree();
}
public void grdFreqSelect(double freq)
{
grdFreqs.ClearSelection();
foreach (DataGridViewRow radek in grdFreqs.Rows)
{
if ((double)radek.Cells[2].Value == freq)
{
radek.Selected = true;
grdFreqs.FirstDisplayedScrollingRowIndex = radek.Index;
}
}
}
public void grdRXsSelect(ushort rxid)
{
grdRXs.ClearSelection();
grdRXs.Rows[rxid].Selected = true;
grdRXs.FirstDisplayedScrollingRowIndex = rxid;
}
private void tmrRefresh_Tick(object sender, EventArgs e)
{
if (!txtBase.Focused)
txtBase.Text = gnuradio.basefreq.ToString();
rebindFreqs();
grdRXs.Invalidate();
bindUSIs();
guiDrawGraph();
}
private void guiDrawGraph()
{
int ix = picFreqGraph.Width;
int iy = picFreqGraph.Height;
Bitmap bmp = new Bitmap(ix, iy);
Graphics gr = Graphics.FromImage(bmp);
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int x1, x2;
Brush bandBrush = new SolidBrush(Color.LightYellow);
Pen bandCenterPen = new Pen(Color.Orange);
Brush freqBrush = new SolidBrush(Color.Blue);
Brush freqSlaveBrush = new SolidBrush(Color.LightBlue);
Brush rxOffBrush = new SolidBrush(Color.FromArgb(128, 128, 128, 128));
Brush rxTunedBrush = new SolidBrush(Color.Cyan);
Brush rxScanBrush = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
Brush textBrush = new SolidBrush(Color.Black);
Font rxFont = new Font(FontFamily.GenericSansSerif, 7);
// baseband rect
x1 = telive.guiFreqToX(gnuradio.lowRange());
x2 = telive.guiFreqToX(gnuradio.HighRange()) - x1;
Rectangle bandRect = new Rectangle(x1, 0, x2, iy - 1);
gr.FillRectangle(bandBrush, bandRect);
gr.DrawRectangle(bandCenterPen, bandRect);
x1 = telive.guiFreqToX(gnuradio.basefreq);
gr.DrawLine(bandCenterPen, x1, 1, x1, iy - 2);
// frequencies
foreach (telive.frequency fre in telive.freqs)
{
x1 = telive.guiFreqToX(fre.dl_freq - gnuradio.cbw / 2);
x2 = telive.guiFreqToX(fre.dl_freq + gnuradio.cbw / 2) - x1;
Rectangle freqRect = new Rectangle(x1, 10, x2, iy - 12);
gr.FillRectangle((fre.mcc != 0 && fre.mnc != 0 ? freqBrush : freqSlaveBrush), freqRect);
}
// receivers
foreach (telive.receiver rx in telive.rxs)
{
x1 = telive.guiFreqToX(rx.freq - gnuradio.cbw / 2);
x2 = telive.guiFreqToX(rx.freq + gnuradio.cbw / 2) - x1;
Rectangle rxRect = new Rectangle(x1, 20, x2, iy - 22);
Brush thisbrush;
switch (rx.mode)
{
case telive.rx_mode.OFF: thisbrush = rxOffBrush; break;
case telive.rx_mode.TUNED: thisbrush = rxTunedBrush; break;
default: thisbrush = rxScanBrush; break;
}
gr.FillRectangle(thisbrush, rxRect);
if (rx.mode == telive.rx_mode.TUNED || rx.mode == telive.rx_mode.BANDSCAN)
{
x1 = telive.guiFreqToX(rx.freq);
gr.DrawString(rx.id.ToString(), rxFont, textBrush, x1 - 5, -1);
}
}
picFreqGraph.Image = bmp;
}
private void tmrAutotune_Tick(object sender, EventArgs e)
{
telive.tuneAllFree();
}
}
}