Skip to content

Commit a29d9bc

Browse files
committed
Add WidgetWithSettings to EMG and EMGJoystick widgets
1 parent 8b68e6b commit a29d9bc

2 files changed

Lines changed: 39 additions & 18 deletions

File tree

OpenBCI_GUI/W_EMG.pde

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,17 @@
1313
// TODO: Add dynamic threshold functionality
1414
////////////////////////////////////////////////////////////////////////////////
1515

16-
class W_Emg extends Widget {
16+
class W_Emg extends WidgetWithSettings {
1717
private ControlP5 emgCp5;
1818
private Button emgSettingsButton;
1919
private final int EMG_SETTINGS_BUTTON_WIDTH = 125;
2020
private List<controlP5.Controller> cp5ElementsToCheck;
21-
2221
public ExGChannelSelect emgChannelSelect;
2322

2423
W_Emg () {
2524
super();
2625
widgetTitle = "EMG";
2726

28-
cp5ElementsToCheck = new ArrayList<controlP5.Controller>();
29-
30-
//Add channel select dropdown to this widget
31-
emgChannelSelect = new ExGChannelSelect(ourApplet, x, y, w, navH);
32-
emgChannelSelect.activateAllButtons();
33-
34-
cp5ElementsToCheck.addAll(emgChannelSelect.getCp5ElementsForOverlapCheck());
35-
3627
emgCp5 = new ControlP5(ourApplet);
3728
emgCp5.setGraphics(ourApplet, 0,0);
3829
emgCp5.setAutoDraw(false);
@@ -41,6 +32,29 @@ class W_Emg extends Widget {
4132
cp5ElementsToCheck.add((controlP5.Controller) emgSettingsButton);
4233
}
4334

35+
@Override
36+
protected void initWidgetSettings() {
37+
super.initWidgetSettings();
38+
emgChannelSelect = new ExGChannelSelect(ourApplet, x, y, w, navH);
39+
emgChannelSelect.activateAllButtons();
40+
cp5ElementsToCheck = new ArrayList<controlP5.Controller>();
41+
cp5ElementsToCheck.addAll(emgChannelSelect.getCp5ElementsForOverlapCheck());
42+
saveActiveChannels(emgChannelSelect.getActiveChannels());
43+
widgetSettings.saveDefaults();
44+
}
45+
46+
@Override
47+
protected void applySettings() {
48+
applyActiveChannels(emgChannelSelect);
49+
}
50+
51+
@Override
52+
protected void updateChannelSettings() {
53+
if (emgChannelSelect != null) {
54+
saveActiveChannels(emgChannelSelect.getActiveChannels());
55+
}
56+
}
57+
4458
public void update() {
4559
super.update();
4660
lockElementsOnOverlapCheck(cp5ElementsToCheck);

OpenBCI_GUI/W_EMGJoystick.pde

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// //
1010
/////////////////////////////////////////////////////////////////////////////////////////////////////////
1111

12-
class W_EmgJoystick extends Widget {
12+
class W_EmgJoystick extends WidgetWithSettings {
1313
private ControlP5 emgCp5;
1414
private Button emgSettingsButton;
1515
private List<controlP5.Controller> cp5ElementsToCheck;
@@ -46,8 +46,6 @@ class W_EmgJoystick extends Widget {
4646

4747
private String[] plotChannelLabels = new String[NUM_EMG_INPUTS];
4848

49-
public EmgJoystickSmoothing joystickSmoothing = EmgJoystickSmoothing.POINT_9;
50-
5149
private int DROPDOWN_HEIGHT = navH - 4;
5250
private int DROPDOWN_WIDTH = 80;
5351
private int DROPDOWN_SPACER = 10;
@@ -96,11 +94,20 @@ class W_EmgJoystick extends Widget {
9694
plotChannelLabels[i] = Integer.toString(emgJoystickInputs.getInput(i).getIndex() + 1);
9795
}
9896

99-
List<String> joystickSmoothingList = EnumHelper.getEnumStrings(EmgJoystickSmoothing.class);
97+
createInputDropdowns();
98+
}
10099

101-
addDropdown("emgJoystickSmoothingDropdown", "Smoothing", joystickSmoothingList, joystickSmoothing.getIndex());
100+
@Override
101+
protected void initWidgetSettings() {
102+
super.initWidgetSettings();
103+
widgetSettings.set(EmgJoystickSmoothing.class, EmgJoystickSmoothing.POINT_9);
104+
initDropdown(EmgJoystickSmoothing.class, "emgJoystickSmoothingDropdown", "Smoothing");
105+
widgetSettings.saveDefaults();
106+
}
102107

103-
createInputDropdowns();
108+
@Override
109+
protected void applySettings() {
110+
updateDropdownLabel(EmgJoystickSmoothing.class, "emgJoystickSmoothingDropdown");
104111
}
105112

106113
public void update(){
@@ -234,7 +241,7 @@ class W_EmgJoystick extends Widget {
234241
joystickRawX = unitCircleXY[0];
235242
joystickRawY = unitCircleXY[1];
236243
//Lerp the joystick values to smooth them out
237-
float amount = 1.0f - joystickSmoothing.getValue();
244+
float amount = 1.0f - widgetSettings.get(EmgJoystickSmoothing.class).getValue();
238245
joystickRawX = lerp(previousJoystickRawX, joystickRawX, amount);
239246
joystickRawY = lerp(previousJoystickRawY, joystickRawY, amount);
240247
}
@@ -316,7 +323,7 @@ class W_EmgJoystick extends Widget {
316323
}
317324

318325
public void setJoystickSmoothing(int n) {
319-
joystickSmoothing = joystickSmoothing.values()[n];
326+
widgetSettings.setByIndex(EmgJoystickSmoothing.class, n);
320327
}
321328

322329
private void createEmgSettingsButton() {

0 commit comments

Comments
 (0)