Skip to content

Commit 19a14e9

Browse files
committed
Refactor settings for TimeSeries, Accelerometer, Analog Read, and Digital Read widgets
1 parent 31a20ad commit 19a14e9

8 files changed

Lines changed: 483 additions & 376 deletions

OpenBCI_GUI/AccelerometerEnums.pde

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
public enum AccelerometerVerticalScale implements IndexingInterface
2+
{
3+
AUTO (0, 0, "Auto"),
4+
ONE_G (1, 1, "1 g"),
5+
TWO_G (2, 2, "2 g"),
6+
FOUR_G (3, 4, "4 g");
7+
8+
private int index;
9+
private int value;
10+
private String label;
11+
private static AccelerometerVerticalScale[] values = AccelerometerVerticalScale.values();
12+
13+
AccelerometerVerticalScale(int _index, int _value, String _label) {
14+
this.index = _index;
15+
this.value = _value;
16+
this.label = _label;
17+
}
18+
19+
public int getValue() {
20+
return value;
21+
}
22+
23+
@Override
24+
public String getString() {
25+
return label;
26+
}
27+
28+
@Override
29+
public int getIndex() {
30+
return index;
31+
}
32+
33+
public static List<String> getEnumStringsAsList() {
34+
List<String> enumStrings = new ArrayList<>();
35+
for (IndexingInterface enumValue : values) {
36+
enumStrings.add(enumValue.getString());
37+
}
38+
return enumStrings;
39+
}
40+
41+
public int getHighestValue() {
42+
int highestValue = 0;
43+
for (AccelerometerVerticalScale scale : values) {
44+
if (scale.getValue() > highestValue) {
45+
highestValue = scale.getValue();
46+
}
47+
}
48+
return highestValue;
49+
}
50+
}
51+
52+
public enum AccelerometerHorizontalScale implements IndexingInterface
53+
{
54+
ONE_SEC (1, 1, "1 sec"),
55+
THREE_SEC (2, 3, "3 sec"),
56+
FIVE_SEC (3, 5, "5 sec"),
57+
TEN_SEC (4, 10, "10 sec"),
58+
TWENTY_SEC (5, 20, "20 sec");
59+
60+
private int index;
61+
private int value;
62+
private String label;
63+
private static AccelerometerHorizontalScale[] values = AccelerometerHorizontalScale.values();
64+
65+
AccelerometerHorizontalScale(int _index, int _value, String _label) {
66+
this.index = _index;
67+
this.value = _value;
68+
this.label = _label;
69+
}
70+
71+
public int getValue() {
72+
return value;
73+
}
74+
75+
@Override
76+
public String getString() {
77+
return label;
78+
}
79+
80+
@Override
81+
public int getIndex() {
82+
return index;
83+
}
84+
85+
public static List<String> getEnumStringsAsList() {
86+
List<String> enumStrings = new ArrayList<>();
87+
for (IndexingInterface enumValue : values) {
88+
enumStrings.add(enumValue.getString());
89+
}
90+
return enumStrings;
91+
}
92+
93+
public int getHighestValue() {
94+
int highestValue = 0;
95+
for (AccelerometerHorizontalScale scale : values) {
96+
if (scale.getValue() > highestValue) {
97+
highestValue = scale.getValue();
98+
}
99+
}
100+
return highestValue;
101+
}
102+
}

