-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui.cpp
1161 lines (993 loc) · 32.3 KB
/
gui.cpp
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file gui.cpp
* @brief Header for Extio DLL GUI classes
* @author Andrea Montefusco IW0HDV
* @version 0.0
* @date 2013-09-23
*/
/* Copyright (C)
* Andrea Montefusco IW0HDV
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#if defined _MSC_VER || defined __MINGW32__
#include <winsock2.h>
#include <iphlpapi.h>
#pragma comment (lib, "ws2_32.lib")
// Link with Iphlpapi.lib
#pragma comment(lib, "IPHLPAPI.lib")
#include <windowsx.h>
#include <commctrl.h> // Include header
#pragma comment(lib, "comctl32.lib") // Include library
#pragma warning( disable : 4995 )
#endif
#if defined _MSC_VER
#include <strsafe.h>
#endif
#include "util.h"
#include "hpsdr.h"
#include "log.h"
#include "resource.h"
#include "log.h"
#include "dllmain.h" // for GetMyHandle()
#include "Extio_config.h"
#include "ExtIO_hermes.h"
#include "guievent.h"
#include "guiutil.h"
#include "gui.h"
static const char *buildString = " - " __DATE__ ", " __TIME__ " - "
#if defined _MSC_VER
"ms";
#elif defined __MINGW32__
"gcc";
#else
"";
#endif
/*
* Gui utilities
*
*/
struct WSize {
WSize() = delete;
WSize(HWND hd)
{
RECT rd, rD;
GetWindowRect(GetDesktopWindow(), &rD);
GetWindowRect(hd, &rd);
x1 = rd.left, x2 = rd.right, y1 = rd.top, y2 = rd.bottom;
w = x2 - x1;
h = y2 - y1;
x1_dt = rD.left, x2_dt = rD.right, y1_dt = rD.top, y2_dt = rD.bottom;
w_dt = rD.right - rD.left;
h_dt = rD.bottom - rD.top;
}
void center(int &x, int &y)
{
x = (w_dt / 2) - (w / 2);
y = (h_dt / 2) - (h / 2);
}
void lower_right(int &xx, int &yy)
{
xx = x2_dt - w;
yy = y2_dt - h;
}
int x1, x2, y1, y2, w, h;
int x1_dt, x2_dt, y1_dt, y2_dt, w_dt, h_dt;
};
/*
* Gui base class
*
*/
class GuiImpl {
public:
GuiImpl(): hDialog(NULL), pr(0), pExr(0) {}
HWND hDialog;
Radio *pr;
ExtioHpsdrRadio < EXTIO_BASE_TYPE > *pExr;
virtual ~GuiImpl () {}
public:
static BOOL CALLBACK CtrlBoxDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL CtrlBoxDlgProcOnInit(HWND hDlg, HWND hFocus, LPARAM lParam);
static BOOL CtrlBoxDlgProcOnHScroll(
HWND hWnd, // hwnd
HWND hwndCtl, // (int)(LOWORD(wParam))
UINT codeNotify, // (UINT)HIWORD(wParam))
int pos
);
static BOOL CtrlBoxDlgProcOnCommand(
HWND hWnd, // hwnd
int id, // (int)(LOWORD(wParam))
HWND hCtl, // (HWND)(lParam)
UINT codeNotify // (UINT)HIWORD(wParam))
);
static BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam);
};
//
// (hwnd), (int)(LOWORD(wParam)), (HWND)(lParam), (UINT)HIWORD(wParam)), 0L
//
BOOL GuiImpl::CtrlBoxDlgProcOnCommand (
HWND hWnd, // hwnd
int id, // (int)(LOWORD(wParam))
HWND hCtl, // (HWND)(lParam)
UINT codeNotify // (UINT)HIWORD(wParam))
)
{
LOGT("%p\n", GetWindowLongPtr(hWnd, GWLP_USERDATA));
Gui *pGui = (Gui *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (pGui) {
LOGT("********************************* Gui addr: %p pi: %p\n", pGui, pGui->pi);
// some button/checkbox has been clicked
// the lower word of wParam holds the controls ID
if (codeNotify == BN_CLICKED) pGui->ButtonClick(GuiEvent(hWnd, id));
if (codeNotify == LBN_DBLCLK) pGui->ListBoxDoubleClick(GuiEvent(hWnd, id));
}
return TRUE;
}
BOOL GuiImpl::CtrlBoxDlgProcOnInit(HWND hDlg, HWND hFocus, LPARAM lParam)
{
LOGT("%08x\n", lParam);
Gui *pGui = (Gui *)lParam;
LOGT("********************************* Gui addr: %p\n", pGui);
return TRUE;
}
BOOL CALLBACK GuiImpl::CtrlBoxDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BOOL fProcessed = TRUE;
Gui *pGui = (Gui *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
//LOGT("********************************* %u %ld %d Gui addr: %p\n", uMsg, wParam, lParam, pGui);
switch (uMsg) {
HANDLE_MSG(hDlg, WM_INITDIALOG, GuiImpl::CtrlBoxDlgProcOnInit);
HANDLE_MSG(hDlg, WM_COMMAND, GuiImpl::CtrlBoxDlgProcOnCommand);
HANDLE_MSG(hDlg, WM_HSCROLL, GuiImpl::CtrlBoxDlgProcOnHScroll);
default:
// process WM_USER messages avoiding to be fooled from WM_APP
if (uMsg > WM_USER && uMsg < WM_APP) {
//LOGT("********************************* MSG: 0x%08X WM_USER + %d\n", uMsg, uMsg - WM_USER);
if (pGui) pGui->OnWmUser(uMsg - WM_USER, GuiEvent(hDlg, wParam));
} else {
fProcessed = FALSE;
}
break;
}
return (fProcessed);
}
BOOL GuiImpl::CtrlBoxDlgProcOnHScroll (
HWND hWnd, // hwnd
HWND hwndCtl, // (int)(LOWORD(wParam))
UINT codeNotify,// (UINT)HIWORD(wParam))
int pos
)
{
Gui *pGui = (Gui *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (pGui) {
LOGT("********************************* Gui addr: %p pi: %p\n", pGui, pGui->pi);
return pGui->OnHScroll(GuiEventHScroll(hWnd, hwndCtl, codeNotify, pos));
}
else {
return FALSE;
}
}
Gui::Gui(): pi(0)
{
}
Gui::Gui (int id) : pi(new GuiImpl)
{
LOGT("********************************* pImpl: %p Gui addr: %p\n", pi, this);
if (pi) {
pi->hDialog = CreateDialogParam(GetMyHandle(),
MAKEINTRESOURCE(id),
HWND_DESKTOP,
GuiImpl::CtrlBoxDlgProc,
(LONG)this
);
if (pi->hDialog != NULL) {
// do not show window here !!!
// setup class instance pointer into Windows object user data
SetWindowLongPtr(pi->hDialog, GWLP_USERDATA, (LONG)this);
return;
}
}
ErrorLog(TEXT("Gui: main dialog failed !"));
}
Gui :: ~Gui()
{
LOGT("********************************* GUI destructor: Gui addr: %p\n", pi);
if (pi) {
if (pi->hDialog) DestroyWindow(pi->hDialog);
delete pi;
}
}
bool Gui :: OnInit(const GuiEvent&)
{
LOGT("%s\n", "*********************************");
return false;
}
void Gui::Show()
{
int x, y;
if (pi && pi->hDialog) {
WSize(pi->hDialog).lower_right(x, y);
LOGT("xxxxxxxxxxxxxxxxxx GUI Show: move to x= %d y= %d\n", x, y);
SetWindowPos(pi->hDialog, HWND_TOPMOST, x, y, 0, 0, SWP_NOSIZE);
ShowWindow(pi->hDialog, SW_SHOW);
}
}
void Gui::Hide()
{
if (pi && pi->hDialog) ShowWindow(pi->hDialog, SW_HIDE);
}
void Gui::EnableControls()
{
if (pi && pi->hDialog) EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(0, true));
}
void Gui::DisableControls()
{
if (pi && pi->hDialog) EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(0, false));
}
void Gui::setHwAddressGUI(const Ethernet::Device *pDev)
{
char szBuf[1024];
if (pDev) {
snprintf(szBuf, sizeof(szBuf),
"%s - %s\t\t\t%s %1.1f",
pDev->ip_address,
pDev->mac_address,
pDev->board_id,
((float)pDev->code_version) / 10.0f);
} else {
snprintf(szBuf, sizeof(szBuf), "%s", "HARDWARE NOT FOUND !!!!!");
}
if (pi && pi->hDialog) PostMessage(pi->hDialog, WM_USER + 2, reinterpret_cast<WPARAM>(xstrdup(szBuf)), static_cast<LPARAM>(0));
// free (pszBuf); FREE IS DONE IN DIALOG BOX !!!!!!!
}
void Gui::setHw (const char *pszBuf)
{
if (pszBuf && strlen(pszBuf) && pi && pi->hDialog) {
PostMessage(pi->hDialog, WM_USER + 2, reinterpret_cast<WPARAM>(xstrdup(pszBuf)), static_cast<LPARAM>(0));
}
}
void Gui::appendMessage (const char *pszBuf)
{
if (pszBuf && strlen(pszBuf) && pi && pi->hDialog) PostMessage(pi->hDialog, WM_USER + 3, reinterpret_cast<WPARAM>(xstrdup(pszBuf)), static_cast<LPARAM>(0));
}
int Gui::getRecNumber (void)
{
char buf[256];
int n = 1;
if (pi && pi->hDialog) {
SendMessage(GetDlgItem(pi->hDialog, IDC_COMBO_N_RX), WM_GETTEXT, (WPARAM)sizeof(buf), (LPARAM)buf);
if (sscanf(buf, "%d", &n) == 1) return n;
}
LOGT("Internal error !! Returning %d\n", n);
return n;
}
void Gui::setRadio (ExtioHpsdrRadio < EXTIO_BASE_TYPE > *pR)
{
if (pR && pi) {
pi->pExr = pR;
pi->pr = pi->pExr->getRadio();
}
}
ExtioHpsdrRadio < EXTIO_BASE_TYPE > * Gui::getRadio()
{
if (pi && pi->pExr) {
return pi->pExr;
} else
return 0;
}
BOOL CALLBACK GuiImpl::MyEnumWindowsProc(HWND hWnd, LPARAM lParam)
{
GuiEvent *pev = (GuiEvent *)lParam;
if (pev) {
bool fEnable = (pev->id > 0);
// for debug only
// char szWindowText[256];
// ::GetWindowText(hWnd, szWindowText, sizeof(szWindowText));
// LOGT("%10.10s: %d\n", szWindowText, fEnable);
if (pev->hWnd == 0) // if nullhandle is specified, applies to children
::EnableWindow(hWnd, fEnable);
else // if an handle is specified, applies only to that window
if (pev->hWnd == hWnd) ::EnableWindow(hWnd, fEnable);
}
return TRUE;
}
void Gui::EnableAll (const GuiEvent& ev1, const GuiEvent& ev2)
{
::EnumChildWindows(ev1.hWnd, GuiImpl::MyEnumWindowsProc, (LPARAM)&ev2);
}
/*
* H E R M E S Gui
*
*
*/
HermesGui::HermesGui(int sample_rate) : Gui(IDD_HERMES), sr(sample_rate)
{
LOGT("********************************* HermesCreateGUI: addr: %p\n", this);
if (pi && pi->hDialog) OnInit(GuiEvent(pi->hDialog, -1));
}
void HermesGui::EnableControls()
{
if (pi) {
EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(0, true));
EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(GetDlgItem(pi->hDialog, IDC_COMBO_N_RX), false));
}
Gui::Show();
}
void HermesGui::DisableControls()
{
if (pi) {
EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(0, false));
EnableAll(GuiEvent(pi->hDialog, 0), GuiEvent(GetDlgItem(pi->hDialog, IDC_COMBO_N_RX), true));
}
Gui::Show();
}
bool HermesGui::OnInit(const GuiEvent& ev)
{
//
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb760238%28v=vs.85%29.aspx
//
HWND sliderAtt = GetDlgItem(ev.hWnd, IDC_SLIDER_ATT);
SendMessage(sliderAtt, TBM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG(0, 30));
SendMessage(sliderAtt, TBM_SETPOS, (WPARAM)0, 0);
SendMessage(sliderAtt, TBM_SETTICFREQ, (WPARAM)10, 0);
SendMessage(sliderAtt, TBM_SETPAGESIZE, (WPARAM)0, (LPARAM)MAKELONG(0, 10));
// fillin the rx number combo box
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"1");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"1");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"2");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"3");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"4");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"5");
// default at first item, one receiver(s)
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_SETCURSEL, 0, 0);
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_SETCURSEL, 1, 0);
switch (sr) {
case 384000:
// order of parameters in the call:
// first last check
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_384K);
break;
case 192000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_192K);
break;
case 96000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_96K);
break;
case 48000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_48K);
break;
}
EnableAll(ev, GuiEvent(0, false));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), true));
AppendWinTitle(GuiEvent(pi->hDialog, 0), buildString);
return true;
}
bool HermesGui::ButtonClick(const GuiEvent &ev)
{
// some button/checkbox has been clicked
// the lower word of wParam holds the controls ID
if (ev.id >= IDC_RADIO_BW_384K && ev.id <= IDC_RADIO_BW_48K) {
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, ev.id);
switch (ev.id) {
case IDC_RADIO_BW_384K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwith: 384 kS/s\r\n");
LOGT("%s", "New Bandwith: 384 kS/s\r\n");
(pi->pExr)->setSampleRateHW(384000);
break;
case IDC_RADIO_BW_192K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwith: 192 kHz\r\n");
LOGT("%s", "New Bandwith: 192 kHz\r\n");
(pi->pExr)->setSampleRateHW(192000);
break;
case IDC_RADIO_BW_96K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwith: 96 kHz\r\n");
LOGT("%s", "New Bandwith: 96 kHz\r\n");
(pi->pExr)->setSampleRateHW(96000);
break;
case IDC_RADIO_BW_48K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwith: 48 KHz\r\n");
LOGT("%s", "New Bandwith: 48 KHz\r\n");
(pi->pExr)->setSampleRateHW(48000);
break;
}
}
if (ev.id >= IDC_CB_DITHER && ev.id <= IDC_CB_RANDOMIZER) {
HWND hCtrl = GetDlgItem(ev.hWnd, ev.id);
const char *pszState;
int newStatus;
if (IsDlgButtonChecked(ev.hWnd, ev.id) == BST_CHECKED) {
pszState = " activated\r\n";
newStatus = 1;
}
else {
pszState = " deactivated\r\n";
newStatus = 0;
}
switch (ev.id) {
case IDC_CB_PREAMP:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Preamp");
pi->pr->setPreamp(newStatus==1);
break;
case IDC_CB_RANDOMIZER:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Randomizer");
pi->pr->setRandomizer(newStatus==1);
break;
case IDC_CB_DITHER:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Dither");
pi->pr->setDither(newStatus==1);
break;
}
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), pszState);
}
return true;
}
bool HermesGui::OnHScroll(const GuiEventHScroll& ev)
{
if (GetDlgItem(ev.hWnd, IDC_SLIDER_ATT) == ev.hwndCtl) {
DWORD newPos = SendMessage(GetDlgItem(ev.hWnd, IDC_SLIDER_ATT), TBM_GETPOS, 0, 0);
int snap = (newPos % 10);
LOGT("NEW: %d SNAP: %d\r\n", newPos, snap);
if (snap) {
if (snap > 5) newPos += (10 - snap);
else newPos = newPos - snap;
if (newPos > 30) newPos = 30;
LOGT("MOVE: %d\r\n", newPos);
SendMessage(GetDlgItem(ev.hWnd, IDC_SLIDER_ATT), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)newPos);
}
else {
LOGT("New attenuator value: %d\r\n", newPos);
pi->pr->setAttenuator(newPos);
}
return true;
}
else
return false;
}
bool HermesGui::OnWmUser(int n, const GuiEvent& ev)
{
char * pszText = reinterpret_cast<char *>(ev.id);
if (n == 2 && pszText) {
SetWindowText (GetDlgItem(ev.hWnd, IDC_STATIC_HW), pszText);
xstrdel(pszText, __LINE__);
return true;
} else
if (n = 3 && pszText) {
AppendTextToEditCtrl (GuiEvent(ev.hWnd, IDC_MSG_PANE), pszText);
xstrdel(pszText, __LINE__);
return true;
} else
return false;
}
bool MercuryGui::OnInit(const GuiEvent& ev)
{
LOGT("Event ref: %p\n", ev);
//
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb760238%28v=vs.85%29.aspx
//
HWND sliderAtt = GetDlgItem(ev.hWnd, IDC_SLIDER_ATT);
SendMessage(sliderAtt, TBM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG(0, 30));
SendMessage(sliderAtt, TBM_SETPOS, (WPARAM)0, 0);
SendMessage(sliderAtt, TBM_SETTICFREQ, (WPARAM)10, 0);
SendMessage(sliderAtt, TBM_SETPAGESIZE, (WPARAM)0, (LPARAM)MAKELONG(0, 10));
// fillin the rx number combo box
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"1");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"1");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"2");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"3");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"4");
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_ADDSTRING, 0, (LPARAM)"5");
// default at first item, one receiver(s)
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_SETCURSEL, 0, 0);
SendMessage(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), CB_SETCURSEL, 1, 0);
switch (sr) {
case 384000:
// first last check
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_384K);
break;
case 192000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_192K);
break;
case 96000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_96K);
break;
case 48000:
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, IDC_RADIO_BW_48K);
break;
}
CheckRadioButton(ev.hWnd, IDC_ALEX_FILTER_AUTO, IDC_ALEX_FILTER_AUTO, IDC_ALEX_FILTER_AUTO);
// default to Antenna 1
CheckRadioButton(ev.hWnd, IDC_ANT_1, IDC_ANT_3, IDC_ANT_1 );
// disable all controls
EnableAll(ev, GuiEvent(0, false));
// enable receivers selection
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_COMBO_N_RX), true));
// enable bandwidth selection
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_384K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_192K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_96K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_48K), true));
AppendWinTitle(GuiEvent(pi->hDialog, 0), buildString);
return true;
}
bool MercuryGui::ButtonClick(const GuiEvent &ev)
{
// some button/checkbox has been clicked
// GuiEvent ev object contains the handle of dialog and the id of control that has been clicked
if (ev.id >= IDC_RADIO_BW_384K && ev.id <= IDC_RADIO_BW_48K) {
CheckRadioButton(ev.hWnd, IDC_RADIO_BW_384K, IDC_RADIO_BW_48K, ev.id);
switch (ev.id) {
case IDC_RADIO_BW_384K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwidth: 384 kS/s\r\n");
LOGT("%s\n", "New Bandwith: 384 kHz");
(pi->pExr)->setSampleRateHW(384000);
break;
case IDC_RADIO_BW_192K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwidth: 192 kHz\r\n");
LOGT("%s\n", "New Bandwith: 192 kHz");
(pi->pExr)->setSampleRateHW(192000);
break;
case IDC_RADIO_BW_96K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwidth: 96 kHz\r\n");
LOGT("%s\n", "New Bandwith: 96 kHz");
(pi->pExr)->setSampleRateHW(96000);
break;
case IDC_RADIO_BW_48K:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "New Bandwidth: 48 KHz\r\n");
LOGT("%s\n", "New Bandwith: 48 KHz");
(pi->pExr)->setSampleRateHW(48000);
break;
}
}
if (ev.id >= IDC_RB_ALEX_LP_3020 && ev.id <= IDC_RB_ALEX_LP_1715) {
CheckRadioButton(ev.hWnd, IDC_RB_ALEX_LP_3020, IDC_RB_ALEX_LP_1715, ev.id);
switch (ev.id) {
case IDC_RB_ALEX_LP_3020:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 30/20 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_3020m);
break;
case IDC_RB_ALEX_LP_6040:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 60/40 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_6040m);
break;
case IDC_RB_ALEX_LP_80:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 80 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_80m);
break;
case IDC_RB_ALEX_LP_160:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 160 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_160m);
break;
case IDC_RB_ALEX_LP_6:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 6 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_6m);
break;
case IDC_RB_ALEX_LP_1210:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 12/10 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_1210m);
break;
case IDC_RB_ALEX_LP_1715:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "LOW PASS: 17/15 m\r\n");
(pi->pr)->setLP(AlexFilter::LowPass::_1715m);
break;
}
}
if (ev.id >= IDC_ALEX_HP_BYPASS && ev.id <= IDC_ALEX_HP_6M_LNP) {
CheckRadioButton(ev.hWnd, IDC_ALEX_HP_BYPASS, IDC_ALEX_HP_6M_LNP, ev.id);
switch (ev.id) {
case IDC_ALEX_HP_BYPASS:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: bypass\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_bypass);
break;
case IDC_ALEX_HP_13MHZ:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 13 MHz\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_13M);
break;
case IDC_ALEX_HP_20MHZ:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 20 MHz\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_20M);
break;
case IDC_ALEX_HP_9_5MHZ:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 9.5 MHz\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_9_5M);
break;
case IDC_ALEX_HP_6_5MHZ:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 6.5 MHz\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_6_5M);
break;
case IDC_ALEX_HP_1_5MHZ:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 1.5 MHz\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_1_5M);
break;
case IDC_ALEX_HP_6M_LNP:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "HIGH PASS: 6 MHz + LNP\r\n");
(pi->pr)->setHP(AlexFilter::HighPass::_6M);
break;
}
}
if (ev.id == IDC_ALEX_FILTER_AUTO) {
const char *pszState;
HWND hCtrl = GetDlgItem(ev.hWnd, ev.id);
if (IsDlgButtonChecked(ev.hWnd, ev.id) == BST_CHECKED) {
pszState = "ALEX AUTO\n";
(pi->pr)->setManual(false);
}
else {
pszState = "ALEX MANUAL\r\n";
(pi->pr)->setManual(true);
}
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), pszState);
LOGT("%p %s", (pi->pr), pszState);
}
if (ev.id >= IDC_CB_DITHER && ev.id <= IDC_CB_RANDOMIZER) {
HWND hCtrl = GetDlgItem(ev.hWnd, ev.id);
const char *pszState;
int newStatus;
if (IsDlgButtonChecked(ev.hWnd, ev.id) == BST_CHECKED) {
pszState = " activated\r\n";
newStatus = 1;
}
else {
pszState = " deactivated\r\n";
newStatus = 0;
}
switch (ev.id) {
case IDC_CB_PREAMP:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Preamp");
pi->pr->setPreamp(newStatus == 1);
break;
case IDC_CB_RANDOMIZER:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Randomizer");
pi->pr->setRandomizer(newStatus == 1);
break;
case IDC_CB_DITHER:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Dither");
pi->pr->setDither(newStatus == 1);
break;
}
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), pszState);
}
if (ev.id >= IDC_ANT_1 && ev.id <= IDC_ANT_3) {
CheckRadioButton(ev.hWnd, IDC_ANT_1, IDC_ANT_3, ev.id);
switch (ev.id) {
case IDC_ANT_1:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Tx Antenna: 1\r\n");
(pi->pr)->setTxAnt(0);
break;
case IDC_ANT_2:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Tx Antenna: 2\r\n");
(pi->pr)->setTxAnt(1);
break;
case IDC_ANT_3:
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_MSG_PANE), "Tx Antenna: 3\r\n");
(pi->pr)->setTxAnt(2);
break;
}
}
return true;
}
void MercuryGui::EnableControls()
{
GuiEvent ev(pi->hDialog, 0);
EnableAll(ev, GuiEvent(0, true));
EnableAll(ev, GuiEvent(GetDlgItem(pi->hDialog, IDC_COMBO_N_RX), false));
Gui::Show();
}
void MercuryGui::DisableControls()
{
GuiEvent ev(pi->hDialog, 0);
EnableAll(ev, GuiEvent(0, false));
EnableAll(ev, GuiEvent(GetDlgItem(pi->hDialog, IDC_COMBO_N_RX), true));
// enable bandwidth selection
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_384K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_192K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_96K), true));
EnableAll(ev, GuiEvent(GetDlgItem(ev.hWnd, IDC_RADIO_BW_48K), true));
Gui::Show();
}
MercuryGui::MercuryGui(int sample_rate) : Gui(IDD_MERCURY), sr(sample_rate)
{
LOGT("********************************* MercuryCreateGUI: pImpl: %p Gui addr: %p\n", pi, this);
if (pi && pi->hDialog) OnInit(GuiEvent(pi->hDialog, -1));
}
bool MercuryGui::OnWmUser(int n, const GuiEvent& ev)
{
char * pszText = reinterpret_cast<char *>(ev.id);
if (n == 2 && pszText) {
LOGT("2: %s\n", pszText);
SetWindowText (GetDlgItem(ev.hWnd, IDC_STATIC_HW), (LPCTSTR)pszText);
xstrdel(pszText, __LINE__);
return true;
} else
if (n = 3 && pszText) {
LOGT("3: %s\n", pszText);
AppendTextToEditCtrl (GuiEvent(ev.hWnd, IDC_MSG_PANE), pszText);
xstrdel(pszText, __LINE__);
return true;
} else
return false;
}
bool MercuryGui::OnHScroll(const GuiEventHScroll& ev)
{
if (GetDlgItem(ev.hWnd, IDC_SLIDER_ATT) == ev.hwndCtl) {
DWORD newPos = SendMessage(GetDlgItem(ev.hWnd, IDC_SLIDER_ATT), TBM_GETPOS, 0, 0);
int snap = (newPos % 10);
LOGT("NEW: %d SNAP: %d\r\n", newPos, snap);
if (snap) {
if (snap > 5) newPos += (10 - snap);
else newPos = newPos - snap;
if (newPos > 30) newPos = 30;
LOGT("MOVE: %d\r\n", newPos);
SendMessage(GetDlgItem(ev.hWnd, IDC_SLIDER_ATT), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)newPos);
}
else {
LOGT("New attenuator value: %d\r\n", newPos);
pi->pr->setAttenuator(newPos);
}
return true;
} else
return false;
}
/**
*
* Splash Screen dialog
*
*/
bool HpsdrSplash::ListBoxDoubleClick(const GuiEvent &ev)
{
if (ev.id == IDC_LBOX_RADIO_FOUND) {
// recover the item of list box that has been clicked
sel = ListBox_GetCurSel(ev.hWnd);
LOGT("xxxxxxxxxxxxxxxxxx GUI Splash: item #%d selected\n", sel);
if (!(*(ppGui_))) {
LOGT("Gui Splash: BOARD ID creating gui: [%s]\n", pDev->board_id);
if (!pi) {
GuiError("Bad environment, unable to start receiver !").show();
return false;
}
if (!(pi->pExr)) {
// Create Radio
pi->pExr = CreateExtioHpsdrRadio<EXTIO_BASE_TYPE>(pDev->board_id, *(ppCr_));
if (! (pi->pExr)) {
GuiError("Hardware unsupported, unable to start receiver !").show();
return 0;
} else {
// Create Gui
*(ppGui_) = pi->pExr->CreateGui(EXTIO_DEFAULT_SAMPLE_RATE);
if (*(ppGui_)) {
(*(ppGui_))->setRadio(pi->pExr); // assign ExtioRadio to Gui
Hide(); // hide ourselves (Splash)
(*(ppGui_))->Show(); // show Radio Gui
} else
return false;
}
}
}
}
return true;
}
bool HpsdrSplash::OnWmUser(int n, const GuiEvent& ev)
{
char * pszText = reinterpret_cast<char *>(ev.id);
if (n == 2 && pszText) {
SetWindowText(GetDlgItem(ev.hWnd, IDC_SPLSH_MSG), (LPCTSTR)(char *)pszText);
BringWindowToTop(ev.hWnd);
xstrdel(pszText, __LINE__);
} else
if (n == 3 && pszText) {
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_SPLSH_MSG_PANE), pszText);
AppendTextToEditCtrl(GuiEvent(ev.hWnd, IDC_SPLSH_MSG_PANE), "\r\n");
BringWindowToTop(ev.hWnd);
xstrdel(pszText, __LINE__);
} else
if (n == 4 && pszText) {
SendMessage(GetDlgItem(ev.hWnd, IDC_LBOX_RADIO_FOUND), LB_INSERTSTRING, -1 /* Index */, (LPARAM)pszText);
BringWindowToTop(ev.hWnd);
xstrdel(pszText, __LINE__);
}
return true;
}
HpsdrSplash::HpsdrSplash(Gui **p, CommandReceiver **ppCr):
Gui(IDD_SPLASH_DIALOG), sel(-1), ppGui_(p), ppCr_(ppCr), pDev(0)
{
OnInit(GuiEvent(pi->hDialog, -1));
}
bool HpsdrSplash::OnInit(const GuiEvent& ev)
{
AppendWinTitle(GuiEvent(pi->hDialog, 0), buildString);
return true;
}
void HpsdrSplash::AppendMessage(const char *pszBuf)
{
PostMessage(pi->hDialog, WM_USER + 3, reinterpret_cast<WPARAM>(xstrdup(pszBuf)), static_cast<LPARAM>(0));
}
template <typename... ARGS>
void HpsdrSplash::SetStatus(const char *format, ARGS... args)
{
char szBuf[1024];
snprintf(szBuf, sizeof(szBuf), format, args...);
PostMessage(pi->hDialog, WM_USER + 2, reinterpret_cast<WPARAM>(xstrdup(szBuf)), static_cast<LPARAM>(0));
}
int HpsdrSplash::ScanStarted()
{
SetStatus("%s", "Searching for hardware...");
return 0;
}
int HpsdrSplash::ScanStopped(int nh)
{
if (nh == 0) SetStatus("%s", "Search done. No device found");
else SetStatus("Search done. %d device(s) found", nh);
return 0;
}
int HpsdrSplash::InterfaceFound(Ethernet::NetInterface *pni)
{
AppendMessage(pni->name);
return 0;
}
int HpsdrSplash::DeviceFound(Ethernet::Device *pd)
{
// append a clear text (progress) message
AppendMessage(pd->board_id);
// append to the list box
char szBuf[1024];
snprintf(szBuf, sizeof(szBuf), "%s - %s", pd->board_id, pd->ip_address);
PostMessage(pi->hDialog, WM_USER + 4, reinterpret_cast<WPARAM>(xstrdup(szBuf)), static_cast<LPARAM>(0) );
pDev = pd;
return 0;
}
void HpsdrSplash::Show()
{
int x, y;