Skip to content

Commit

Permalink
Merge pull request #6 from aj-ptw/development
Browse files Browse the repository at this point in the history
Update sample rate functions
  • Loading branch information
AJ Keller authored Jul 16, 2017
2 parents 0c0eb16 + b5bfe33 commit 00c1d1c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
82 changes: 48 additions & 34 deletions OpenBCI_Ganglion_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,20 @@ void OpenBCI_Ganglion::loadlnString(void) {
loadlnString("");
}

void OpenBCI_Ganglion::printFailure() {
loadString("Failure: ");
}

void OpenBCI_Ganglion::printSuccess() {
loadString("Success: ");
}

void OpenBCI_Ganglion::printSampleRate() {
loadString("Sample rate is ");
loadString(getSampleRate());
loadlnString("Hz");
}

void OpenBCI_Ganglion::loadChar(char thatChar, boolean addNewLine) {
// const char* temp[1];
// temp[0] = (const char *)thatChar;
Expand Down Expand Up @@ -1195,17 +1209,21 @@ void OpenBCI_Ganglion::parseChar(char token) {
break;
case OPENBCI_WIFI_ATTACH:
if (wifi.attach()) {
loadlnString("Success: Wifi attached");
printSuccess();
loadlnString("Wifi attached");
} else {
loadlnString("Failure: Wifi not attached");
printFailure();
loadlnString("Wifi not attached");
}
prepToSendBytes();
break;
case OPENBCI_WIFI_REMOVE:
if (wifi.remove()) {
loadlnString("Success: Wifi removed");
printSuccess();
loadlnString("Wifi removed");
} else {
loadlnString("Failure: Wifi not removed");
printFailure();
loadlnString("Wifi not removed");
}
prepToSendBytes();
break;
Expand Down Expand Up @@ -1268,67 +1286,63 @@ void SimbleeBLE_onReceive(char *data, int len) {

// <<<<<<<<<<<<<<<<<<<<<<<<< END OF SIMBLEE FUNCTIONS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

void OpenBCI_Ganglion::setSampleRate(uint8_t newSampleRateCode) {
curSampleRate = (SAMPLE_RATE)newSampleRateCode;
config_MCP3912(gain);
}

void OpenBCI_Ganglion::processIncomingSampleRate(char c) {
if (c == OPENBCI_SAMPLE_RATE_SET) {
// printSuccess();
printSuccess();
printSampleRate();
prepToSendBytes();
} else if (isDigit(c)) {
uint8_t digit = c - '0';
if (digit <= SAMPLE_RATE_200) {
if (!is_running) {
setSampleRate(digit);
// initialize();
// printSuccess();
printSuccess();
printSampleRate();
prepToSendBytes();
}
} else {
if (!is_running) {
// printFailure();
Serial.print("sample value out of bounds. ");
printFailure();
loadlnString("sample value out of bounds");
printSampleRate();
prepToSendBytes();
}
}
} else {
if (!is_running) {
// printFailure();
Serial.print("invalid sample value.");
printFailure();
loadString("Invalid sample value.");
printSampleRate();
prepToSendBytes();
}
}
settingSampleRate = false;
}

void OpenBCI_Ganglion::setSampleRate(uint8_t newSampleRateCode) {
curSampleRate = (SAMPLE_RATE)newSampleRateCode;
config_MCP3912(gain);
}

void OpenBCI_Ganglion::printSampleRate() {
const char* OpenBCI_Ganglion::getSampleRate() {
switch (curSampleRate) {
case SAMPLE_RATE_25600:
Serial.print("25600");
break;
return "25600";
case SAMPLE_RATE_12800:
Serial.print("12800");
break;
return "12800";
case SAMPLE_RATE_6400:
Serial.print("6400");
break;
return "6400";
case SAMPLE_RATE_3200:
Serial.print("3200");
break;
return "3200";
case SAMPLE_RATE_1600:
Serial.print("1600");
break;
return "1600";
case SAMPLE_RATE_800:
Serial.print("800");
break;
return "800";
case SAMPLE_RATE_400:
Serial.print("400");
break;
return "400";
case SAMPLE_RATE_200:
default:
Serial.print("200");
break;

return "200";
}
}

Expand Down
5 changes: 4 additions & 1 deletion OpenBCI_Ganglion_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OpenBCI_Ganglion {

void processIncomingSampleRate(char);
void setSampleRate(uint8_t);
void printSampleRate(void);
const char * getSampleRate(void);

void initialize(void);
void makeUniqueId(void);
Expand Down Expand Up @@ -114,6 +114,9 @@ class OpenBCI_Ganglion {
void initSerialBuffer(void);
void loadInt(int i, boolean);
void parseChar(char);
void printFailure(void);
void printSampleRate(void);
void printSuccess(void);
uint8_t * getGains(void);

boolean settingSampleRate = false;
Expand Down
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

* Changed MCP3912 setup to NOT accept sample rate passed into it

## Beta4

### Enhancements

* Needed to update sample rate setting functions to match the Cyton responses and thus work with wifi drivers.
* Add more helper printing functions to reduce code string foot prints such as `::printSampleRate()`, `::printFailure()`, and `::printSuccess()`

## Beta3

### New Features
Expand All @@ -27,7 +34,7 @@ The overall goal was to clean the wifi code out of the library so it would not b

* Removed all wifi code and put into [new library](https://github.com/OpenBCI/OpenBCI_Wifi_Master_Library) that must be included! The new library is a called [OpenBCI_Wifi_Master_Library](https://github.com/OpenBCI/OpenBCI_Wifi_Master_Library). It is simply included when wifi is wanted.
* Removed `.loop()` function from library and all other `wifi*.()` functions.
* `DefaultBoard.ino` now has wifi code.
* `DefaultGanglion.ino` now has wifi code.

### Files

Expand Down

0 comments on commit 00c1d1c

Please sign in to comment.