forked from pavels/spektrum
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspektrum.pde
1994 lines (1693 loc) · 63.8 KB
/
spektrum.pde
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
import org.bridj. * ;
import org.bridj.ann. * ;
import org.bridj.cpp. * ;
import org.bridj.cpp.com. * ;
import org.bridj.cpp.com.shell. * ;
import org.bridj.cpp.mfc. * ;
import org.bridj.cpp.std. * ;
import org.bridj.demangling. * ;
import org.bridj.dyncall. * ;
import org.bridj.func. * ;
import org.bridj.jawt. * ;
import org.bridj.util. * ;
import org.bridj.relocated.org.objectweb.asm. * ;
import org.bridj.relocated.org.objectweb.asm.signature. * ;
import controlP5. * ;
import rtlspektrum.Rtlspektrum;
import java.io.FileWriter;
import java.util. * ;
import processing.serial. * ;
import java.io. * ;
String glb_WindowTitle = "Spektrum ";
String glb_ProgramVersion = "v0.20b - SV8ARJ";
String glb_renderedMode = "";
SpektrumInterface spektrumReader; // TODO ... I will regret this, why not just use ifs on every call ? It's only 30 or so...
ControlP5 cp5;
DataPoint[] scaledBuffer;
boolean startingupBypassSaveConfiguration = true;
int reloadConfigurationAfterStartUp = 0; // This will be set at the end of the startup
int CONFIG_RELOAD_DELAY = 30; // 0 is disabled
interface CURSORS {
int
CUR_NONE = 0,
CUR_X_LEFT = 1,
CUR_X_RIGHT = 2,
CUR_Y_TOP = 3,
CUR_Y_BOTTOM = 4;
}
int movingCursor = CURSORS.CUR_NONE;
String tmpMessage;
String tmpMessage1;
int genericFrameCounter = 0; // Used for various tests. Gets incremented with every frame TAG_ARJ
// HackRF stuff TAG_ARJ
//
String glb_currentPath;
String glb_sweepCommandLine;
String glb_cmdFrequencyRange;
String glb_cmdBinSize = " -W 25000";
String glb_cmdLnaGain; // [-l gain_db] # RX LNA (IF) gain, 0-40dB, 8dB steps
String glb_cmdVgaGain = " -g 10"; // [-g gain_db] # RX VGA (baseband) gain, 0-62dB, 2dB steps
String glb_cmdPreAmp = " -a 0"; // [-a amp_enable] # RX RF amplifier 1=Enable, 0=Disable
final int NONE = 0;
// TABS
//
int tabActiveID = 1;
String tabActiveName = "default";
final int TAB_HEIGHT = 25;
final int TAB_HEIGHT_ACTIVE = 30;
final int TAB_GENERAL = 1;
final int TAB_MEASURE = 2;
final int TAB_SETTINGS = 3;
final int TAB_SARK100 = 4;
String tabLabels[] = {
"global",
"SETUP",
"MEASURE",
"SETTINGS",
"NOT YET",
"WHO ARE YOU"
};
final int ITEM_GAIN = 1;
final int ITEM_FREQUENCY = 2;
final int ITEM_ZOOM = 3;
final int ITEM_RF_GAIN = 4;
// interface IF_TYPES {
// int
final int IF_TYPE_NONE = 0;
final int IF_TYPE_ABOVE = 1;
final int IF_TYPE_BELOW = 2;
final int TOOLTIP_TIME = 300; // 5 seconds at 60 fps
// }
// Configuration
//
final int nrOfConfigurations = 10; // First element is used for the Autosave functionality.
final int PRESET_SAVE = 1;
final int PRESET_LOAD = 2;
int configurationOperation = 0;
int CONFIG_SAVE_DELAY = 80; // 0 is disabled
configurationClass[] configSet = new configurationClass[10];
int configurationActive = 0;
String configurationName;
DropdownList configurationDropdown;
int configurationSaveDelay = 0;
int glb_fps = 60;
String glb_renderer = "P2D";
// Maybe not needed -- TBD
//
public class configurationClass {
public int startFreq;
public int stopFreq;
public int binStep;
public int scaleMin;
public int scaleMax;
public int rfGain;
public int fullRangeMin;
public int fullRangeMax;
public int ifOffset;
public int ifType;
public int activeConfig;
public String configName;
public configurationClass(int i) {
configName = "Config" + i;
}
}
int timeToSet = 0; // GRGNICK add
int itemToSet = 0; // GRGNICK add -- 1 is Gain, 2 is Frequency
int infoText1X = 0;
int infoText1Y = 0;
int infoColor = #00FF3F;
int infoLineX = 0;
int infoLineY = 0;
int infoRectangle[] = {
0,
0,
0,
0
};
String infoText = "";
int lastWidth = 0;
int lastHeight = 0;
long glb_zoomBackFreqMin = 0;
long glb_zoomBackFreqMax = 0;
int zoomBackScalMin = 0;
int zoomBackScalMax = 0;
long glb_fullRangeMin = 24000000;
long glb_fullRangeMax = 1800000000;
int glb_fullScaleMin = -110;
int glb_fullScaleMax = 40;
int glb_correctFrequencyTimer = 0; // Correct frequency after setFrequency if needed (if SDR produced different results)
long glb_startFreq = 88000000;
long glb_stopFreq = 108000000;
long glb_startFreqCorrected = 88000000; // HackRF is not always producing requested range. Fix the UI.
long glb_stopFreqCorrected = 108000000;
int glb_binStepCorrected = 1000; // Used for correction
int glb_binStep = 1000;
int binStepProtection = 200;
long vertCursorFreq = 88000000;
int tmpFreq = 0;
int rfGain = 0;
int ifOffset = 0;
int ifType = 0;
int cropPercent = 0; // RTL data chunks percentage to keep. Values 0 to 70 percent
int scaleMin = -110;
int scaleMax = 40;
int uiNextLineIndex = 0;
int[][] uiLines = new int[10][10];
final int GRAPH_DRAG_NONE = 0;
final int GRAPH_DRAG_STARTED = 1;
final int GRAPH_DRAG_ENDED = 0;
int mouseDragGraph = GRAPH_DRAG_NONE;
int dragGraphStartX;
int dragGraphStartY;
int cursorVerticalLeftX = -1;
int cursorVerticalRightX = -1;
int cursorHorizontalTopY = -1;
int cursorHorizontalBottomY = -1;
int cursorVerticalLeftX_Color = #3399ff; // Cyan
int cursorHorizontalBottomY_Color = #3399ff;
int cursorVerticalRightX_Color = #ff80d5; // Magenta
int cursorHorizontalTopY_Color = #ff80d5;
int cursorDeltaColor = #00E010;
int glb_tooltipCounter = 0;
int glb_lastCursor = 0;
ListBox deviceDropdown;
DropdownList gainDropdown;
DropdownList serialDropdown;
Textarea infoTextbox;
String[] glb_devices;
int[] gains;
int relMode = 0;
double minFrequency;
double minValue;
double minScaledValue;
double maxFrequency;
double maxValue;
double maxScaledValue;
boolean minmaxDisplay = false;
boolean sweepDisplay = false;
int showInfoScreen = 0;
class DataPoint {
public int x;
public double yMin = 0;
public double yMax = 0;
public double yAvg = 0;
}
class infoScreen {
public int topY = 0;
public int leftX = 0;
public int width = 0;
public int height = 0;
public String text = "";
color colorBack;
}
infoScreen infoHelp;
//========= added by Dave N
Table table;
String glb_configFileName = "config.csv"; // config file used to save and load program setting like frequency etc.
boolean setupDone = false;
boolean frozen = true;
boolean vertCursor = false;
float minMaxTextX = 10;
float minMaxTextY = 660;
int deltaLabelsX;
int deltaLabelsY;
int deltaLabelsXWaiting;
int deltaLabelsYWaiting;
boolean overGraph = false;
boolean mouseDragLock = false;
int startDraggingThr = 5;
int lastMouseX;
color buttonColor = color(70, 70, 70);
color buttonColorText = color(255, 255, 230);
color setButtonColor = color(127, 0, 0);
color clickMeButtonColor = color(20, 200, 20);
color willSaveButtonColor = color(200, 20, 20);
boolean drawSampleToggle = false;
boolean vertCursorToggle = true;
boolean drawFill = false;
// Reference
//
boolean refShow = false; // If the reference graph is shown on screen
boolean refStoreFlag = false; // Used to flag a save in draw()
DataPoint[] refArray; // Storage of reference graph
boolean refArrayHasData = false;
int refYoffset = 0;
// Average
//
DataPoint[] avgArray; // Storage of reference graph
boolean avgShow = false;
boolean avgArrayHasData = false;
int avgDepth = 10;
int avgNewSampleWeight = 1;
boolean avgSamples = false;
// Persistent
//
DataPoint[] perArray; // Storage of Minimum and Maximum persiastant data graph
boolean perShowMax = false;
boolean perShowMin = false;
boolean perShowMed = false;
boolean perArrayHasData = false;
int lastScanPosition = 0;
int scanPosition = 0;
int completeCycles = 0; // How many times the scanner has finished the defined range
color tabColorBachground = color(0, 70, 80);
//=========================
void MsgBox(String Msg, String Title) {
// Messages
javax.swing.JOptionPane.showMessageDialog(null, Msg, Title, javax.swing.JOptionPane.ERROR_MESSAGE);
}
// Generic event handler for controls
//
void controlEvent(ControlEvent theEvent) {
// println("controlEvent: EVENT DETECTED");
if (theEvent.isTab()) {
// println("got an event from tab : "+theEvent.getTab().getName()+" with id "+theEvent.getTab().getId());
cp5.getTab(tabActiveName).setHeight(TAB_HEIGHT);
tabActiveID = theEvent.getTab().getId();
theEvent.getTab().setHeight(TAB_HEIGHT_ACTIVE);
tabActiveName = theEvent.getTab().getName();
}
if (theEvent.isController()) {
println(theEvent.getController().getName());
if (theEvent.getController().getName() == "rfGain") {
println("RF GAIN CLICKED");
}
}
}
public void cropPrcntTxt(String tmpText) {
cropPercent = parseInt(tmpText);
cropPercent = max(min(70, cropPercent), 0);
cp5.get(Textfield.class, "cropPrcntTxt").setText(strArj(cropPercent));
setRangeButton();
}
// Change the active configuration from the drop down list
//
public void configurationList(int confValue) {
if (configurationOperation == PRESET_SAVE) {
configurationName = cp5.get(Textfield.class, "presetName").getText();
table.setString(confValue, "configName", configurationName);
saveConfigToIndx(confValue);
configurationDropdown.clear();
for (int i = 0; i < nrOfConfigurations; i++) {
configurationDropdown.addItem(table.getString(i, "configName"), i);
}
configurationActive = confValue;
} else { // Load
configurationActive = confValue;
println("configurationList: Setting active configuration to " + confValue);
presetRestore();
}
configurationOperation = NONE;
cp5.get(Textfield.class, "presetName").setText(configurationName);
configurationDropdown.hide();
cp5.get(Button.class, "savePreset").setColorBackground(buttonColor);
}
public void selectPreset() {
if (configurationDropdown.isVisible()) {
configurationDropdown.hide();
configurationOperation = NONE;
cp5.get(Button.class, "savePreset").setColorBackground(buttonColor);
} else {
configurationDropdown.show();
}
configurationDropdown.bringToFront();
configurationDropdown.open();
}
public void savePreset() {
if (configurationOperation != NONE) { // If already opened for saving, cancel it.
configurationOperation = NONE;
configurationDropdown.hide();
configurationDropdown.close();
cp5.get(Button.class, "savePreset").setColorBackground(buttonColor);
} else {
configurationOperation = PRESET_SAVE;
configurationDropdown.show();
configurationDropdown.open();
cp5.get(Button.class, "savePreset").setColorBackground(willSaveButtonColor);
}
}
public void presetRestore() {
loadConfig();
loadConfigPostCreation();
}
public void openSerial() {
println(cp5.getController("serialPort").getValue());
println(cp5.get(DropdownList.class, "serialPort").getValue());
}
public void rfGain(int gainValue) {
// println( gainValue);
spektrumReader.setGain(gainValue);
}
public void rfGain00(int gainValue) {
rfGain(gains[0]);
cp5.get(Knob.class, "rfGain").setValue(gains[0]);
}
public void rfGain01(int gainValue) {
//println( (int) (( gains[0] + ( gains[gains.length-1] - gains[0]) / 3 ) ) );
int tpmInt = (int)((gains[0] + (gains[gains.length - 1] - gains[0]) * 1 / 3));
rfGain(tpmInt);
cp5.get(Knob.class, "rfGain").setValue(tpmInt);
}
public void rfGain02(int gainValue) {
int tpmInt = (int)((gains[0] + (gains[gains.length - 1] - gains[0]) / 2));
rfGain(tpmInt);
cp5.get(Knob.class, "rfGain").setValue(tpmInt);
}
public void rfGain03(int gainValue) {
int tpmInt = (int)((gains[0] + (gains[gains.length - 1] - gains[0]) * 2.5 / 3));
rfGain(tpmInt);
cp5.get(Knob.class, "rfGain").setValue(tpmInt);
}
public void rfGain04(int gainValue) {
rfGain(gains[gains.length - 1]);
cp5.get(Knob.class, "rfGain").setValue(gains[gains.length - 1]);
}
// bin sizes
//
public void binSize00(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("2500");
setRangeFromTextFields();
}
public void binSize01(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("5000");
setRangeFromTextFields();
}
public void binSize02(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("10000");
setRangeFromTextFields();
}
public void binSize03(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("50000");
setRangeFromTextFields();
}
public void binSize04(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("100000");
setRangeFromTextFields();
}
public void binSize05(int gainValue) {
cp5.get(Textfield.class, "binStepText").setText("250000");
setRangeFromTextFields();
}
// IF settings UI
//
public void ifPlusToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
cp5.get(Toggle.class, "ifMinusToggle").setValue(0);
ifType = IF_TYPE_ABOVE;
ifOffset = parseInt(cp5.get(Textfield.class, "ifOffset").getText());
} else {
ifType = IF_TYPE_NONE;
}
configurationSaveDelay = CONFIG_SAVE_DELAY;
}
}
public void ifMinusToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
cp5.get(Toggle.class, "ifPlusToggle").setValue(0);
ifType = IF_TYPE_BELOW;
ifOffset = parseInt(cp5.get(Textfield.class, "ifOffset").getText());
} else {
ifType = IF_TYPE_NONE;
}
}
configurationSaveDelay = CONFIG_SAVE_DELAY;
}
// Min/Max UI
//
public void offsetToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
spektrumReader.setOffsetTunning(true);
} else {
spektrumReader.setOffsetTunning(false);
}
}
}
public void minmaxToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
minmaxDisplay = true;
} else {
minmaxDisplay = false;
}
}
}
public void sweepToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
sweepDisplay = true;
} else {
sweepDisplay = false;
}
}
}
public void perShowMaxToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
perShowMax = true;
} else {
perShowMax = false;
}
}
}
public void perShowMinToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
perShowMin = true;
} else {
perShowMin = false;
}
}
}
public void perShowMedToggle(int theValue) {
if (setupDone) {
if (theValue > 0) {
perShowMed = true;
} else {
perShowMed = false;
}
}
}
public double ifCorrectedFreq(long inFreq) {
double tmpFreq = inFreq;
if (ifType == IF_TYPE_ABOVE) tmpFreq -= ifOffset;
else if (ifType == IF_TYPE_BELOW) tmpFreq = ifOffset - tmpFreq;
return tmpFreq;
}
public void setRangeButton() {
setRangeFromTextFields();
}
public void setRangeFromTextFields() {
// Button color indicating change
cp5.get(Button.class, "setRangeButton").setColorBackground(buttonColor);
cursorVerticalLeftX = -1;
cursorVerticalRightX = -1;
try {
glb_startFreq = Long.parseLong(cp5.get(Textfield.class, "startFreqText").getText());
glb_stopFreq = Long.parseLong(cp5.get(Textfield.class, "stopFreqText").getText());
glb_binStep = parseInt(cp5.get(Textfield.class, "binStepText").getText());
cropPercent = parseInt(cp5.get(Textfield.class, "cropPrcntTxt").getText());
}
catch(Exception e) {
println("setRange exception.");
}
if (glb_startFreq == 0 || glb_stopFreq <= glb_startFreq || glb_binStep < 1) return;
configurationSaveDelay = CONFIG_SAVE_DELAY;
double tmpCrop = (double)(max(min(70, cropPercent), 0) / 100.0);
relMode = 0;
spektrumReader.clearFrequencyRange();
spektrumReader.setFrequencyRange(glb_startFreq, glb_stopFreq, glb_binStep, tmpCrop);
spektrumReader.startAutoScan();
println("setRange: CROP set to " + tmpCrop);
glb_correctFrequencyTimer = 200;
}
public void setScale() {
// Button color indicating change
cp5.get(Button.class, "setScale").setColorBackground(buttonColor);
cursorHorizontalTopY = -1;
cursorHorizontalBottomY = -1;
try {
scaleMin = parseInt(cp5.get(Textfield.class, "scaleMinText").getText());
scaleMax = parseInt(cp5.get(Textfield.class, "scaleMaxText").getText());
}
catch(Exception e) {
return;
}
configurationSaveDelay = CONFIG_SAVE_DELAY;
}
public void resetScale() {
scaleMin = glb_fullScaleMin;
scaleMax = glb_fullScaleMax;
cp5.get(Textfield.class, "scaleMinText").setText(strArj(scaleMin));
cp5.get(Textfield.class, "scaleMaxText").setText(strArj(scaleMax));
}
public void autoScale() {
if (setupDone) {
if (minmaxDisplay) {
scaleMin = (int)(minValue - abs((float) minValue * 0.1));
scaleMax = (int)(maxValue + abs((float) maxValue * 0.1));
} else {
scaleMin = (int)(minScaledValue - abs((float) minScaledValue * 0.1));
scaleMax = (int)(maxScaledValue + abs((float) maxScaledValue * 0.1));
}
cp5.get(Textfield.class, "scaleMinText").setText(strArj(scaleMin));
cp5.get(Textfield.class, "scaleMaxText").setText(strArj(scaleMax));
}
}
void refSave() {
println("Flaging for graph storage");
refStoreFlag = true;
}
void perReset() {
perArrayHasData = false;
}
// On set scale (V or H) fix the cursors involved so the primaries are always on the lower side (swap them is needed).
void swapCursors() {
int tmpInt;
if (cursorVerticalLeftX > cursorVerticalRightX) {
tmpInt = cursorVerticalLeftX;
cursorVerticalLeftX = cursorVerticalRightX;
cursorVerticalRightX = tmpInt;
}
if (cursorHorizontalTopY > cursorHorizontalBottomY) {
tmpInt = cursorHorizontalTopY;
cursorHorizontalTopY = cursorHorizontalBottomY;
cursorHorizontalBottomY = tmpInt;
}
}
void zoomBack() {
swapCursors(); //Fix order
cp5.get(Textfield.class, "startFreqText").setText(strArj(glb_zoomBackFreqMin));
cp5.get(Textfield.class, "stopFreqText").setText(strArj(glb_zoomBackFreqMax));
cp5.get(Textfield.class, "scaleMinText").setText(strArj(zoomBackScalMin));
cp5.get(Textfield.class, "scaleMaxText").setText(strArj(zoomBackScalMax));
glb_zoomBackFreqMin = glb_startFreq;
glb_zoomBackFreqMax = glb_stopFreq;
zoomBackScalMin = scaleMin;
zoomBackScalMax = scaleMax;
setScale();
setRangeFromTextFields();
}
void zoomIn() {
swapCursors(); //Fix order
glb_zoomBackFreqMin = glb_startFreq;
glb_zoomBackFreqMax = glb_stopFreq;
zoomBackScalMin = scaleMin;
zoomBackScalMax = scaleMax;
cp5.get(Textfield.class, "startFreqText").setText(strArj(glb_startFreq + hzPerPixel() * (cursorVerticalLeftX - graphX())));
cp5.get(Textfield.class, "stopFreqText").setText(strArj(glb_startFreq + hzPerPixel() * (cursorVerticalRightX - graphX())));
cp5.get(Textfield.class, "scaleMinText").setText(strArj(scaleMax - (((cursorHorizontalBottomY - graphY()) * gainPerPixel()) / 1000)));
cp5.get(Textfield.class, "scaleMaxText").setText(strArj(scaleMax - (((cursorHorizontalTopY - graphY()) * gainPerPixel()) / 1000)));
setScale();
setRangeFromTextFields();
}
public void toggleRelMode(int theValue) {
if (setupDone) {
relMode++;
if (relMode > 2) {
relMode = 0;
}
}
}
public void deviceDropdown(int theValue) {
deviceDropdown.hide();
infoTextbox.hide();
String selectedText = deviceDropdown.getItem(theValue).get("name").toString();
// TODO_REMOVE MsgBox("Device selected : " + theValue + " " + selectedText, "Spektrum");
if (selectedText.startsWith("Hack RF")) {
spektrumReader = new HackRFspektrum(theValue);
// MsgBox("HackRF device selected.", "Spektrum");
}
else {
spektrumReader = new RtlspektrumWrapper(theValue);
// MsgBox("RTL-SDR device selected.", "Spektrum");
}
int status = spektrumReader.openDevice();
// Initialiaze configuration class array
//
for (int i = 0; i < nrOfConfigurations; i++) {
configSet[i] = new configurationClass(i + 1);
}
//============ Function calls added by Dave N
makeConfig(); // create config file if it is not found.
loadConfig();
//============================
if (status < 0) {
MsgBox("Error: Can't open SDR device.", "Spektrum");
exit();
return;
}
// Device dependent parameters
//
gains = spektrumReader.getGains();
glb_fullRangeMin = spektrumReader.getFrequencyRangeSupported()[0];
glb_fullRangeMax = spektrumReader.getFrequencyRangeSupported()[1];
setupControls();
relMode = 0;
setupDone = true;
genericFrameCounter = 0;
}
public void gainDropdown(int theValue) {
spektrumReader.setGain(gains[theValue]);
}
// ======================================================================================
//
void settings() {
lastWidth = 1200;
lastHeight = 750;
File file = new File("P3D");
if (file.exists()) {
size(lastWidth, lastHeight, P3D); // P2D, P3D Size should be the first statement TODO add method to settings file
glb_renderedMode = "P3D"; // used for the title bar
}
else size(lastWidth, lastHeight); // P2D, P3D Size should be the first statement TODO add method to settings file
}
void setup() {
windowTitle(glb_WindowTitle + glb_ProgramVersion + (glb_renderedMode == "" ? "": " - P3D "));
surface.setResizable(true);
frameRate(60); // TODO Add it to settings file
// Get the current working directory
//
glb_currentPath = System.getProperty("user.dir") + "\\hackrf";
println("Current working directory: " + glb_currentPath);
// Get RTL devices
//
glb_devices = Rtlspektrum.getDevices();
for (String dev: glb_devices) {
println(dev);
}
// Get HackRF devices
//
HackRFspektrum hackRF = new HackRFspektrum(0); // Create an instance of HackRFspektrum
String[] devicesHackRF = hackRF.getDevices(); // Call the non-static method on the instance
for (String dev: devicesHackRF) {
println(dev);
glb_devices = addElement(glb_devices, "Hack RF (" + dev + ")");
}
cp5 = new ControlP5(this);
setupStartControls();
for (int i = 0; i < glb_devices.length; i++) {
deviceDropdown.addItem(glb_devices[i], i);
}
// Check files
//
boolean allFound = true;
allFound = allFound && checkHackRFfile("hackrf_sweep.exe");
allFound = allFound && checkHackRFfile("hackrf_info.exe");
allFound = allFound && checkHackRFfile("hackrf.dll");
allFound = allFound && checkHackRFfile("libfftw3f-3.dll");
allFound = allFound && checkHackRFfile("pthreadVC2.dll");
if (allFound) addStartupMessage("HackRF Files OK");
println("Reached end of setup.");
reloadConfigurationAfterStartUp = CONFIG_RELOAD_DELAY; //Reload configuration after this time
}
void stop() {
spektrumReader.stopAutoScan();
}
void windowResized() {
println("windowResized: RESIZE DETECTED ");
genericFrameCounter = 0;
// surface.setSize(width, height);
}
void draw() {
genericFrameCounter++;
background(color(#222324));
if (!setupDone) {
return;
}
if (width != lastWidth || height != lastHeight) {
refShow = false;
avgShow = false;
println("RESIZE DETECTED :" + genericFrameCounter);
lastWidth = width;
lastHeight = height;
cp5.get(Toggle.class, "refShow").setValue(0);
cp5.get(Toggle.class, "avgShow").setValue(0);
return;
}
if (relMode == 1) {
cp5.get(Button.class, "toggleRelMode").getCaptionLabel().setText("Set relative");
spektrumReader.setRelativeMode(Rtlspektrum.RelativeModeType.RECORD);
} else if (relMode == 2) {
cp5.get(Button.class, "toggleRelMode").getCaptionLabel().setText("Cancel relative");
spektrumReader.setRelativeMode(Rtlspektrum.RelativeModeType.RELATIVE);
} else {
cp5.get(Button.class, "toggleRelMode").getCaptionLabel().setText("Relative mode");
spektrumReader.setRelativeMode(Rtlspektrum.RelativeModeType.NONE);
}
double[] buffer = spektrumReader.getDbmBuffer();
// Adapt corrected frequency of needed
//
if ( glb_correctFrequencyTimer != 0 ){
glb_correctFrequencyTimer--;
if ( glb_correctFrequencyTimer == 1 ) setCorrectFrequencyRange();
}
minValue = Double.POSITIVE_INFINITY;
minScaledValue = Double.POSITIVE_INFINITY;
maxValue = Double.NEGATIVE_INFINITY;
maxScaledValue = Double.NEGATIVE_INFINITY;
for (int i = 0; i < buffer.length; i++) {
if (minValue > buffer[i] && buffer[i] != Double.NEGATIVE_INFINITY) {
minFrequency = glb_startFreq + i * glb_binStep;
minValue = buffer[i];
}
if (maxValue < buffer[i] && buffer[i] != Double.POSITIVE_INFINITY) {
maxFrequency = glb_startFreq + i * glb_binStep;
maxValue = buffer[i];
}
}
scaledBuffer = scaleBufferX(buffer);
// Mouse Pointer
//
if ((movingCursor != CURSORS.CUR_NONE || mouseDragGraph == GRAPH_DRAG_STARTED)) {
if (glb_lastCursor != MOVE) {
cursor(MOVE);
glb_lastCursor = MOVE;
}
}
else if (Math.abs(mouseX - width) < 5 && Math.abs(mouseY - height) < 5) {
if (glb_lastCursor != CROSS) {
cursor(CROSS);
glb_lastCursor = CROSS;
}
}
else if (Math.abs(mouseX - cursorVerticalLeftX) < 20 || Math.abs(mouseX - cursorVerticalRightX) < 20 || Math.abs(mouseY - cursorHorizontalTopY) < 20 || Math.abs(mouseY - cursorHorizontalBottomY) < 20) {
if (glb_lastCursor != HAND) {
cursor(HAND);
glb_lastCursor = HAND;
}
}
else if (mouseX < graphX()) {
if (glb_lastCursor != ARROW) {
cursor(ARROW);
glb_lastCursor = ARROW;
}
}
else {
if (glb_lastCursor != ARROW) {
cursor(ARROW);
glb_lastCursor = ARROW;
}
}
// Tooltips
//
if (width - mouseX < 30) {
if (glb_tooltipCounter == 0) glb_tooltipCounter = TOOLTIP_TIME;
if (glb_tooltipCounter > 1) showTooltip(mouseX - 150, mouseY, " Use mouse wheel\n to change upper frequency");
}
else if (Math.abs(graphX() - mouseX) < 30) {
if (glb_tooltipCounter == 0) glb_tooltipCounter = TOOLTIP_TIME;
if (glb_tooltipCounter > 1) showTooltip(mouseX, mouseY, " Use mouse wheel\n to change lower frequency");
}
else if (height - mouseY < 30) {
if (glb_tooltipCounter == 0) glb_tooltipCounter = TOOLTIP_TIME;
if (glb_tooltipCounter > 1) showTooltip(mouseX - 150, mouseY - 60, " Use mouse wheel\n to change lower db limit");
}
else if (mouseY < 30) {
if (glb_tooltipCounter == 0) glb_tooltipCounter = TOOLTIP_TIME;
if (glb_tooltipCounter > 1) showTooltip(mouseX - 150, mouseY + 20, " Use mouse wheel\n to change upper db limit");
}
else if (mouseX > cursorVerticalLeftX + 20 && mouseX < cursorVerticalRightX - 20 && mouseY > cursorHorizontalTopY + 20 && mouseY < cursorHorizontalBottomY - 20) {
if (glb_tooltipCounter == 0) glb_tooltipCounter = TOOLTIP_TIME;
if (glb_tooltipCounter > 1) showTooltip(mouseX, mouseY, "Double Click to zoom in \narea between cursors.");
}
else {
glb_tooltipCounter = 0;
}
if (glb_tooltipCounter > 1) glb_tooltipCounter--;
// Reference graph
//
if (!refArrayHasData && refShow) {
refArray = new DataPoint[scaledBuffer.length];
refShow = false;
cp5.get(Toggle.class, "refShow").setValue(0);
}
if (refShow && refArray.length != scaledBuffer.length) {
refStoreFlag = true;
refShow = false;
}
if (refStoreFlag) {
// println("STORE size: " + refArray.length );
if (avgShow && avgArrayHasData) {
refArray = new DataPoint[avgArray.length];
arrayCopy(avgArray, refArray);
cp5.get(Toggle.class, "avgShow").setValue(0);
} else {
refArray = new DataPoint[scaledBuffer.length];
arrayCopy(scaledBuffer, refArray);
}
refArrayHasData = true;
refStoreFlag = false;
refShow = true;
cp5.get(Toggle.class, "refShow").setValue(1);
cp5.get(Knob.class, "refYoffset").setValue(0);
}
// Average graph
//
if (!avgArrayHasData && avgShow) {
avgArray = new DataPoint[scaledBuffer.length];
}
if (avgShow && avgArray.length != scaledBuffer.length) {
avgArray = new DataPoint[scaledBuffer.length];
}
// Persistent data graph
//
if (!perArrayHasData && (perShowMin || perShowMax || perShowMed)) {
perArray = new DataPoint[scaledBuffer.length];
}
if ((perShowMin || perShowMax || perShowMed) && perArray.length != scaledBuffer.length) {
perArray = new DataPoint[scaledBuffer.length];
}
// Data processing per screen point
//
for (int i = 0; i < scaledBuffer.length; i++) {
if (scaledBuffer[i] == null) continue;
if (minScaledValue > scaledBuffer[i].yAvg) {
minScaledValue = scaledBuffer[i].yAvg;
}