Skip to content

Commit b4c5fd1

Browse files
committed
Refactor WidgetManager to contain all Widgets
1 parent bdd3dd9 commit b4c5fd1

33 files changed

Lines changed: 573 additions & 431 deletions

OpenBCI_GUI/ADS1299SettingsController.pde

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,9 @@ void loadHardwareSettings(File selection) {
750750
if (((ADS1299SettingsBoard)currentBoard).getADS1299Settings().loadSettingsValues(selection.getAbsolutePath())) {
751751
outputSuccess("Hardware Settings Loaded!");
752752
for (int i = 0; i < globalChannelCount; i++) {
753-
w_timeSeries.adsSettingsController.updateChanSettingsDropdowns(i, currentBoard.isEXGChannelActive(i));
754-
w_timeSeries.adsSettingsController.updateHasUnappliedSettings(i);
753+
W_TimeSeries timeSeriesWidget = widgetManager.getTimeSeriesWidget();
754+
timeSeriesWidget.adsSettingsController.updateChanSettingsDropdowns(i, currentBoard.isEXGChannelActive(i));
755+
timeSeriesWidget.adsSettingsController.updateHasUnappliedSettings(i);
755756
}
756757
} else {
757758
outputError("Failed to load Hardware Settings.");

OpenBCI_GUI/ControlPanel.pde

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,10 @@ class InitBox {
25062506
//creates new data file name so that you don't accidentally overwrite the old one
25072507
controlPanel.dataLogBoxCyton.setSessionTextfieldText(directoryManager.getFileNameDateTime());
25082508
controlPanel.dataLogBoxGanglion.setSessionTextfieldText(directoryManager.getFileNameDateTime());
2509-
w_focus.killAuditoryFeedback();
2510-
w_marker.disposeUdpMarkerReceiver();
2509+
W_Focus focusWidget = (W_Focus) widgetManager.getWidget("W_Focus");
2510+
W_Marker markerWidget = (W_Marker) widgetManager.getWidget("W_Marker");
2511+
focusWidget.killAuditoryFeedback();
2512+
markerWidget.disposeUdpMarkerReceiver();
25112513
haltSystem();
25122514
widgetManager.setAllWidgetsNull();
25132515
}

OpenBCI_GUI/CytonElectrodeStatus.pde

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ class CytonElectrodeStatus {
346346
final int _chan = channelNumber - 1;
347347
final int curMillis = millis();
348348
println("CytonElectrodeTestButton: Toggling Impedance on ~~ " + electrodeLocation);
349-
w_cytonImpedance.toggleImpedanceOnElectrode(!cytonBoard.isCheckingImpedanceNorP(_chan, is_N_Pin), _chan, is_N_Pin, curMillis);
349+
W_CytonImpedance cytonImpedanceWidget = (W_CytonImpedance) widgetManager.getWidget("W_CytonImpedance");
350+
cytonImpedanceWidget.toggleImpedanceOnElectrode(!cytonBoard.isCheckingImpedanceNorP(_chan, is_N_Pin), _chan, is_N_Pin, curMillis);
350351
}
351352
});
352353
testing_button.setDescription("Click to toggle impedance check for this ADS pin.");