OpenBCI_GUI/AnalogReadEnums.pde

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
public enum AnalogReadVerticalScale implements IndexingInterface
2+
{
3+
AUTO (0, 0, "Auto"),
4+
FIFTY (1, 50, "50 uV"),
5+
ONE_HUNDRED (2, 100, "100 uV"),
6+
TWO_HUNDRED (3, 200, "200 uV"),
7+
FOUR_HUNDRED (4, 400, "400 uV"),
8+
ONE_THOUSAND_FIFTY (5, 1050, "1050 uV"),
9+
TEN_THOUSAND (6, 10000, "10000 uV");
10+
11+
private int index;
12+
private int value;
13+
private String label;
14+
private static AnalogReadVerticalScale[] values = AnalogReadVerticalScale.values();
15+
16+
AnalogReadVerticalScale(int _index, int _value, String _label) {
17+
this.index = _index;
18+
this.value = _value;
19+
this.label = _label;
20+
}
21+
22+
public int getValue() {
23+
return value;
24+
}
25+
26+
@Override
27+
public String getString() {
28+
return label;
29+
}
30+
31+
@Override
32+
public int getIndex() {
33+
return index;
34+
}
35+
36+
public static List<String> getEnumStringsAsList() {
37+
List<String> enumStrings = new ArrayList<>();
38+
for (IndexingInterface enumValue : values) {
39+
enumStrings.add(enumValue.getString());
40+
}
41+
return enumStrings;
42+
}
43+
}
44+
45+
public enum AnalogReadHorizontalScale implements IndexingInterface
46+
{
47+
ONE_SEC (1, 1, "1 sec"),
48+
THREE_SEC (2, 3, "3 sec"),
49+
FIVE_SEC (3, 5, "5 sec"),
50+
TEN_SEC (4, 10, "10 sec"),
51+
TWENTY_SEC (5, 20, "20 sec");
52+
53+
private int index;
54+
private int value;
55+
private String label;
56+
private static AnalogReadHorizontalScale[] values = AnalogReadHorizontalScale.values();
57+
58+
AnalogReadHorizontalScale(int _index, int _value, String _label) {
59+
this.index = _index;
60+
this.value = _value;
61+
this.label = _label;
62+
}
63+
64+
public int getValue() {
65+
return value;
66+
}
67+
68+
@Override
69+
public String getString() {
70+
return label;
71+
}
72+
73+
@Override
74+
public int getIndex() {
75+
return index;
76+
}
77+
78+
public static List<String> getEnumStringsAsList() {
79+
List<String> enumStrings = new ArrayList<>();
80+
for (IndexingInterface enumValue : values) {
81+
enumStrings.add(enumValue.getString());
82+
}
83+
return enumStrings;
84+
}
85+
}

