Skip to content

Commit

Permalink
Merge pull request #9 from pushtheworldllc/dev-time-sync
Browse files Browse the repository at this point in the history
Dev time sync
  • Loading branch information
AJ Keller authored Jul 14, 2016
2 parents e56d1f9 + f0c5564 commit 685f97f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 29 deletions.
23 changes: 18 additions & 5 deletions OpenBCI_32bit_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
Expand All @@ -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++;

Expand Down
1 change: 1 addition & 0 deletions OpenBCI_32bit_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class OpenBCI_32bit_Library {
boolean sniffMode;
boolean streaming;
boolean timeSynced;
boolean sendTimeSyncUpPacket;
boolean isProcessingIncomingSettingsChannel;
boolean isProcessingIncomingSettingsLeadOff;
// boolean isProcessingIncomingTime;
Expand Down
7 changes: 4 additions & 3 deletions OpenBCI_32bit_Library_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 26 additions & 21 deletions examples/BoardWithAnalogSensor/BoardWithAnalogSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
46 changes: 46 additions & 0 deletions examples/BoardWithDigitalRead/BoardWithDigitalRead.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <DSPI.h>
#include <OpenBCI_32bit_Library.h>
#include <OpenBCI_32Bit_Library_Definitions.h>

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());
}
}

0 comments on commit 685f97f

Please sign in to comment.