OpenBCI_GUI/DataProcessing.pde

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,12 @@ class DataProcessing {
321321
// -RW #1094 //
322322
/////////////////////////////////////////////////////////////
323323
emgSettings.values.process(dataProcessingFilteredBuffer);
324-
w_focus.updateFocusWidgetData();
325-
w_bandPower.updateBandPowerWidgetData();
326-
w_emgJoystick.updateEmgJoystickWidgetData();
324+
((W_Focus) widgetManager.getWidget("W_Focus")).updateFocusWidgetData();
325+
((W_BandPower) widgetManager.getWidget("W_BandPower")).updateBandPowerWidgetData();
326+
((W_EmgJoystick) widgetManager.getWidget("W_EmgJoystick")).updateEmgJoystickWidgetData();
327327
if (currentBoard instanceof BoardCyton) {
328-
if (w_pulseSensor != null) {
329-
w_pulseSensor.updatePulseSensorWidgetData();
328+
if (widgetManager.getWidgetExists("W_PulseSensor")) {
329+
((W_PulseSensor) widgetManager.getWidget("W_PulseSensor")).updatePulseSensorWidgetData();
330330
}
331331
}
332332

@@ -381,7 +381,7 @@ class DataProcessing {
381381

382382
private void clearCalculatedMetricWidgets() {
383383
println("Clearing calculated metric widgets");
384-
w_spectrogram.clear();
385-
w_focus.clear();
384+
((W_Spectrogram) widgetManager.getWidget("W_Spectrogram")).clear();
385+
((W_Focus) widgetManager.getWidget("W_Focus")).clear();
386386
}
387387
}

OpenBCI_GUI/EmgJoystickEnums.pde

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
public enum EmgJoystickSmoothing implements IndexingInterface
3+
{
4+
OFF (0, "Off", 0f),
5+
POINT_9 (1, "0.9", .9f),
6+
POINT_95 (2, "0.95", .95f),
7+
POINT_98 (3, "0.98", .98f),
8+
POINT_99 (4, "0.99", .99f),
9+
POINT_999 (5, "0.999", .999f),
10+
POINT_9999 (6, "0.9999", .9999f);
11+
12+
private int index;
13+
private String name;
14+
private float value;
15+
private static EmgJoystickSmoothing[] vals = values();
16+
17+
EmgJoystickSmoothing(int index, String name, float value) {
18+
this.index = index;
19+
this.name = name;
20+
this.value = value;
21+
}
22+
23+
public int getIndex() {
24+
return index;
25+
}
26+
27+
public String getString() {
28+
return name;
29+
}
30+
31+
public float getValue() {
32+
return value;
33+
}
34+
35+
private static List<String> getEnumStringsAsList() {
36+
List<String> enumStrings = new ArrayList<String>();
37+
for (IndexingInterface val : vals) {
38+
enumStrings.add(val.getString());
39+
}
40+
return enumStrings;
41+
}
42+
}
43+
44+
public class EMGJoystickInput {
45+
private int index;
46+
private String name;
47+
private int value;
48+
49+
EMGJoystickInput(int index, String name, int value) {
50+
this.index = index;
51+
this.name = name;
52+
this.value = value;
53+
}
54+
55+
public int getIndex() {
56+
return index;
57+
}
58+
59+
public String getString() {
60+
return name;
61+
}
62+
63+
public int getValue() {
64+
return value;
65+
}
66+
}
67+
68+
public class EMGJoystickInputs {
69+
private final int NUM_EMG_INPUTS = 4;
70+
private final EMGJoystickInput[] VALUES;
71+
private final EMGJoystickInput[] INPUTS = new EMGJoystickInput[NUM_EMG_INPUTS];
72+
73+
EMGJoystickInputs(int numExGChannels) {
74+
VALUES = new EMGJoystickInput[numExGChannels];
75+
for (int i = 0; i < numExGChannels; i++) {
76+
VALUES[i] = new EMGJoystickInput(i, "Channel " + (i + 1), i);
77+
}
78+
}
79+
80+
public EMGJoystickInput[] getValues() {
81+
return VALUES;
82+
}
83+
84+
public EMGJoystickInput[] getInputs() {
85+
return INPUTS;
86+
}
87+
88+
public EMGJoystickInput getInput(int index) {
89+
return INPUTS[index];
90+
}
91+
92+
public void setInputToChannel(int inputNumber, int channel) {
93+
if (inputNumber < 0 || inputNumber >= NUM_EMG_INPUTS) {
94+
println("Invalid input number: " + inputNumber);
95+
return;
96+
}
97+
if (channel < 0 || channel >= VALUES.length) {
98+
println("Invalid channel: " + channel);
99+
return;
100+
}
101+
INPUTS[inputNumber] = VALUES[channel];
102+
}
103+
104+
public List<String> getValueStringsAsList() {
105+
List<String> enumStrings = new ArrayList<String>();
106+
for (EMGJoystickInput val : VALUES) {
107+
enumStrings.add(val.getString());
108+
}
109+
return enumStrings;
110+
}
111+
}

OpenBCI_GUI/Extras.pde

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ void doubleToFloatArray(double[] array, float[] res) {
416416
}
417417
}
418418

419+
public double convertByteArrayToDouble(byte[] array) {
420+
ByteBuffer buffer = ByteBuffer.wrap(array);
421+
return buffer.getDouble();
422+
}
423+
419424
// shortens a string to a given width by adding [...] in the middle
420425
// make sure to pass the right font for accurate sizing
421426
String shortenString(String str, float maxWidth, PFont font) {

OpenBCI_GUI/Interactivity.pde

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ void parseKey(char val) {
225225
}
226226

227227
// Check for software marker keyboard shortcuts
228-
if (w_marker.checkForMarkerKeyPress(val)) {
228+
W_Marker markerWidget = (W_Marker) widgetManager.getWidget("W_Marker");
229+
if (markerWidget.checkForMarkerKeyPress(val)) {
229230
return;
230231
}
231232

OpenBCI_GUI/Layout.pde

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
//The Layout class is an organizational tool. A layout consists of a combination of containers (found in Container.pde).
3+
class Layout {
4+
5+
Container[] myContainers;
6+
int[] containerInts;
7+
8+
Layout(int[] _myContainers){ //when creating a new layout, you pass in the integer #s of the containers you want as part of the layout ... so if I pass in the array {5}, my layout is 1 container that takes up the whole GUI body
9+
//constructor stuff
10+
myContainers = new Container[_myContainers.length]; //make the myContainers array equal to the size of the incoming array of ints
11+
containerInts = new int[_myContainers.length];
12+
for(int i = 0; i < _myContainers.length; i++){
13+
myContainers[i] = container[_myContainers[i]];
14+
containerInts[i] = _myContainers[i];
15+
}
16+
}
17+
18+
Container getContainer(int _numContainer){
19+
if(_numContainer < myContainers.length){
20+
return myContainers[_numContainer];
21+
} else{
22+
println("Widget Manager: Tried to return a non-existant container...");
23+
return myContainers[myContainers.length-1];
24+
}
25+
}
26+
};

OpenBCI_GUI/NetworkingDataAccumulator.pde

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,26 @@ public class NetworkingDataAccumulator {
294294
}
295295

296296
public float[] getNormalizedBandPowerData() {
297-
return w_bandPower.getNormalizedBPSelectedChannels();
297+
return ((W_BandPower) widgetManager.getWidget("W_BandPower")).getNormalizedBPSelectedChannels();
298298
}
299299

300300
public float[] getEmgNormalizedValues() {
301301
return dataProcessing.emgSettings.values.getNormalizedValues();
302302
}
303303

304304
public int getPulseSensorBPM() {
305-
return w_pulseSensor.getBPM();
305+
return ((W_PulseSensor) widgetManager.getWidget("W_PulseSensor")).getBPM();
306306
}
307307

308308
public int getPulseSensorIBI() {
309-
return w_pulseSensor.getIBI();
309+
return ((W_PulseSensor) widgetManager.getWidget("W_PulseSensor")).getIBI();
310310
}
311311

312312
public int getFocusValueExceedsThreshold() {
313-
return w_focus.getMetricExceedsThreshold();
313+
return ((W_Focus) widgetManager.getWidget("W_Focus")).getMetricExceedsThreshold();
314314
}
315315

316316
public float[] getEMGJoystickXY() {
317-
return w_emgJoystick.getJoystickXY();
317+
return ((W_EmgJoystick) widgetManager.getWidget("W_EmgJoystick")).getJoystickXY();
318318
}
319319
}

OpenBCI_GUI/OpenBCI_GUI.pde

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,9 @@ void startRunning() {
861861
output("Data stream started.");
862862
// todo: this should really be some sort of signal that listeners can register for "OnStreamStarted"
863863
// close hardware settings if user starts streaming
864-
if (w_timeSeries.getAdsSettingsVisible()) {
865-
w_timeSeries.closeADSSettings();
864+
W_TimeSeries timeSeriesWidget = widgetManager.getTimeSeriesWidget();
865+
if (timeSeriesWidget.getAdsSettingsVisible()) {
866+
timeSeriesWidget.closeADSSettings();
866867
}
867868
try {
868869
streamTimeElapsed.reset();
@@ -918,8 +919,8 @@ void haltSystem() {
918919
}
919920
}
920921

921-
if (w_focus != null) {
922-
w_focus.endSession();
922+
if (widgetManager.getWidgetExists("W_Focus")) {
923+
((W_Focus) widgetManager.getWidget("W_Focus")).endSession();
923924
}
924925

925926
stopRunning();

0 commit comments

Comments
 (0)