Skip to content

Commit

Permalink
Merge pull request #61 from aj-ptw/dev-3.0.0
Browse files Browse the repository at this point in the history
Dev 3.0.0
  • Loading branch information
AJ Keller authored Jul 13, 2017
2 parents 8c9fc27 + d93670a commit f1becf3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
60 changes: 24 additions & 36 deletions OpenBCI_32bit_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,24 +670,15 @@ void OpenBCI_32bit_Library::setBoardMode(uint8_t newBoardMode) {
curAccelMode = ACCEL_MODE_OFF;
pinMode(11, INPUT);
pinMode(12, INPUT);
#ifdef USE_WIFI
if (!wifi.present) pinMode(13, INPUT);
#else
pinMode(13, INPUT);
#endif
break;
case BOARD_MODE_DIGITAL:
curAccelMode = ACCEL_MODE_OFF;
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(17, INPUT);
// #if USE_WIFI
if (!wifi.present) pinMode(13, INPUT);
if (!wifi.present) pinMode(18, INPUT);
// #else
// pinMode(13, INPUT);
// pinMode(18, INPUT);
// #endif
break;
case BOARD_MODE_DEBUG:
curAccelMode = ACCEL_MODE_ON;
Expand Down Expand Up @@ -1050,14 +1041,14 @@ void OpenBCI_32bit_Library::sendChannelData() {
* Adds stop byte `OPENBCI_EOP_STND_ACCEL`. See `OpenBCI_32bit_Library_Definitions.h`
*/
void OpenBCI_32bit_Library::sendChannelData(PACKET_TYPE packetType) {
if (wifi.tx) {
if (wifi.present && wifi.tx) {
sendChannelDataWifi(packetType, false);
if (daisyPresent) sendChannelDataWifi(packetType, true);
} else {
// Send over bluetooth
if (iSerial0.tx || iSerial1.tx) sendChannelDataSerial(packetType);
}

// Send over bluetooth
if (iSerial0.tx || iSerial1.tx) sendChannelDataSerial(packetType);

if (packetType == PACKET_TYPE_ACCEL) LIS3DH_zeroAxisData();
if (packetType == PACKET_TYPE_RAW_AUX || packetType == PACKET_TYPE_RAW_AUX_TIME_SYNC) zeroAuxData();

Expand Down Expand Up @@ -1567,19 +1558,27 @@ void OpenBCI_32bit_Library::streamSafeSetAllChannelsToDefault(void) {
}
}

/**
* Return an array of gains in coded ADS form i.e. 0-6 where 6 is x24 and so on.
* @return [description]
*/
uint8_t *OpenBCI_32bit_Library::getGains(void) {
uint8_t gains[numChannels];
for (uint8_t i = 0; i < numChannels; i++) {
gains[i] = channelSettings[i][GAIN_SET];
}
return gains;
}

/**
* @description Call this to start the streaming data from the ADS1299
* @returns boolean if able to start streaming
*/
void OpenBCI_32bit_Library::streamStart(){ // needs daisy functionality

if (wifi.tx) {
uint8_t gains[numChannels];
for (uint8_t i = 0; i < numChannels; i++) {
gains[i] = channelSettings[i][GAIN_SET];
}
if (wifi.present && wifi.tx) {
// TODO: Remove this debug line
wifi.sendGains(numChannels, gains);
wifi.sendGains(numChannels, getGains());
}
streaming = true;
startADS();
Expand Down Expand Up @@ -2440,23 +2439,14 @@ void OpenBCI_32bit_Library::updateChannelData(){
case BOARD_MODE_ANALOG:
auxData[0] = analogRead(A5);
auxData[1] = analogRead(A6);
#ifdef USE_WIFI
if (!wifi.present) {
auxData[2] = analogRead(A7);
}
#else
auxData[2] = analogRead(A7);
#endif
break;
case BOARD_MODE_DIGITAL:
auxData[0] = digitalRead(11) << 8 | digitalRead(12);
#ifdef USE_WIFI
auxData[1] = (wifi.present ? 0 : digitalRead(13) << 8) | digitalRead(17);
auxData[2] = wifi.present ? 0 : digitalRead(18);
#else
auxData[1] = (digitalRead(13) << 8) | digitalRead(17);
auxData[2] = digitalRead(18);
#endif
break;
case BOARD_MODE_DEBUG:
case BOARD_MODE_DEFAULT:
Expand Down Expand Up @@ -2667,9 +2657,7 @@ void OpenBCI_32bit_Library::printlnSerial(const char *c) {
}

void OpenBCI_32bit_Library::write(uint8_t b) {
#ifdef USE_WIFI
wifi.storeByteBufTx(b);
#endif
writeSerial(b);
}

Expand Down Expand Up @@ -3181,16 +3169,16 @@ void OpenBCI_32bit_Library::printSuccess() {

void OpenBCI_32bit_Library::printAll(const char *arr) {
printSerial(arr);
// #ifdef USE_WIFI
wifi.sendStringMulti(arr);
// #endif
if (wifi.present && wifi.tx) {
wifi.sendStringMulti(arr);
}
}

void OpenBCI_32bit_Library::printlnAll(const char *arr) {
printlnSerial(arr);
// #ifdef USE_WIFI
wifi.sendStringLast(arr);
// #endif
if (wifi.present && wifi.tx) {
wifi.sendStringLast(arr);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions OpenBCI_32bit_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class OpenBCI_32bit_Library {
byte getDefaultChannelSettingForSetting(byte);
char getDefaultChannelSettingForSettingAscii(byte);
char getGainForAsciiChar(char);
uint8_t * getGains(void);
char getNumberForAsciiChar(char);
const char* getSampleRate(void);
char getTargetSSForConstrainedChannelNumber(byte);
Expand Down
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
* Removed public `timeSynced` and private `sendTimeSyncUpPacket`
* Setting internal test signal now, when not streaming, returns a success message, with EOT `$$$`

## Beta5

### New Features

* Send gains after connecting to Wifi shield

### Breaking Changes

* Don't send streaming data over bluetooth when wifi is present and attached

## Beta4

The overall goal was to clean the wifi code out of the library so it would not be needed when you are building a bare board.
Expand Down
6 changes: 6 additions & 0 deletions examples/BoardWithWifi/BoardWithWifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ void loop() {
// Send to the board library
board.processChar(newChar);
}

if (!wifi.sentGains) {
if(wifi.present && wifi.tx) {
wifi.sendGains(board.numChannels, board.getGains());
}
}
}
12 changes: 9 additions & 3 deletions examples/DefaultBoard/DefaultBoard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ void loop() {
}
}

// Call to wifi loop
wifi.loop();

// Check serial 0 for new data
if (board.hasDataSerial0()) {
// Read one char from the serial 0 port
Expand All @@ -74,6 +71,9 @@ void loop() {
board.processChar(newChar);
}

// Call to wifi loop
wifi.loop();

if (wifi.hasData()) {
// Read one char from the wifi shield
char newChar = wifi.getChar();
Expand All @@ -84,4 +84,10 @@ void loop() {
// Send to the board library
board.processChar(newChar);
}

if (!wifi.sentGains) {
if(wifi.present && wifi.tx) {
wifi.sendGains(board.numChannels, board.getGains());
}
}
}
2 changes: 1 addition & 1 deletion libraries.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OpenBCI_32bit_Library
version=3.0.0-beta4
version=3.0.0
author=Joel Murphy <[email protected]>, Conor Russomanno <[email protected]>, Leif Percifield <[email protected]>, AJ Keller <[email protected]>
maintainers=Joel Murphy <[email protected]>, AJ Keller <[email protected]>
sentence=The library for controlling OpenBCI 32bit boards. The Cyton is the main one.
Expand Down

0 comments on commit f1becf3

Please sign in to comment.