OpenBCI_GUI/SessionSettings.pde

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ class SessionSettings {
5656
private long logFileMaxDurationNano = -1;
5757
//this is a global CColor that determines the style of all widget dropdowns ... this should go in WidgetManager.pde
5858
CColor dropdownColors = new CColor();
59-
///These `Save` vars are set to default when each widget instantiates
60-
///and updated every time user selects from dropdown
61-
//Accelerometer settings
62-
int accVertScaleSave;
63-
int accHorizScaleSave;
64-
//Analog Read settings
65-
int arVertScaleSave;
66-
int arHorizScaleSave;
6759

6860
//default configuration settings file location and file name variables
6961
private String sessionPath = "";
@@ -86,14 +78,6 @@ class SessionSettings {
8678
"SynthSixteenDefaultSettings.json"
8779
};
8880

89-
//Used to set text in dropdown menus when loading Accelerometer settings
90-
String[] accVertScaleArray = {"Auto","1 g", "2 g"};
91-
String[] accHorizScaleArray = {"Sync", "1 sec", "3 sec", "5 sec", "10 sec", "20 sec"};
92-
93-
//Used to set text in dropdown menus when loading Analog Read settings
94-
String[] arVertScaleArray = {"Auto", "50", "100", "200", "400", "1000", "10000"};
95-
String[] arHorizScaleArray = {"Sync", "1 sec", "3 sec", "5 sec", "10 sec", "20 sec"};
96-
9781
//Load Accel. dropdown variables
9882
int loadAccelVertScale;
9983
int loadAccelHorizScale;
@@ -278,9 +262,9 @@ class SessionSettings {
278262

279263
//Make a new JSON Object for Time Series Settings
280264
JSONObject saveTSSettings = new JSONObject();
281-
saveTSSettings.setInt("Time Series Vert Scale", w_timeSeries.getTSVertScale().getIndex());
282-
saveTSSettings.setInt("Time Series Horiz Scale", w_timeSeries.getTSHorizScale().getIndex());
283-
saveTSSettings.setInt("Time Series Label Mode", w_timeSeries.getTSLabelMode().getIndex());
265+
saveTSSettings.setInt("Time Series Vert Scale", w_timeSeries.getVerticalScale().getIndex());
266+
saveTSSettings.setInt("Time Series Horiz Scale", w_timeSeries.getHorizontalScale().getIndex());
267+
saveTSSettings.setInt("Time Series Label Mode", w_timeSeries.getLabelMode().getIndex());
284268
//Save data from the Active channel checkBoxes
285269
JSONArray saveActiveChanTS = new JSONArray();
286270
int numActiveTSChan = w_timeSeries.tsChanSelect.getActiveChannels().size();
@@ -294,8 +278,11 @@ class SessionSettings {
294278
//Make a second JSON object within our JSONArray to store Global settings for the GUI
295279
JSONObject saveGlobalSettings = new JSONObject();
296280
saveGlobalSettings.setInt("Current Layout", currentLayout);
281+
//FIX ME
282+
/*
297283
saveGlobalSettings.setInt("Analog Read Vert Scale", arVertScaleSave);
298284
saveGlobalSettings.setInt("Analog Read Horiz Scale", arHorizScaleSave);
285+
*/
299286
if (currentBoard instanceof SmoothingCapableBoard) {
300287
saveGlobalSettings.setBoolean("Data Smoothing", ((SmoothingCapableBoard)currentBoard).getSmoothingActive());
301288
}
@@ -329,12 +316,15 @@ class SessionSettings {
329316
saveSettingsJSONData.setJSONObject(kJSONKeyFFT, saveFFTSettings); //next object will be set to sessionSettingsChannelCount+3, etc.
330317

331318
///////////////////////////////////////////////Setup new JSON object to save Accelerometer settings
319+
//FIX ME
320+
/*
332321
if (w_accelerometer != null) {
333322
JSONObject saveAccSettings = new JSONObject();
334323
saveAccSettings.setInt("Accelerometer Vert Scale", accVertScaleSave);
335324
saveAccSettings.setInt("Accelerometer Horiz Scale", accHorizScaleSave);
336325
saveSettingsJSONData.setJSONObject(kJSONKeyAccel, saveAccSettings);
337326
}
327+
*/
338328

339329
///////////////////////////////////////////////Save Networking settings
340330
String nwSettingsValues = dataProcessing.networkingSettings.getJson();
@@ -512,8 +502,11 @@ class SessionSettings {
512502
JSONObject loadGlobalSettings = loadSettingsJSONData.getJSONObject(kJSONKeySettings);
513503
//Store loaded layout to current layout variable
514504
currentLayout = loadGlobalSettings.getInt("Current Layout");
505+
//FIX ME
506+
/*
515507
loadAnalogReadVertScale = loadGlobalSettings.getInt("Analog Read Vert Scale");
516508
loadAnalogReadHorizScale = loadGlobalSettings.getInt("Analog Read Horiz Scale");
509+
*/
517510
//Load more global settings after this line, if needed
518511
Boolean loadDataSmoothingSetting = (currentBoard instanceof SmoothingCapableBoard) ? loadGlobalSettings.getBoolean("Data Smoothing") : null;
519512

@@ -528,12 +521,15 @@ class SessionSettings {
528521
fftFilterLoad = loadFFTSettings.getInt("FFT_Filter");
529522
*/
530523

524+
//FIX ME
525+
/*
531526
//get the Accelerometer settings
532527
if (w_accelerometer != null) {
533528
JSONObject loadAccSettings = loadSettingsJSONData.getJSONObject(kJSONKeyAccel);
534529
loadAccelVertScale = loadAccSettings.getInt("Accelerometer Vert Scale");
535530
loadAccelHorizScale = loadAccSettings.getInt("Accelerometer Horiz Scale");
536531
}
532+
*/
537533

538534
//get the Networking Settings
539535
loadNetworkingSettings = loadSettingsJSONData.getJSONObject(kJSONKeyNetworking);
@@ -710,24 +706,29 @@ class SessionSettings {
710706
w_fft.cp5_widget.getController("UnfiltFilt").getCaptionLabel().setText(fftFilterArray[fftFilterLoad]);
711707
*/
712708

713-
////////Apply Accelerometer settings;
709+
////////Apply Accelerometer settings
710+
//FIX ME
711+
/*
714712
if (w_accelerometer != null) {
715713
accelVertScale(loadAccelVertScale);
716714
w_accelerometer.cp5_widget.getController("accelVertScale").getCaptionLabel().setText(accVertScaleArray[loadAccelVertScale]);
717715
718716
accelDuration(loadAccelHorizScale);
719717
w_accelerometer.cp5_widget.getController("accelDuration").getCaptionLabel().setText(accHorizScaleArray[loadAccelHorizScale]);
720718
}
719+
*/
721720

722721
////////Apply Anolog Read dropdowns to Live Cyton Only
722+
//FIX ME
723+
/*
723724
if (eegDataSource == DATASOURCE_CYTON) {
724-
////////Apply Analog Read settings
725725
VertScale_AR(loadAnalogReadVertScale);
726726
w_analogRead.cp5_widget.getController("VertScale_AR").getCaptionLabel().setText(arVertScaleArray[loadAnalogReadVertScale]);
727727
728728
Duration_AR(loadAnalogReadHorizScale);
729729
w_analogRead.cp5_widget.getController("Duration_AR").getCaptionLabel().setText(arHorizScaleArray[loadAnalogReadHorizScale]);
730730
}
731+
*/
731732

732733
////////////////////////////Apply Headplot settings
733734
//FIX ME
@@ -854,14 +855,14 @@ class SessionSettings {
854855

855856
JSONObject loadTimeSeriesSettings = loadSettingsJSONData.getJSONObject(kJSONKeyTimeSeries);
856857
////////Apply Time Series widget settings
857-
w_timeSeries.setTSVertScale(loadTimeSeriesSettings.getInt("Time Series Vert Scale"));
858-
w_timeSeries.cp5_widget.getController("VertScale_TS").getCaptionLabel().setText(w_timeSeries.getTSVertScale().getString()); //changes front-end
858+
w_timeSeries.setVerticalScale(loadTimeSeriesSettings.getInt("Time Series Vert Scale"));
859+
w_timeSeries.cp5_widget.getController("VertScale_TS").getCaptionLabel().setText(w_timeSeries.getVerticalScale().getString()); //changes front-end
859860

860-
w_timeSeries.setTSHorizScale(loadTimeSeriesSettings.getInt("Time Series Horiz Scale"));
861-
w_timeSeries.cp5_widget.getController("Duration").getCaptionLabel().setText(w_timeSeries.getTSHorizScale().getString());
861+
w_timeSeries.setHorizontalScale(loadTimeSeriesSettings.getInt("Time Series Horiz Scale"));
862+
w_timeSeries.cp5_widget.getController("Duration").getCaptionLabel().setText(w_timeSeries.getHorizontalScale().getString());
862863

863-
w_timeSeries.setTSLabelMode(loadTimeSeriesSettings.getInt("Time Series Label Mode"));
864-
w_timeSeries.cp5_widget.getController("LabelMode_TS").getCaptionLabel().setText(w_timeSeries.getTSLabelMode().getString());
864+
w_timeSeries.setLabelMode(loadTimeSeriesSettings.getInt("Time Series Label Mode"));
865+
w_timeSeries.cp5_widget.getController("LabelMode_TS").getCaptionLabel().setText(w_timeSeries.getLabelMode().getString());
865866

866867
JSONArray loadTSChan = loadTimeSeriesSettings.getJSONArray("activeChannels");
867868
w_timeSeries.tsChanSelect.deactivateAllButtons();

0 commit comments

Comments
 (0)