![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mindflex
Dependencies: mbed Arduino millis
Brain.h@1:c8dd92fc8aa8, 2018-10-11 (annotated)
- Committer:
- harrisonstatham
- Date:
- Thu Oct 11 18:26:36 2018 +0000
- Revision:
- 1:c8dd92fc8aa8
- Parent:
- 0:6466440bff3a
Added harry;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kbeck8 | 0:6466440bff3a | 1 | #ifndef Brain_h |
kbeck8 | 0:6466440bff3a | 2 | #define Brain_h |
kbeck8 | 0:6466440bff3a | 3 | |
kbeck8 | 0:6466440bff3a | 4 | #include "mbed.h" |
kbeck8 | 0:6466440bff3a | 5 | |
kbeck8 | 0:6466440bff3a | 6 | #define MAX_PACKET_LENGTH 32 |
kbeck8 | 0:6466440bff3a | 7 | #define EEG_POWER_BANDS 8 |
kbeck8 | 0:6466440bff3a | 8 | |
kbeck8 | 0:6466440bff3a | 9 | class Brain { |
kbeck8 | 0:6466440bff3a | 10 | public: |
kbeck8 | 0:6466440bff3a | 11 | Brain(Stream &_brainStream); |
kbeck8 | 0:6466440bff3a | 12 | |
kbeck8 | 0:6466440bff3a | 13 | // Run this in the main loop. |
kbeck8 | 0:6466440bff3a | 14 | boolean update(); |
kbeck8 | 0:6466440bff3a | 15 | |
kbeck8 | 0:6466440bff3a | 16 | // String with most recent error. |
kbeck8 | 0:6466440bff3a | 17 | char* readErrors(); |
kbeck8 | 0:6466440bff3a | 18 | |
kbeck8 | 0:6466440bff3a | 19 | // Returns comme-delimited string of all available brain data. |
kbeck8 | 0:6466440bff3a | 20 | // Sequence is as below. |
kbeck8 | 0:6466440bff3a | 21 | char* readCSV(); |
kbeck8 | 0:6466440bff3a | 22 | |
kbeck8 | 0:6466440bff3a | 23 | // Individual pieces of brain data. |
kbeck8 | 0:6466440bff3a | 24 | uint8_t readSignalQuality(); |
kbeck8 | 0:6466440bff3a | 25 | uint8_t readAttention(); |
kbeck8 | 0:6466440bff3a | 26 | uint8_t readMeditation(); |
kbeck8 | 0:6466440bff3a | 27 | uint32_t* readPowerArray(); |
kbeck8 | 0:6466440bff3a | 28 | uint32_t readDelta(); |
kbeck8 | 0:6466440bff3a | 29 | uint32_t readTheta(); |
kbeck8 | 0:6466440bff3a | 30 | uint32_t readLowAlpha(); |
kbeck8 | 0:6466440bff3a | 31 | uint32_t readHighAlpha(); |
kbeck8 | 0:6466440bff3a | 32 | uint32_t readLowBeta(); |
kbeck8 | 0:6466440bff3a | 33 | uint32_t readHighBeta(); |
kbeck8 | 0:6466440bff3a | 34 | uint32_t readLowGamma(); |
kbeck8 | 0:6466440bff3a | 35 | uint32_t readMidGamma(); |
kbeck8 | 0:6466440bff3a | 36 | |
kbeck8 | 0:6466440bff3a | 37 | private: |
kbeck8 | 0:6466440bff3a | 38 | Stream* brainStream; |
kbeck8 | 0:6466440bff3a | 39 | uint8_t packetData[MAX_PACKET_LENGTH]; |
kbeck8 | 0:6466440bff3a | 40 | boolean inPacket; |
kbeck8 | 0:6466440bff3a | 41 | uint8_t latestByte; |
kbeck8 | 0:6466440bff3a | 42 | uint8_t lastByte; |
kbeck8 | 0:6466440bff3a | 43 | uint8_t packetIndex; |
kbeck8 | 0:6466440bff3a | 44 | uint8_t packetLength; |
kbeck8 | 0:6466440bff3a | 45 | uint8_t checksum; |
kbeck8 | 0:6466440bff3a | 46 | uint8_t checksumAccumulator; |
kbeck8 | 0:6466440bff3a | 47 | uint8_t eegPowerLength; |
kbeck8 | 0:6466440bff3a | 48 | boolean hasPower; |
kbeck8 | 0:6466440bff3a | 49 | void clearPacket(); |
kbeck8 | 0:6466440bff3a | 50 | void clearEegPower(); |
kbeck8 | 0:6466440bff3a | 51 | boolean parsePacket(); |
kbeck8 | 0:6466440bff3a | 52 | |
kbeck8 | 0:6466440bff3a | 53 | void printPacket(); |
kbeck8 | 0:6466440bff3a | 54 | void init(); |
kbeck8 | 0:6466440bff3a | 55 | void printCSV(); // maybe should be public? |
kbeck8 | 0:6466440bff3a | 56 | void printDebug(); |
kbeck8 | 0:6466440bff3a | 57 | |
kbeck8 | 0:6466440bff3a | 58 | // With current hardware, at most we would have... |
kbeck8 | 0:6466440bff3a | 59 | // 3 x 3 char uint8_t |
kbeck8 | 0:6466440bff3a | 60 | // 8 x 10 char uint32_t |
kbeck8 | 0:6466440bff3a | 61 | // 10 x 1 char commas |
kbeck8 | 0:6466440bff3a | 62 | // 1 x 1 char 0 (string termination) |
kbeck8 | 0:6466440bff3a | 63 | // ------------------------- |
kbeck8 | 0:6466440bff3a | 64 | // 100 characters |
kbeck8 | 0:6466440bff3a | 65 | char csvBuffer[100]; |
kbeck8 | 0:6466440bff3a | 66 | |
kbeck8 | 0:6466440bff3a | 67 | // Longest error is |
kbeck8 | 0:6466440bff3a | 68 | // 22 x 1 char uint8_ts |
kbeck8 | 0:6466440bff3a | 69 | // 1 x 1 char 0 (string termination) |
kbeck8 | 0:6466440bff3a | 70 | char latestError[23]; |
kbeck8 | 0:6466440bff3a | 71 | |
kbeck8 | 0:6466440bff3a | 72 | uint8_t signalQuality; |
kbeck8 | 0:6466440bff3a | 73 | uint8_t attention; |
kbeck8 | 0:6466440bff3a | 74 | uint8_t meditation; |
kbeck8 | 0:6466440bff3a | 75 | |
kbeck8 | 0:6466440bff3a | 76 | boolean freshPacket; |
kbeck8 | 0:6466440bff3a | 77 | |
kbeck8 | 0:6466440bff3a | 78 | // Lighter to just make this public, instead of using the getter? |
kbeck8 | 0:6466440bff3a | 79 | uint32_t eegPower[EEG_POWER_BANDS]; |
kbeck8 | 0:6466440bff3a | 80 | }; |
kbeck8 | 0:6466440bff3a | 81 | |
kbeck8 | 0:6466440bff3a | 82 | #endif |