Skip to content

Commit 1cd9232

Browse files
authored
Merge pull request #1009 from OpenBCI/development
Development 5.0.9
2 parents 4ab8cf7 + 6d76ef9 commit 1cd9232

24 files changed

+1916
-318
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v5.0.9
2+
3+
### Bug Fixes
4+
* Change TimeSeries y-axis textfields to labels to increase performance and fix font on some Macs
5+
6+
### Improvements
7+
* For Cyton, only allow checking impedance on one channel at a time #983
8+
* Make new Cyton Signal Check Widget #983
9+
110
# v5.0.8
211

312
### Bug Fixes

OpenBCI_GUI/ADS1299SettingsBoard.pde

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class ADS1299Settings {
143143

144144
public ADS1299SettingsValues values;
145145
public ADS1299SettingsValues previousValues;
146+
private ADS1299SettingsValues defaultValues;
146147

147148
protected Board board;
148149
protected ADS1299SettingsBoard settingsBoard;
@@ -152,6 +153,7 @@ class ADS1299Settings {
152153
settingsBoard = (ADS1299SettingsBoard)theBoard;
153154
values = new ADS1299SettingsValues();
154155
previousValues = new ADS1299SettingsValues();
156+
defaultValues = new ADS1299SettingsValues();
155157

156158
int channelCount = board.getNumEXGChannels();
157159

@@ -185,6 +187,10 @@ class ADS1299Settings {
185187
values.previousBias = values.bias.clone();
186188
values.previousSrb2 = values.srb2.clone();
187189
values.previousInputType = values.inputType.clone();
190+
191+
String currentVals = getJson();
192+
Gson gson = new Gson();
193+
defaultValues = gson.fromJson(currentVals, ADS1299SettingsValues.class);
188194
}
189195

190196
public boolean loadSettingsValues(String filename) {
@@ -271,6 +277,26 @@ class ADS1299Settings {
271277
return success;
272278
}
273279

280+
//Return true if all commits are successful
281+
public boolean commitDefaultsAllAtOnce() {
282+
StringBuilder sb = new StringBuilder();
283+
for (int i = 0; i < board.getNumEXGChannels(); i++) {
284+
String command = String.format("x%c%d%d%d%d%d%dX", settingsBoard.getChannelSelector(i),
285+
defaultValues.powerDown[i].ordinal(), defaultValues.gain[i].ordinal(),
286+
defaultValues.inputType[i].ordinal(), defaultValues.bias[i].ordinal(),
287+
defaultValues.srb2[i].ordinal(), defaultValues.srb1[i].ordinal());
288+
sb.append(command);
289+
}
290+
return board.sendCommand(sb.toString()).getKey().booleanValue();
291+
}
292+
293+
//Return true if all commits are successful
294+
public void revertAllChannelsToDefaultValues() {
295+
Gson gson = new GsonBuilder().setPrettyPrinting().create();
296+
String defaultValsAsString = gson.toJson(defaultValues);
297+
values = gson.fromJson(defaultValsAsString, ADS1299SettingsValues.class);
298+
}
299+
274300
public void saveAllLastValues() {
275301
String lastVals = getJson();
276302
Gson gson = new Gson();
@@ -285,6 +311,14 @@ class ADS1299Settings {
285311
previousValues.srb1[chan] = values.srb1[chan];
286312
}
287313

314+
public void revertToLastValues(int chan) {
315+
values.gain[chan] = previousValues.gain[chan];
316+
values.inputType[chan] = previousValues.inputType[chan];
317+
values.bias[chan] = previousValues.bias[chan];
318+
values.srb2[chan] = previousValues.srb2[chan];
319+
values.srb1[chan] = previousValues.srb1[chan];
320+
}
321+
288322
public boolean equalsLastValues(int chan) {
289323
boolean equal = previousValues.gain[chan] == values.gain[chan] &&
290324
previousValues.inputType[chan] == values.inputType[chan] &&
@@ -294,6 +328,15 @@ class ADS1299Settings {
294328
;
295329
return equal;
296330
}
331+
332+
//Get previous or current values as a string
333+
public String getValuesString(int chan, ADS1299SettingsValues vals) {
334+
String commandString = String.format("x%c%d%d%d%d%d%dX", settingsBoard.getChannelSelector(chan),
335+
vals.powerDown[chan].ordinal(), vals.gain[chan].ordinal(),
336+
vals.inputType[chan].ordinal(), vals.bias[chan].ordinal(),
337+
vals.srb2[chan].ordinal(), vals.srb1[chan].ordinal());
338+
return commandString;
339+
}
297340
}
298341

299342
interface ADS1299SettingsBoard {

OpenBCI_GUI/ADS1299SettingsController.pde

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,14 @@ class ADS1299SettingsController {
491491
c = isActive ? (boardSettings.values.srb1[chan] == Srb1.CONNECT ? yesOnColor : noOffColor) : darkNotActive;
492492
srb1Lists[chan].setValue(boardSettings.values.srb1[chan].ordinal());
493493
srb1Lists[chan].setColorBackground(c);
494-
srb1Lists[chan].setLock(!isActive);
494+
srb1Lists[chan].setLock(!isActive);
495+
}
495496

496-
497+
public void updateAllChanSettingsDropdowns() {
498+
for (int i = 0; i < currentBoard.getNumEXGChannels(); i++) {
499+
updateChanSettingsDropdowns(i, currentBoard.isEXGChannelActive(i));
500+
setHasUnappliedSettings(i, false);
501+
}
497502
}
498503

499504
private class SLCallbackListener implements CallbackListener {

OpenBCI_GUI/BoardCyton.pde

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
249249

250250
private ADS1299Settings currentADS1299Settings;
251251
private boolean[] isCheckingImpedance;
252+
protected boolean[] isCheckingImpedanceN;
253+
protected boolean[] isCheckingImpedanceP;
252254

253255
// same for all channels
254256
private final double brainflowGain = 24.0;
@@ -267,6 +269,11 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
267269
isCheckingImpedance = new boolean[getNumEXGChannels()];
268270
Arrays.fill(isCheckingImpedance, false);
269271

272+
isCheckingImpedanceN= new boolean[getNumEXGChannels()];
273+
isCheckingImpedanceP= new boolean[getNumEXGChannels()];
274+
Arrays.fill(isCheckingImpedanceN, false);
275+
Arrays.fill(isCheckingImpedanceP, false);
276+
270277
// The command 'd' is automatically sent by brainflow on prepare_session
271278
currentADS1299Settings = new CytonDefaultSettings(this);
272279
useDynamicScaler = true;
@@ -416,9 +423,120 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
416423
isCheckingImpedance[channel] = active;
417424
}
418425

426+
//Use this method instead of the one above!
427+
public Pair<Boolean, String> setCheckingImpedanceCyton(final int channel, final boolean active, final boolean _isN) {
428+
429+
char p = '0';
430+
char n = '0';
431+
//Build a command string so we can send 1 command to Cyton instead of 2!
432+
//Hopefully, this lowers the chance of confusing the board with multiple commands sent quickly
433+
StringBuilder fullCommand = new StringBuilder();
434+
435+
//println("CYTON_IMP_CHECK -- Attempting to change channel== " + channel + " || isActive == " + active);
436+
437+
if (active) {
438+
439+
currentADS1299Settings.saveLastValues(channel);
440+
441+
currentADS1299Settings.values.gain[channel] = Gain.X1;
442+
currentADS1299Settings.values.inputType[channel] = InputType.NORMAL;
443+
currentADS1299Settings.values.bias[channel] = Bias.INCLUDE;
444+
currentADS1299Settings.values.srb2[channel] = Srb2.DISCONNECT;
445+
currentADS1299Settings.values.srb1[channel] = Srb1.DISCONNECT;
446+
447+
fullCommand.append(currentADS1299Settings.getValuesString(channel, currentADS1299Settings.values));
448+
449+
if (_isN) {
450+
n = '1';
451+
} else {
452+
p = '1';
453+
}
454+
455+
} else {
456+
//Revert ADS channel settings to what user had before checking impedance on this channel
457+
currentADS1299Settings.revertToLastValues(channel);
458+
fullCommand.append(currentADS1299Settings.getValuesString(channel, currentADS1299Settings.values));
459+
//println("CYTON REVERTING TO PREVIOUS ADS SETTINGS");
460+
}
461+
462+
// Format the impedance command string. Example: z 4 1 0 Z
463+
String impedanceCommandString = String.format("z%c%c%cZ", channelSelectForSettings[channel], p, n);
464+
fullCommand.append(impedanceCommandString);
465+
final String commandToSend = fullCommand.toString();
466+
467+
final Pair<Boolean, String> fullResponse = sendCommand(commandToSend);
468+
boolean response = fullResponse.getKey().booleanValue();
469+
if (!response) {
470+
outputWarn("Cyton Impedance Check - Error sending impedance command to board.");
471+
if (active) {
472+
currentADS1299Settings.revertToLastValues(channel);
473+
return new ImmutablePair<Boolean, String>(false, "Error");
474+
}
475+
}
476+
477+
if (_isN) {
478+
isCheckingImpedanceN[channel] = active;
479+
} else {
480+
isCheckingImpedanceP[channel] = active;
481+
}
482+
483+
return fullResponse;
484+
}
485+
419486
@Override
487+
//General check that is a method for all impedance boards
420488
public boolean isCheckingImpedance(int channel) {
421-
return isCheckingImpedance[channel];
489+
return isCheckingImpedanceN[channel] || isCheckingImpedanceP[channel];
490+
}
491+
492+
//Specifically check the status of N or P pins
493+
public boolean isCheckingImpedanceNorP(int channel, boolean _isN) {
494+
if (_isN) {
495+
return isCheckingImpedanceN[channel];
496+
}
497+
return isCheckingImpedanceP[channel];
498+
}
499+
500+
//Returns <pin, channel> if found
501+
//Return <null,null> if not checking on any channels
502+
public Pair<Boolean, Integer> isCheckingImpedanceOnAnyChannelsNorP() {
503+
Boolean is_n_pin = true;
504+
for (int i = 0; i < isCheckingImpedanceN.length; i++) {
505+
if (isCheckingImpedanceN[i]) {
506+
return new ImmutablePair<Boolean, Integer>(is_n_pin, Integer.valueOf(i));
507+
}
508+
if (isCheckingImpedanceP[i]) {
509+
is_n_pin = false;
510+
return new ImmutablePair<Boolean, Integer>(is_n_pin, Integer.valueOf(i));
511+
}
512+
}
513+
return new ImmutablePair<Boolean, Integer>(null, null);
514+
}
515+
516+
//Returns the channel number where impedance check is currently active, otherwise return null
517+
//Less detailed than the previous method
518+
@Override
519+
public Integer isCheckingImpedanceOnChannel() {
520+
//printArray(isCheckingImpedance);
521+
for (int i = 0; i < isCheckingImpedance.length; i++) {
522+
if (isCheckingImpedance(i)) {
523+
return i;
524+
}
525+
}
526+
return null;
527+
}
528+
529+
public void forceStopImpedanceFrontEnd(Integer channel, Boolean _isN) {
530+
if (channel == null || _isN == null) {
531+
outputError("OOPS! Are you sure you know what you are doing with this method? Please pass non-null values.");
532+
return;
533+
}
534+
535+
if (_isN) {
536+
isCheckingImpedanceN[channel] = false;
537+
} else {
538+
isCheckingImpedanceP[channel] = false;
539+
}
422540
}
423541

424542
@Override

OpenBCI_GUI/BoardGalea.pde

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ implements ImpedanceSettingsBoard, EDACapableBoard, PPGCapableBoard, BatteryInfo
270270
return isCheckingImpedance[channel];
271271
}
272272

273+
//Returns the channel number where impedance check is currently active, otherwise return null
274+
@Override
275+
public Integer isCheckingImpedanceOnChannel() {
276+
for (int i = 0; i < isCheckingImpedance.length; i++) {
277+
if (isCheckingImpedance[i]) {
278+
return i;
279+
}
280+
}
281+
return null;
282+
}
283+
273284
@Override
274285
protected double[][] getNewDataInternal() {
275286
double[][] data = super.getNewDataInternal();

0 commit comments

Comments
 (0)