From b5bfe3381686ad125ea34ed5716fa5fdeff60137 Mon Sep 17 00:00:00 2001 From: AJ Keller Date: Sun, 16 Jul 2017 14:33:05 -0400 Subject: [PATCH] Update sample rate functions --- OpenBCI_Ganglion_Library.cpp | 82 +++++++++++++++++++++--------------- OpenBCI_Ganglion_Library.h | 5 ++- changelog.md | 9 +++- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/OpenBCI_Ganglion_Library.cpp b/OpenBCI_Ganglion_Library.cpp index c37b06e..186b727 100644 --- a/OpenBCI_Ganglion_Library.cpp +++ b/OpenBCI_Ganglion_Library.cpp @@ -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; @@ -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; @@ -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"; } } diff --git a/OpenBCI_Ganglion_Library.h b/OpenBCI_Ganglion_Library.h index 0f7a6a6..7a710be 100644 --- a/OpenBCI_Ganglion_Library.h +++ b/OpenBCI_Ganglion_Library.h @@ -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); @@ -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; diff --git a/changelog.md b/changelog.md index 50f70bf..5889d1d 100644 --- a/changelog.md +++ b/changelog.md @@ -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 @@ -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