Skip to content

Commit dc75e1e

Browse files
author
AJ Keller
authored
Merge pull request #66 from aj-ptw/dev-3.0.0
ADD: msg to wifi when stopping and starting streaming
2 parents 1c81e73 + a6f77e9 commit dc75e1e

File tree

4 files changed

+91
-50
lines changed

4 files changed

+91
-50
lines changed

OpenBCI_32bit_Library.cpp

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ boolean OpenBCI_32bit_Library::isProcessingMultibyteMsg(void) {
147147
* @return {boolean} - `true` if the command was recognized, `false` if not
148148
*/
149149
boolean OpenBCI_32bit_Library::processChar(char character) {
150-
// Serial0.print("pC: "); Serial0.print(character); Serial0.print(" 0x"); Serial0.println(character, HEX);
151150
if (curBoardMode == BOARD_MODE_DEBUG) {
152151
Serial1.print("pC: "); Serial1.println(character);
153152
}
@@ -331,14 +330,19 @@ boolean OpenBCI_32bit_Library::processChar(char character) {
331330
if(curAccelMode == ACCEL_MODE_ON){
332331
enable_accel(RATE_25HZ);
333332
} // fire up the accelerometer if you want it
334-
// Serial0.println("streamStart - pc");
333+
if (wifi.present && wifi.tx) {
334+
wifi.sendStringLast("Stream started");
335+
}
335336
streamStart(); // turn on the fire hose
336337
break;
337338
case OPENBCI_STREAM_STOP: // stop streaming data
338339
if(curAccelMode == ACCEL_MODE_ON){
339340
disable_accel();
340341
} // shut down the accelerometer if you're using it
341342
streamStop();
343+
if (wifi.present && wifi.tx) {
344+
wifi.sendStringLast("Stream stopped");
345+
}
342346
break;
343347

344348
// INITIALIZE AND VERIFY
@@ -355,8 +359,8 @@ boolean OpenBCI_32bit_Library::processChar(char character) {
355359
// TIME SYNC
356360
case OPENBCI_TIME_SET:
357361
// Set flag to send time packet
358-
if (!streaming && iSerial0.tx) {
359-
Serial0.print("Time stamp ON");
362+
if (!streaming) {
363+
printAll("Time stamp ON");
360364
sendEOT();
361365
}
362366
curTimeSyncMode = TIME_SYNC_MODE_ON;
@@ -366,7 +370,7 @@ boolean OpenBCI_32bit_Library::processChar(char character) {
366370
case OPENBCI_TIME_STOP:
367371
// Stop the Sync
368372
if (!streaming) {
369-
Serial0.print("Time stamp OFF");
373+
printAll("Time stamp OFF");
370374
sendEOT();
371375
}
372376
curTimeSyncMode = TIME_SYNC_MODE_OFF;
@@ -589,13 +593,13 @@ void OpenBCI_32bit_Library::boardReset(void) {
589593
initialize(); // initalizes accelerometer and on-board ADS and on-daisy ADS if present
590594
delay(500);
591595
configureLeadOffDetection(LOFF_MAG_6NA, LOFF_FREQ_31p2HZ);
592-
Serial0.println("OpenBCI V3 8-16 channel");
593-
Serial0.print("On Board ADS1299 Device ID: 0x"); Serial0.println(ADS_getDeviceID(ON_BOARD),HEX);
596+
printlnAll("OpenBCI V3 8-16 channel");
597+
printAll("On Board ADS1299 Device ID: 0x"); printlnHex(ADS_getDeviceID(ON_BOARD));
594598
if(daisyPresent){ // library will set this in initialize() if daisy present and functional
595-
Serial0.print("On Daisy ADS1299 Device ID: 0x"); Serial0.println(ADS_getDeviceID(ON_DAISY),HEX);
599+
printAll("On Daisy ADS1299 Device ID: 0x"); printlnHex(ADS_getDeviceID(ON_DAISY));
596600
}
597-
Serial0.print("LIS3DH Device ID: 0x"); Serial0.println(LIS3DH_getDeviceID(),HEX);
598-
Serial0.println("Firmware: v3.0.0");
601+
printAll("LIS3DH Device ID: 0x"); printlnHex(LIS3DH_getDeviceID());
602+
printlnAll("Firmware: v3.0.0");
599603
sendEOT();
600604
delay(5);
601605
wifi.reset();
@@ -1019,13 +1023,13 @@ void OpenBCI_32bit_Library::setSerialInfo(SerialInfo si, boolean rx, boolean tx,
10191023

10201024
void OpenBCI_32bit_Library::printAllRegisters(){
10211025
if(!isRunning){
1022-
Serial0.println("\nBoard ADS Registers");
1026+
printlnAll("\nBoard ADS Registers");
10231027
printADSregisters(BOARD_ADS);
10241028
if(daisyPresent){
1025-
Serial0.println("\nDaisy ADS Registers");
1029+
printlnAll("\nDaisy ADS Registers");
10261030
printADSregisters(DAISY_ADS);
10271031
}
1028-
Serial0.println("\nLIS3DH Registers");
1032+
printlnAll("\nLIS3DH Registers");
10291033
LIS3DH_readAllRegs();
10301034
sendEOT();
10311035
}
@@ -1606,7 +1610,7 @@ void OpenBCI_32bit_Library::streamStop(){
16061610
boolean OpenBCI_32bit_Library::smellDaisy(void){ // check if daisy present
16071611
boolean isDaisy = false;
16081612
byte setting = RREG(ID_REG,DAISY_ADS); // try to read the daisy product ID
1609-
if(verbosity){Serial0.print("Daisy ID 0x"); Serial0.println(setting,HEX); sendEOT();}
1613+
if(verbosity){printAll("Daisy ID 0x"); printlnHex(setting); sendEOT();}
16101614
if(setting == ADS_ID) {isDaisy = true;} // should read as 0x3E
16111615
return isDaisy;
16121616
}
@@ -2736,17 +2740,17 @@ void OpenBCI_32bit_Library::printADSregisters(int targetSS)
27362740
{
27372741
boolean prevverbosityState = verbosity;
27382742
verbosity = true; // set up for verbosity output
2739-
RREGS(0x00,0x0C,targetSS); // read out the first registers
2743+
RREGS(0x00, 0x0C, targetSS); // read out the first registers
27402744
delay(10); // stall to let all that data get read by the PC
2741-
RREGS(0x0D,0x17-0x0D,targetSS); // read out the rest
2745+
RREGS(0x0D, 0x17-0x0D, targetSS); // read out the rest
27422746
verbosity = prevverbosityState;
27432747
}
27442748

27452749
byte OpenBCI_32bit_Library::ADS_getDeviceID(int targetSS) { // simple hello world com check
27462750
byte data = RREG(ID_REG,targetSS);
27472751
if(verbosity){ // verbosity otuput
2748-
Serial0.print("On Board ADS ID ");
2749-
printHex(data); Serial0.println();
2752+
printAll("On Board ADS ID ");
2753+
printHex(data); printlnAll();
27502754
sendEOT();
27512755
}
27522756
return data;
@@ -2852,15 +2856,16 @@ byte OpenBCI_32bit_Library::RREG(byte _address,int targetSS) { // reads ONE
28522856
if (verbosity){ // verbosity output
28532857
printRegisterName(_address);
28542858
printHex(_address);
2855-
Serial0.print(", ");
2859+
printAll(", ");
28562860
printHex(regData[_address]);
2857-
Serial0.print(", ");
2861+
printAll(", ");
28582862
for(byte j = 0; j<8; j++){
2859-
Serial0.print(bitRead(regData[_address], 7-j));
2860-
if(j!=7) Serial0.print(", ");
2863+
char buf[3];
2864+
printAll(itoa(bitRead(regData[_address], 7-j), buf, DEC));
2865+
if(j!=7) printAll(", ");
28612866
}
28622867

2863-
Serial0.println();
2868+
printlnAll();
28642869
}
28652870
return regData[_address]; // return requested register value
28662871
}
@@ -2881,14 +2886,15 @@ void OpenBCI_32bit_Library::RREGS(byte _address, byte _numRegistersMinusOne, int
28812886
for(int i = 0; i<= _numRegistersMinusOne; i++){
28822887
printRegisterName(_address + i);
28832888
printHex(_address + i);
2884-
Serial0.print(", ");
2889+
printAll(", ");
28852890
printHex(regData[_address + i]);
2886-
Serial0.print(", ");
2891+
printAll(", ");
28872892
for(int j = 0; j<8; j++){
2888-
Serial0.print(bitRead(regData[_address + i], 7-j));
2889-
if(j!=7) Serial0.print(", ");
2893+
char buf[3];
2894+
printAll(itoa(bitRead(regData[_address + i], 7-j), buf, DEC));
2895+
if(j!=7) printAll(", ");
28902896
}
2891-
Serial0.println();
2897+
printlnAll();
28922898
delay(30);
28932899
}
28942900
}
@@ -2903,9 +2909,9 @@ void OpenBCI_32bit_Library::WREG(byte _address, byte _value, int target_SS) { //
29032909
csHigh(target_SS); // close SPI
29042910
regData[_address] = _value; // update the mirror array
29052911
if(verbosity){ // verbosity output
2906-
Serial0.print("Register ");
2912+
printAll("Register ");
29072913
printHex(_address);
2908-
Serial0.println(" modified.");
2914+
printlnAll(" modified.");
29092915
sendEOT();
29102916
}
29112917
}
@@ -2920,10 +2926,10 @@ void OpenBCI_32bit_Library::WREGS(byte _address, byte _numRegistersMinusOne, int
29202926
}
29212927
csHigh(targetSS);
29222928
if(verbosity){
2923-
Serial0.print("Registers ");
2924-
printHex(_address); Serial0.print(" to ");
2929+
printAll("Registers ");
2930+
printHex(_address); printAll(" to ");
29252931
printHex(_address + _numRegistersMinusOne);
2926-
Serial0.println(" modified");
2932+
printlnAll(" modified");
29272933
sendEOT();
29282934
}
29292935
}
@@ -3066,25 +3072,25 @@ void OpenBCI_32bit_Library::LIS3DH_readAllRegs(){
30663072

30673073
for (int i = STATUS_REG_AUX; i <= WHO_AM_I; i++){
30683074
inByte = LIS3DH_read(i);
3069-
Serial0.print("0x0");Serial0.print(i,HEX);
3070-
Serial0.print("\t");Serial0.println(inByte,HEX);
3075+
printAll("0x"); printHex(i);
3076+
printAll(" "); printlnHex(inByte);
30713077
delay(20);
30723078
}
3073-
Serial0.println();
3079+
printlnAll();
30743080

30753081
for (int i = TMP_CFG_REG; i <= INT1_DURATION; i++){
30763082
inByte = LIS3DH_read(i);
30773083
// printRegisterName(i);
3078-
Serial0.print("0x");Serial0.print(i,HEX);
3079-
Serial0.print("\t");Serial0.println(inByte,HEX);
3084+
printAll("0x"); printHex(i);
3085+
printAll(" "); printlnHex(inByte);
30803086
delay(20);
30813087
}
3082-
Serial0.println();
3088+
printlnAll();
30833089

30843090
for (int i = CLICK_CFG; i <= TIME_WINDOW; i++){
30853091
inByte = LIS3DH_read(i);
3086-
Serial0.print("0x");Serial0.print(i,HEX);
3087-
Serial0.print("\t");Serial0.println(inByte,HEX);
3092+
printAll("0x"); printHex(i);
3093+
printAll(" "); printlnHex(inByte);
30883094
delay(20);
30893095
}
30903096

@@ -3154,9 +3160,15 @@ void OpenBCI_32bit_Library::printRegisterName(byte _address) {
31543160

31553161
// Used for printing HEX in verbosity feedback mode
31563162
void OpenBCI_32bit_Library::printHex(byte _data){
3157-
Serial0.print("0x");
3158-
if(_data < 0x10) Serial0.print("0");
3159-
Serial0.print(_data, HEX);
3163+
if(_data < 0x10) printAll("0");
3164+
char buf[4];
3165+
// Serial.print(_data);
3166+
printAll(itoa(_data, buf, HEX));
3167+
}
3168+
3169+
void OpenBCI_32bit_Library::printlnHex(byte _data){
3170+
printHex(_data);
3171+
printlnAll();
31603172
}
31613173

31623174
void OpenBCI_32bit_Library::printFailure() {
@@ -3167,6 +3179,13 @@ void OpenBCI_32bit_Library::printSuccess() {
31673179
printAll("Success: ");
31683180
}
31693181

3182+
void OpenBCI_32bit_Library::printAll(char c) {
3183+
printSerial(c);
3184+
if (wifi.present && wifi.tx) {
3185+
wifi.sendStringMulti(c);
3186+
}
3187+
}
3188+
31703189
void OpenBCI_32bit_Library::printAll(const char *arr) {
31713190
printSerial(arr);
31723191
if (wifi.present && wifi.tx) {
@@ -3177,7 +3196,15 @@ void OpenBCI_32bit_Library::printAll(const char *arr) {
31773196
void OpenBCI_32bit_Library::printlnAll(const char *arr) {
31783197
printlnSerial(arr);
31793198
if (wifi.present && wifi.tx) {
3180-
wifi.sendStringLast(arr);
3199+
wifi.sendStringMulti(arr);
3200+
wifi.sendStringMulti("\n");
3201+
}
3202+
}
3203+
3204+
void OpenBCI_32bit_Library::printlnAll(void) {
3205+
printlnSerial();
3206+
if (wifi.present && wifi.tx) {
3207+
wifi.sendStringMulti("\n");
31813208
}
31823209
}
31833210

@@ -3235,10 +3262,10 @@ char OpenBCI_32bit_Library::getChannelCommandForAsciiChar(char asciiChar) {
32353262
char OpenBCI_32bit_Library::getYesOrNoForAsciiChar(char asciiChar) {
32363263
switch (asciiChar) {
32373264
case '1':
3238-
return ACTIVATE;
3265+
return ACTIVATE;
32393266
case '0':
32403267
default:
3241-
return DEACTIVATE;
3268+
return DEACTIVATE;
32423269
}
32433270
}
32443271

OpenBCI_32bit_Library.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ class OpenBCI_32bit_Library {
118118
void leadOffSetForChannel(byte, byte, byte);
119119
void ledFlash(int);
120120
void loop(void);
121-
void printAll(const char *arr);
122-
void printlnAll(const char *arr);
121+
void printAll(char);
122+
void printAll(const char *);
123+
void printlnAll(void);
124+
void printlnAll(const char *);
123125
void printlnSerial(void);
124126
void printlnSerial(char);
125127
void printlnSerial(int);
@@ -265,6 +267,7 @@ class OpenBCI_32bit_Library {
265267
void printAllRegisters(void);
266268
void printFailure();
267269
void printHex(byte);
270+
void printlnHex(byte);
268271
void printRegisterName(byte);
269272
void printSuccess();
270273
void RDATA(int); // read data one-shot

changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
* Removed public `timeSynced` and private `sendTimeSyncUpPacket`
4848
* Setting internal test signal now, when not streaming, returns a success message, with EOT `$$$`
4949

50+
## Release Candidate 4
51+
52+
### Enhancements
53+
54+
* Can now send long messages to Wifi shield which will allow for the GUI to understand the the channel settings for each channel on the Cyton. Required changing a ton of `Serial0.print` to `printAll` and `Serial0.println` to `printlnAll`.
55+
* Send response when stopping and starting streaming to wifi shield if present, will not send to Serial ever.
56+
57+
## Release Candidate 3
58+
59+
Fix the library.properties file again...
60+
5061
## Release Candidate 2
5162

5263
Had to fix the library.properties file

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=OpenBCI_32bit_Library
2-
version=3.0.0-rc3
2+
version=3.0.0-rc4
33
author=Joel Murphy <[email protected]>, Conor Russomanno <[email protected]>, Leif Percifield <[email protected]>, AJ Keller <[email protected]>
44
maintainer=Joel Murphy <[email protected]>, AJ Keller <[email protected]>
55
sentence=The library for controlling OpenBCI Cyton (32bit) boards. The Cyton is the main one.

0 commit comments

Comments
 (0)