@@ -249,6 +249,8 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
249
249
250
250
private ADS1299Settings currentADS1299Settings;
251
251
private boolean [] isCheckingImpedance;
252
+ protected boolean [] isCheckingImpedanceN;
253
+ protected boolean [] isCheckingImpedanceP;
252
254
253
255
// same for all channels
254
256
private final double brainflowGain = 24.0 ;
@@ -267,6 +269,11 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
267
269
isCheckingImpedance = new boolean [getNumEXGChannels()];
268
270
Arrays . fill(isCheckingImpedance, false );
269
271
272
+ isCheckingImpedanceN= new boolean [getNumEXGChannels()];
273
+ isCheckingImpedanceP= new boolean [getNumEXGChannels()];
274
+ Arrays . fill(isCheckingImpedanceN, false );
275
+ Arrays . fill(isCheckingImpedanceP, false );
276
+
270
277
// The command 'd' is automatically sent by brainflow on prepare_session
271
278
currentADS1299Settings = new CytonDefaultSettings (this );
272
279
useDynamicScaler = true ;
@@ -416,9 +423,120 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
416
423
isCheckingImpedance[channel] = active;
417
424
}
418
425
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
+
419
486
@Override
487
+ // General check that is a method for all impedance boards
420
488
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
+ }
422
540
}
423
541
424
542
@Override
0 commit comments