diff --git a/OpenBCI_32bit_Library.cpp b/OpenBCI_32bit_Library.cpp index c420a87..d84df3a 100644 --- a/OpenBCI_32bit_Library.cpp +++ b/OpenBCI_32bit_Library.cpp @@ -277,12 +277,12 @@ boolean OpenBCI_32bit_Library::processChar(char character) { // DAISY MODULE COMMANDS - case 'c': // use 8 channel mode + case OPENBCI_CHANNEL_MAX_NUMBER_8: // use 8 channel mode if(daisyPresent){ removeDaisy(); } break; - case 'C': // use 16 channel mode + case OPENBCI_CHANNEL_MAX_NUMBER_16: // use 16 channel mode if(daisyPresent == false){ attachDaisy(); } @@ -323,7 +323,9 @@ boolean OpenBCI_32bit_Library::processChar(char character) { // TIME SYNC case OPENBCI_TIME_SET: - // Send time Packet + // Set flag to send time packet + sendTimeSyncUpPacket = true; + timeSynced = true; streamSafeTimeSendSyncSetPacket(); break; @@ -676,6 +678,7 @@ void OpenBCI_32bit_Library::initialize(){ void OpenBCI_32bit_Library::initializeVariables(void) { streaming = false; + sendTimeSyncUpPacket = false; timeSynced = false; isProcessingIncomingSettingsChannel = false; isProcessingIncomingSettingsLeadOff = false; @@ -761,7 +764,12 @@ void OpenBCI_32bit_Library::sendChannelDataWithTimeAndAccel(void) { writeTimeCurrent(); // 4 bytes - Serial0.write(OPENBCI_EOP_TIME_SYNCED_ACCEL); // 0xC4 + if (sendTimeSyncUpPacket) { + sendTimeSyncUpPacket = false; + Serial0.write(OPENBCI_EOP_ACCEL_TIME_SET); // 0xC3 + } else { + Serial0.write(OPENBCI_EOP_ACCEL_TIME_SYNCED); // 0xC4 + } sampleCounter++; } @@ -779,7 +787,12 @@ void OpenBCI_32bit_Library::sendChannelDataWithTimeAndRawAux(void) { writeTimeCurrent(); // 4 bytes - Serial0.write(OPENBCI_EOP_TIME_SYNCED_RAW_AUX); // 0xF5 + if (sendTimeSyncUpPacket) { + sendTimeSyncUpPacket = false; + Serial0.write(OPENBCI_EOP_RAW_AUX_TIME_SET); // 0xC5 + } else { + Serial0.write(OPENBCI_EOP_RAW_AUX_TIME_SYNCED); // 0xC6 + } sampleCounter++; diff --git a/OpenBCI_32bit_Library.h b/OpenBCI_32bit_Library.h index af3029e..4a4b3d7 100644 --- a/OpenBCI_32bit_Library.h +++ b/OpenBCI_32bit_Library.h @@ -82,6 +82,7 @@ class OpenBCI_32bit_Library { boolean sniffMode; boolean streaming; boolean timeSynced; + boolean sendTimeSyncUpPacket; boolean isProcessingIncomingSettingsChannel; boolean isProcessingIncomingSettingsLeadOff; // boolean isProcessingIncomingTime; diff --git a/OpenBCI_32bit_Library_Definitions.h b/OpenBCI_32bit_Library_Definitions.h index 595c72f..db7b387 100644 --- a/OpenBCI_32bit_Library_Definitions.h +++ b/OpenBCI_32bit_Library_Definitions.h @@ -18,9 +18,10 @@ #define OPENBCI_EOP_STND_ACCEL 0xC0 // End of standard stream packet #define OPENBCI_EOP_STND_RAW_AUX 0xC1 // End of stream packet with raw packet #define OPENBCI_EOP_USER_DEFINED 0xC2 // End of stream packet, user defined -#define OPENBCI_EOP_TIME_SET 0xC3 // End of time set stream packet -#define OPENBCI_EOP_TIME_SYNCED_ACCEL 0xC4 // End of time syned stream packet -#define OPENBCI_EOP_TIME_SYNCED_RAW_AUX 0xC5 // End of time syned stream packet +#define OPENBCI_EOP_ACCEL_TIME_SET 0xC3 // End of time sync up with accel stream packet +#define OPENBCI_EOP_ACCEL_TIME_SYNCED 0xC4 // End of time syned stream packet +#define OPENBCI_EOP_RAW_AUX_TIME_SET 0xC5 // End of time sync up stream packet +#define OPENBCI_EOP_RAW_AUX_TIME_SYNCED 0xC6 // End of time syned stream packet //PIN CONNECTIONS #define ADS_DRDY 9 // ADS data ready pin diff --git a/examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino b/examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino index 6428404..a72444d 100644 --- a/examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino +++ b/examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino @@ -12,27 +12,32 @@ void setup() { void loop() { - // The main dependency of this single threaded microcontroller is to - // stream data from the ADS. - if (board.streaming) { - // Wait for the ADS to signal it's ready with new data - while (board.waitForNewChannelData()) {} - - // Read from the ADS(s) and store data into - board.updateChannelData(); - - // Read from the analog sensor and store auxiliary position 0 - // take a reading from the ADC. Result range from 0 to 1023 - board.auxData[0] = analogRead(A7); - - // Send standard packet with channel data and accel data - // includes aux data because we set `useAux` in setup() - board.sendChannelData(); - } - - // Check the serial port for new data - if (board.isSerialAvailableForRead()) { + // The main dependency of this single threaded microcontroller is to + // stream data from the ADS. + if (board.streaming) { + // Wait for the ADS to signal it's ready with new data + while (board.waitForNewChannelData()) {} + + // Read from the ADS(s) and store data into + board.updateChannelData(); + + // Read from the analog sensor and store auxiliary position 0 + // take a reading from the ADC. Result range from 0 to 1023 + board.auxData[0] = analogRead(A7); + + // Send standard packet with channel data and accel data + // includes aux data because we set `useAux` in setup() + if (board.timeSynced) { + board.sendChannelDataWithTimeAndRawAux(); + } else { + // Send standard packet with channel data + board.sendChannelDataWithRawAux(); + } + } + + // Check the serial port for new data + if (board.isSerialAvailableForRead()) { // Read one char and process it board.processChar(board.readOneSerialChar()); - } + } } diff --git a/examples/BoardWithDigitalRead/BoardWithDigitalRead.ino b/examples/BoardWithDigitalRead/BoardWithDigitalRead.ino new file mode 100644 index 0000000..aaf9e4c --- /dev/null +++ b/examples/BoardWithDigitalRead/BoardWithDigitalRead.ino @@ -0,0 +1,46 @@ +#include +#include +#include + +void setup() { + // Bring up the OpenBCI Board + board.begin(); + + // Notify the board we want to use aux data, this effects `::sendChannelData()` + board.useAux = true; + + // Set pin to input A0-A5 can be digital input + pinMode(17, INPUT); +} + +void loop() { + + // The main dependency of this single threaded microcontroller is to + // stream data from the ADS. + if (board.streaming) { + // Wait for the ADS to signal it's ready with new data + while (board.waitForNewChannelData()) {} + + // Read from the ADS(s) and store data into + board.updateChannelData(); + + // Read from the analog sensor and store auxiliary position 0 + // take a reading from the ADC. Result range from 0 to 1023 + board.auxData[0] = digitalRead(17); + + // Send standard packet with channel data and accel data + // includes aux data because we set `useAux` in setup() + if (board.timeSynced) { + board.sendChannelDataWithTimeAndRawAux(); + } else { + // Send standard packet with channel data + board.sendChannelDataWithRawAux(); + } + } + + // Check the serial port for new data + if (board.isSerialAvailableForRead()) { + // Read one char and process it + board.processChar(board.readOneSerialChar()); + } +}