Skip to content

Commit ecd6985

Browse files
committed
Add EMG joystick to session settings #1159
1 parent dbe46f9 commit ecd6985

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

OpenBCI_GUI/SessionSettings.pde

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ class SessionSettings {
189189
//Serial load variables
190190
int nwSerialBaudRateLoad;
191191

192+
//EMG Widget
193+
List<Integer> loadEmgActiveChannels = new ArrayList<Integer>();
194+
195+
//EMG Joystick Widget
196+
int loadEmgJoystickSmoothing;
197+
192198
//Primary JSON objects for saving and loading data
193199
private JSONObject saveSettingsJSONData;
194200
private JSONObject loadSettingsJSONData;
@@ -204,6 +210,8 @@ class SessionSettings {
204210
private final String kJSONKeyWidget = "widget";
205211
private final String kJSONKeyVersion = "version";
206212
private final String kJSONKeySpectrogram = "spectrogram";
213+
private final String kJSONKeyEmg = "emg";
214+
private final String kJSONKeyEmgJoystick = "emgJoystick";
207215

208216
//used only in this class to count the number of channels being used while saving/loading, this gets updated in updateToNChan whenever the number of channels being used changes
209217
int slnchan;
@@ -453,6 +461,24 @@ class SessionSettings {
453461
saveSpectrogramSettings.setInt("Spectrogram_LogLin", spectLogLinSave);
454462
saveSettingsJSONData.setJSONObject(kJSONKeySpectrogram, saveSpectrogramSettings);
455463

464+
///////////////////////////////////////////////Setup new JSON object to save EMG Settings
465+
JSONObject saveEMGSettings = new JSONObject();
466+
467+
//Save data from the Active channel checkBoxes
468+
JSONArray saveActiveChanEMG = new JSONArray();
469+
int numActiveEMGChan = w_emg.emgChannelSelect.activeChan.size();
470+
for (int i = 0; i < numActiveEMGChan; i++) {
471+
int activeChan = w_emg.emgChannelSelect.activeChan.get(i);
472+
saveActiveChanEMG.setInt(i, activeChan);
473+
}
474+
saveEMGSettings.setJSONArray("activeChannels", saveActiveChanEMG);
475+
saveSettingsJSONData.setJSONObject(kJSONKeyEmg, saveEMGSettings);
476+
477+
///////////////////////////////////////////////Setup new JSON object to save EMG Joystick Settings
478+
JSONObject saveEmgJoystickSettings = new JSONObject();
479+
saveEmgJoystickSettings.setInt("smoothing", w_emgJoystick.joystickSmoothing.getIndex());
480+
saveSettingsJSONData.setJSONObject(kJSONKeyEmgJoystick, saveEmgJoystickSettings);
481+
456482
///////////////////////////////////////////////Setup new JSON object to save Widgets Active in respective Containers
457483
JSONObject saveWidgetSettings = new JSONObject();
458484

@@ -625,6 +651,18 @@ class SessionSettings {
625651
e.printStackTrace();
626652
}
627653

654+
//Get EMG widget settings
655+
loadEmgActiveChannels.clear();
656+
JSONObject loadEmgSettings = loadSettingsJSONData.getJSONObject(kJSONKeyEmg);
657+
JSONArray loadEmgChan = loadEmgSettings.getJSONArray("activeChannels");
658+
for (int i = 0; i < loadEmgChan.size(); i++) {
659+
loadEmgActiveChannels.add(loadEmgChan.getInt(i));
660+
}
661+
662+
//Get EMG Joystick widget settings
663+
JSONObject loadEmgJoystickSettings = loadSettingsJSONData.getJSONObject(kJSONKeyEmgJoystick);
664+
loadEmgJoystickSmoothing = loadEmgJoystickSettings.getInt("smoothing");
665+
628666
//get the Widget/Container settings
629667
JSONObject loadWidgetSettings = loadSettingsJSONData.getJSONObject(kJSONKeyWidget);
630668
//Apply Layout directly before loading and applying widgets to containers
@@ -859,6 +897,25 @@ class SessionSettings {
859897
break;
860898
}//end switch-case for networking settings for all networking protocols
861899

900+
////////////////////////////Apply EMG widget settings
901+
try {
902+
//apply channel checkbox settings
903+
w_emg.emgChannelSelect.deactivateAllButtons();;
904+
for (int i = 0; i < loadEmgActiveChannels.size(); i++) {
905+
w_emg.emgChannelSelect.setToggleState(loadEmgActiveChannels.get(i), true);
906+
}
907+
} catch (Exception e) {
908+
println("Settings: Exception caught applying EMG widget settings " + e);
909+
}
910+
verbosePrint("Settings: EMG Widget Active Channels: " + loadEmgActiveChannels);
911+
912+
////////////////////////////Apply EMG Joystick settings
913+
w_emgJoystick.setJoystickSmoothing(loadEmgJoystickSmoothing);
914+
println("Settings: EMG Joystick Smoothing: " + loadEmgJoystickSmoothing);
915+
println(EmgJoystickSmoothing.getEnumStringsAsList().get(loadEmgJoystickSmoothing));
916+
w_emgJoystick.cp5_widget.getController("emgJoystickSmoothingDropdown").getCaptionLabel()
917+
.setText(EmgJoystickSmoothing.getEnumStringsAsList().get(loadEmgJoystickSmoothing));
918+
862919
////////////////////////////////////////////////////////////
863920
// Apply more loaded widget settings above this line //
864921

0 commit comments

Comments
 (0)