Permalink
Browse files

ENH interrupt driven

  • Loading branch information...
1 parent 242593d commit 82a4b41c6024fd4f50ee714f24c190272af08fd2 @aj-ptw aj-ptw committed Aug 2, 2016
Oops, something went wrong.
@@ -10,27 +10,30 @@
#include <Arduino.h>
#include "OpenBCI_32bit_Library_Definitions.h"
-
+void __USER_ISR ADS_DRDY_Service(void);
class OpenBCI_32bit_Library {
public:
// Start up functions
OpenBCI_32bit_Library();
- void begin(void);
- void beginDebug(void);
+ boolean accelHasNewData(void);
+ void accelUpdateAxisData(void);
+ void accelWriteAxisData(void);
+ void begin(void);
+ void beginDebug(void);
boolean beginSecondarySerial(void);
- char readOneSerialChar(void);
+ char getCharSerial0(void);
+ char getCharSerial1(void);
+ boolean hasDataSerial0(void);
+ boolean hasDataSerial1(void);
- void writeSerial(char *data, int len);
+
+ void writeSerial(char *data, int len);
boolean isADSDataAvailable(void);
- boolean isSerialAvailableForRead(void);
- boolean accelHasNewData(void);
- void accelUpdateAxisData(void);
- void accelWriteAxisData(void);
void writeTimeCurrent(void);
void writeZeroAux(void);
@@ -47,8 +50,9 @@ class OpenBCI_32bit_Library {
void leadOffSetForChannel(byte channelNumber, byte pInput, byte nInput);
boolean processChar(char character);
- void processIncomingLeadOffSettings(char character);
+ void processIncomingBoardMode(char character);
void processIncomingChannelSettings(char character);
+ void processIncomingLeadOffSettings(char character);
void resetChannelSettingsArrayToDefault(byte channelSettingsArray[][OPENBCI_NUMBER_OF_CHANNEL_SETTINGS]);
void resetLeadOffArrayToDefault(byte leadOffArray[][OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS]);
@@ -58,7 +62,6 @@ class OpenBCI_32bit_Library {
void sendChannelDataWithTimeAndAccel(void);
void sendChannelDataWithTimeAndRawAux(void);
- void setStreamPacketType(char newPacketType);
void streamSafeChannelDeactivate(byte channelNumber);
void streamSafeChannelActivate(byte channelNumber);
void streamSafeChannelSettingsForChannel(byte channelNumber, byte powerDown, byte gain, byte inputType, byte bias, byte srb2, byte srb1);
@@ -86,17 +89,18 @@ class OpenBCI_32bit_Library {
boolean sendTimeSyncUpPacket;
boolean isProcessingIncomingSettingsChannel;
boolean isProcessingIncomingSettingsLeadOff;
- // boolean isProcessingIncomingTime;
- boolean isProcessingIncomingPacketType;
+ boolean settingBoardMode;
+ volatile boolean channelDataAvailable;
+
boolean isProcessingMultibyteMsg(void);
+ boolean isValidBoardType(char c);
+
+ uint8_t curBoardMode;
- int boardType;
int numberOfIncomingSettingsProcessedChannel;
int numberOfIncomingSettingsProcessedLeadOff;
- int numberOfIncomingBytesProcessedTime;
char streamPacketType;
char currentChannelSetting;
- // HardwareSerial *_serial;
// Getters
char getChannelCommandForAsciiChar(char asciiChar);
@@ -317,15 +317,20 @@
#define OPENBCI_STREAM_STOP 's'
/** Miscellaneous */
-#define OPENBCI_MISC_QUERY_REGISTER_SETTINGS '?'
-#define OPENBCI_MISC_SOFT_RESET 'v'
+#define OPENBCI_MISC_QUERY_REGISTER_SETTINGS '?'
+#define OPENBCI_MISC_SOFT_RESET 'v'
/** 16 Channel Commands */
#define OPENBCI_CHANNEL_MAX_NUMBER_8 'c'
#define OPENBCI_CHANNEL_MAX_NUMBER_16 'C'
/** Set Packet Type */
-#define OPENBCI_PACKET_TYPE_SET '/'
+#define OPENBCI_BOARD_MODE_SET '/'
+#define OPENBCI_BOARD_MODE_DEFAULT '0'
+#define OPENBCI_BOARD_MODE_DEBUG '1'
+#define OPENBCI_BOARD_MODE_WIFI '2'
+#define OPENBCI_BOARD_MODE_INPUT_ANALOG '3'
+#define OPENBCI_BOARD_MODE_INPUT_DIGITAL '4'
/** Sync Clocks */
#define OPENBCI_TIME_SET '<'
@@ -336,6 +341,7 @@
#define OPENBCI_NUMBER_OF_CHANNELS_DEFAULT 8
/** Helpful numbers */
+#define OPENBCI_NUMBER_OF_BOARD_SETTINGS 1
#define OPENBCI_NUMBER_OF_CHANNEL_SETTINGS 6
#define OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS 2
@@ -368,9 +374,4 @@
#define OPENBCI_FIRMWARE_VERSION_V1 1
#define OPENBCI_FIRMWARE_VERSION_V2 1
-#define OPENBCI_BOARD_MODE_DEFAULT 0x00
-#define OPENBCI_BOARD_MODE_SERIAL_EXTERN 0x01
-#define OPENBCI_BOARD_MODE_INPUT_ANALOG 0x02
-#define OPENBCI_BOARD_MODE_INPUT_DIGITAL 0x03
-
#endif
View
@@ -1,7 +1,15 @@
-# 2.0.0
+# v2.0.0-rc.6
+
+### New Features
+
+* Add `hasDataSerial0`, `hasDataSerial1`, `getCharSerial0`, and `getCharSerial1`
### Breaking Changes
+* Removed `isSerialAvailableForRead`
+
+# 2.0.0
+
### Bug Fixes
* Sending `d` did not terminate with an EOT (`$$$`)
@@ -10,23 +10,21 @@ void setup() {
void loop() {
if (board.streaming) {
- // Wait for the ADS to signal it's ready with new data
- while (board.waitForNewChannelData()) {}
+ if (board.channelDataAvailable) {
+ // Read from the ADS(s), store data, set channelDataAvailable flag to false
+ board.updateChannelData();
- // Read from the ADS(s) and store data into
- board.updateChannelData();
-
- if (board.timeSynced) {
+ if (board.timeSynced) {
board.sendChannelDataWithTimeAndRawAux();
- } else {
+ } else {
// Send standard packet with channel data
board.sendChannelDataWithRawAux();
+ }
}
}
-
// Check the serial port for new data
- if (board.isSerialAvailableForRead()) {
+ if (board.hasDataSerial0()) {
// Read one char and process it
- board.processChar(board.readOneSerialChar());
+ board.processChar(board.getCharSerial0());
}
}
@@ -10,23 +10,26 @@ void setup() {
void loop() {
if (board.streaming) {
- // Wait for the ADS to signal it's ready with new data
- while (board.waitForNewChannelData()) {}
+ if (board.channelDataAvailable) {
+ // Read from the ADS(s), store data, set channelDataAvailable flag to false
+ board.updateChannelData();
- // Read from the ADS(s) and store data into
- board.updateChannelData();
-
- if (board.timeSynced) {
+ if (board.timeSynced) {
board.sendChannelDataWithTimeAndRawAux();
- } else {
+ } else {
// Send standard packet with channel data
board.sendChannelDataWithRawAux();
+ }
}
}
// Check the serial port for new data
- if (board.isSerialAvailableForRead()) {
+ if (board.hasDataSerial0()) {
+ // Read one char and process it
+ board.processChar(board.getCharSerial0());
+ }
+ if (board.hasDataSerial1()) {
// Read one char and process it
- board.processChar(board.readOneSerialChar());
+ board.processChar(board.getCharSerial1());
}
}
@@ -41,51 +41,48 @@ void setup() {
void loop() {
if (board.streaming) {
- // Wait for the ADS to signal it's ready with new data
- while (board.waitForNewChannelData()) {
- // Could do tiny maintiance tasks here
- }
-
- // Read from the ADS(s) and store data into
- board.updateChannelData();
+ if (board.channelDataAvailable) {
+ // Read from the ADS(s), store data, set channelDataAvailable flag to false
+ board.updateChannelData();
- leftButtonValue = digitalRead(leftButton); // feel the left button
- if (leftButtonValue != lastLeftButtonValue){ // if it's changed,
+ // Read the left button value
+ leftButtonValue = digitalRead(leftButton);
+ if (leftButtonValue != lastLeftButtonValue) { // if it's changed,
if (leftButtonValue == HIGH){ // if it's gone from LOW to HIGH
- // 0x6220 converts to PI in GUI
- board.auxData[0] = 0x6220;
- addAuxToSD = true; // add Aux Data to the SD card if it's there
+ // 0x6220 converts to PI in GUI
+ board.auxData[0] = 0x6220;
+ addAuxToSD = true; // add Aux Data to the SD card if it's there
}
lastLeftButtonValue = leftButtonValue; // keep track of the changes
- }
+ }
- rightButtonValue = digitalRead(rightButton); // feel the right button
- if (rightButtonValue != lastRightButtonValue){ // if it's changed,
+ // Read the right button value
+ rightButtonValue = digitalRead(rightButton);
+ if (rightButtonValue != lastRightButtonValue){ // if it's changed,
if (rightButtonValue == HIGH){ // if it's gone from LOW to HIGH
- // 0x6220 converts to PI in GUI
- board.auxData[1] = 0x6220;
- addAuxToSD = true; // add Aux Data to the SD card if it's there
+ // 0x6220 converts to PI in GUI
+ board.auxData[1] = 0x6220;
+ addAuxToSD = true; // add Aux Data to the SD card if it's there
}
lastRightButtonValue = rightButtonValue; // keep track of the changes
- }
+ }
- // Verify the SD file is open
- if(SDfileOpen) {
+ // Verify the SD file is open
+ if(SDfileOpen) {
// Write to the SD card, writes aux data
writeDataToSDcard(board.sampleCounter);
- }
-
-
- // Send standard packet with channel data and accel data
- // includes aux data because we set told the board to add it
- board.sendChannelData();
+ }
+ // Send standard packet with channel data and accel data
+ // includes aux data because we set told the board to add it
+ board.sendChannelData();
+ }
}
// Check the serial port for new data
- if (board.isSerialAvailableForRead()) {
+ if (board.hasDataSerial0()) {
// Read one char from the serial port
- char newChar = board.readOneSerialChar();
+ char newChar = board.getCharSerial0();
// Send to the sd library for processing
sdProcessChar(newChar);
@@ -15,30 +15,28 @@ 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()) {}
+ if (board.channelDataAvailable) {
+ // Read from the ADS(s), store data, set channelDataAvailable flag to false
+ board.updateChannelData();
- // Read from the ADS(s) and store data into
- board.updateChannelData();
-
- // Check to see if accel has new data
- if(board.accelHasNewData()){
+ // Check to see if accel has new data
+ if(board.accelHasNewData()){
// Get new accel data
board.accelUpdateAxisData();
- }
+ }
- // Send standard packet with channel data
- if (board.timeSynced) {
+ // Send standard packet with channel data
+ if (board.timeSynced) {
board.sendChannelDataWithTimeAndAccel();
- } else {
+ } else {
board.sendChannelDataWithAccel();
+ }
}
-
}
// Check the serial port for new data
- if (board.isSerialAvailableForRead()) {
+ if (board.hasDataSerial0()) {
// Read one char and process it
- board.processChar(board.readOneSerialChar());
+ board.processChar(board.getCharSerial0());
}
}
@@ -12,32 +12,31 @@ 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()
- if (board.timeSynced) {
- board.sendChannelDataWithTimeAndRawAux();
- } else {
- // Send standard packet with channel data
- board.sendChannelDataWithRawAux();
- }
+ // The main dependency of this single threaded microcontroller is to
+ // stream data from the ADS.
+ if (board.streaming) {
+ if (board.channelDataAvailable) {
+ // Read from the ADS(s), store data, set channelDataAvailable flag to false
+ 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()) {
+ // Check the serial port for new data
+ if (board.hasDataSerial0()) {
// Read one char and process it
- board.processChar(board.readOneSerialChar());
- }
+ board.processChar(board.getCharSerial0());
+ }
}
Oops, something went wrong.

0 comments on commit 82a4b41

Please sign in to comment.