Skip to content

Commit 676cdcb

Browse files
committed
Add ability to save/load emg joystick inputs
1 parent b857f04 commit 676cdcb

2 files changed

Lines changed: 53 additions & 12 deletions

File tree

OpenBCI_GUI/SessionSettings.pde

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class SessionSettings {
6868
int fftSmoothingSave;
6969
int fftFilterSave;
7070
//Analog Read settings
71-
int arVertScaleSave; //updates in VertScale_AR()
72-
int arHorizScaleSave; //updates in Duration_AR()
71+
int arVertScaleSave;
72+
int arHorizScaleSave;
7373
//Headplot settings
7474
int hpIntensitySave;
7575
int hpPolaritySave;
@@ -194,6 +194,7 @@ class SessionSettings {
194194

195195
//EMG Joystick Widget
196196
int loadEmgJoystickSmoothing;
197+
List<Integer> loadEmgJoystickInputs = new ArrayList<Integer>();
197198

198199
//Primary JSON objects for saving and loading data
199200
private JSONObject saveSettingsJSONData;
@@ -477,6 +478,12 @@ class SessionSettings {
477478
///////////////////////////////////////////////Setup new JSON object to save EMG Joystick Settings
478479
JSONObject saveEmgJoystickSettings = new JSONObject();
479480
saveEmgJoystickSettings.setInt("smoothing", w_emgJoystick.joystickSmoothing.getIndex());
481+
JSONArray saveEmgJoystickInputs = new JSONArray();
482+
int numEmgJoystickInputs = w_emgJoystick.emgJoystickInputs.length;
483+
for (int i = 0; i < numEmgJoystickInputs; i++) {
484+
saveEmgJoystickInputs.setInt(i, w_emgJoystick.emgJoystickInputs[i].getIndex());
485+
}
486+
saveEmgJoystickSettings.setJSONArray("joystickInputs", saveEmgJoystickInputs);
480487
saveSettingsJSONData.setJSONObject(kJSONKeyEmgJoystick, saveEmgJoystickSettings);
481488

482489
///////////////////////////////////////////////Setup new JSON object to save Widgets Active in respective Containers
@@ -662,6 +669,11 @@ class SessionSettings {
662669
//Get EMG Joystick widget settings
663670
JSONObject loadEmgJoystickSettings = loadSettingsJSONData.getJSONObject(kJSONKeyEmgJoystick);
664671
loadEmgJoystickSmoothing = loadEmgJoystickSettings.getInt("smoothing");
672+
loadEmgJoystickInputs.clear();
673+
JSONArray loadJoystickInputsJson = loadEmgJoystickSettings.getJSONArray("joystickInputs");
674+
for (int i = 0; i < loadJoystickInputsJson.size(); i++) {
675+
loadEmgJoystickInputs.add(loadJoystickInputsJson.getInt(i));
676+
}
665677

666678
//get the Widget/Container settings
667679
JSONObject loadWidgetSettings = loadSettingsJSONData.getJSONObject(kJSONKeyWidget);
@@ -913,6 +925,13 @@ class SessionSettings {
913925
w_emgJoystick.setJoystickSmoothing(loadEmgJoystickSmoothing);
914926
w_emgJoystick.cp5_widget.getController("emgJoystickSmoothingDropdown").getCaptionLabel()
915927
.setText(EmgJoystickSmoothing.getEnumStringsAsList().get(loadEmgJoystickSmoothing));
928+
try {
929+
for (int i = 0; i < loadEmgJoystickInputs.size(); i++) {
930+
w_emgJoystick.updateJoystickInput(i, loadEmgJoystickInputs.get(i));
931+
}
932+
} catch (Exception e) {
933+
println("Settings: Exception caught applying EMG Joystick settings " + e);
934+
}
916935

917936
////////////////////////////////////////////////////////////
918937
// Apply more loaded widget settings above this line //

OpenBCI_GUI/W_EMGJoystick.pde

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ class W_EMGJoystick extends Widget {
4747

4848
private String[] plotChannelLabels = new String[NUM_EMG_CHANNELS];
4949

50-
EmgJoystickSmoothing joystickSmoothing = EmgJoystickSmoothing.POINT_9;
50+
public EmgJoystickSmoothing joystickSmoothing = EmgJoystickSmoothing.POINT_9;
5151

5252
private int DROPDOWN_HEIGHT = navH - 4;
5353
private int DROPDOWN_WIDTH = 80;
5454
private int DROPDOWN_SPACER = 10;
5555
private int DROPDOWN_LABEL_WIDTH = 24;
5656

57-
EmgJoystickInput[] emgJoystickInputs = new EmgJoystickInput[NUM_EMG_CHANNELS];
57+
public EmgJoystickInput[] emgJoystickInputs = new EmgJoystickInput[NUM_EMG_CHANNELS];
5858

59-
ScrollableList xNegativeInputDropdown;
60-
ScrollableList xPositiveInputDropdown;
61-
ScrollableList yPositiveInputDropdown;
62-
ScrollableList yNegativeInputDropdown;
59+
private ScrollableList xNegativeInputDropdown;
60+
private ScrollableList xPositiveInputDropdown;
61+
private ScrollableList yPositiveInputDropdown;
62+
private ScrollableList yNegativeInputDropdown;
6363

64-
TextBox xNegativeInputDropdownLabel;
65-
TextBox xPositiveInputDropdownLabel;
66-
TextBox yPositiveInputDropdownLabel;
67-
TextBox yNegativeInputDropdownLabel;
64+
private TextBox xNegativeInputDropdownLabel;
65+
private TextBox xPositiveInputDropdownLabel;
66+
private TextBox yPositiveInputDropdownLabel;
67+
private TextBox yNegativeInputDropdownLabel;
6868

6969
W_EMGJoystick(PApplet _parent){
7070
super(_parent); //calls the parent CONSTRUCTOR method of Widget (DON'T REMOVE)
@@ -424,6 +424,28 @@ class W_EMGJoystick extends Widget {
424424
yNegativeInputDropdownLabel.draw();
425425
}
426426

427+
public void updateJoystickInput(int inputNumber, Integer value) {
428+
if (value == null) {
429+
return;
430+
}
431+
emgJoystickInputs[inputNumber] = EmgJoystickInput.values()[value];
432+
String inputName = emgJoystickInputs[inputNumber].getString();
433+
switch (inputNumber) {
434+
case 0:
435+
xNegativeInputDropdown.getCaptionLabel().setText(inputName);
436+
break;
437+
case 1:
438+
xPositiveInputDropdown.getCaptionLabel().setText(inputName);
439+
break;
440+
case 2:
441+
yPositiveInputDropdown.getCaptionLabel().setText(inputName);
442+
break;
443+
case 3:
444+
yNegativeInputDropdown.getCaptionLabel().setText(inputName);
445+
break;
446+
}
447+
}
448+
427449
};
428450

429451
public void emgJoystickSmoothingDropdown(int n) {

0 commit comments

Comments
 (0)