Microcontroller firmware that uses a simple, yet powerful scripting language to control the timing of input and output events with high temporal resolution. Written by Mattias Karlsson

Dependencies:   SMARTWAV mbed

Committer:
mkarlsso
Date:
Tue Feb 07 19:40:32 2017 +0000
Revision:
8:872b843a3053
Parent:
7:5fe7329751d4
Added "version command"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkarlsso 0:8dbd6bd9167f 1 #include "hardwareInterface.h"
mkarlsso 0:8dbd6bd9167f 2 //#include <ostream>
mkarlsso 0:8dbd6bd9167f 3 #include <sstream>
mkarlsso 0:8dbd6bd9167f 4
mkarlsso 0:8dbd6bd9167f 5 using namespace std;
mkarlsso 0:8dbd6bd9167f 6
mkarlsso 0:8dbd6bd9167f 7 //In debug mode, debug messages output to the screen
mkarlsso 0:8dbd6bd9167f 8 #ifdef DEBUGOUTPUT
mkarlsso 0:8dbd6bd9167f 9 bool debugOut = true;
mkarlsso 0:8dbd6bd9167f 10 #else
mkarlsso 0:8dbd6bd9167f 11 bool debugOut = false;
mkarlsso 0:8dbd6bd9167f 12 #endif
mkarlsso 0:8dbd6bd9167f 13
mkarlsso 0:8dbd6bd9167f 14 uint32_t timeKeeper; //the main clock (updated every ms)
mkarlsso 0:8dbd6bd9167f 15 bool resetTimer;
mkarlsso 0:8dbd6bd9167f 16 bool clockSlave;
mkarlsso 0:8dbd6bd9167f 17 bool changeToSlave;
mkarlsso 0:8dbd6bd9167f 18 bool changeToStandAlone;
mkarlsso 0:8dbd6bd9167f 19
mkarlsso 0:8dbd6bd9167f 20
mkarlsso 0:8dbd6bd9167f 21 #ifdef MBEDHARDWARE
mkarlsso 0:8dbd6bd9167f 22
mkarlsso 0:8dbd6bd9167f 23 //On the MBED, this needs to be put on a defined bank of memory, or else we run out of memory
mkarlsso 0:8dbd6bd9167f 24 __attribute((section("AHBSRAM0"),aligned)) outputStream textDisplay(512);
mkarlsso 0:8dbd6bd9167f 25
mkarlsso 0:8dbd6bd9167f 26 #else
mkarlsso 0:8dbd6bd9167f 27 outputStream textDisplay(256);
mkarlsso 0:8dbd6bd9167f 28
mkarlsso 0:8dbd6bd9167f 29 #endif
mkarlsso 0:8dbd6bd9167f 30
mkarlsso 0:8dbd6bd9167f 31
mkarlsso 0:8dbd6bd9167f 32 //---------------------------------------------------------
mkarlsso 0:8dbd6bd9167f 33
mkarlsso 0:8dbd6bd9167f 34 sSystem::sSystem() {
mkarlsso 3:d7b0a0890d96 35 for (int i=0;i<32;i++) {
mkarlsso 7:5fe7329751d4 36 ignorePortUpdates[i] = true; //by default, all digital port changes are not automatically reported.
mkarlsso 3:d7b0a0890d96 37 }
mkarlsso 3:d7b0a0890d96 38 }
mkarlsso 0:8dbd6bd9167f 39
mkarlsso 3:d7b0a0890d96 40 //The user can toggle whether a particular port triggers a state update report every time it changes
mkarlsso 3:d7b0a0890d96 41 //This is useful for inputs that toggle continuously.
mkarlsso 3:d7b0a0890d96 42 void sSystem::setPortUpdatesOff(int portNum) {
mkarlsso 3:d7b0a0890d96 43 ignorePortUpdates[portNum] = true;
mkarlsso 3:d7b0a0890d96 44 }
mkarlsso 3:d7b0a0890d96 45
mkarlsso 3:d7b0a0890d96 46 void sSystem::setPortUpdatesOn(int portNum) {
mkarlsso 3:d7b0a0890d96 47 ignorePortUpdates[portNum] = false;
mkarlsso 3:d7b0a0890d96 48 }
mkarlsso 3:d7b0a0890d96 49
mkarlsso 3:d7b0a0890d96 50 bool* sSystem::getIgnoreUpdates() {
mkarlsso 3:d7b0a0890d96 51 return ignorePortUpdates;
mkarlsso 0:8dbd6bd9167f 52 }
mkarlsso 0:8dbd6bd9167f 53
mkarlsso 0:8dbd6bd9167f 54 void sSystem::immediateClockReset() {
mkarlsso 0:8dbd6bd9167f 55 //For external clock reset
mkarlsso 0:8dbd6bd9167f 56 timeKeeper = 0;
mkarlsso 0:8dbd6bd9167f 57 textDisplay << timeKeeper << " Clock reset\r\n";
mkarlsso 0:8dbd6bd9167f 58 }
mkarlsso 0:8dbd6bd9167f 59
mkarlsso 0:8dbd6bd9167f 60 void sSystem::mainLoopToDo() {
mkarlsso 0:8dbd6bd9167f 61
mkarlsso 0:8dbd6bd9167f 62 }
mkarlsso 0:8dbd6bd9167f 63
mkarlsso 0:8dbd6bd9167f 64 void sSystem::pauseInterrupts() {
mkarlsso 0:8dbd6bd9167f 65
mkarlsso 0:8dbd6bd9167f 66 }
mkarlsso 0:8dbd6bd9167f 67
mkarlsso 7:5fe7329751d4 68 void sSystem::reset() {
mkarlsso 7:5fe7329751d4 69
mkarlsso 7:5fe7329751d4 70 }
mkarlsso 7:5fe7329751d4 71
mkarlsso 8:872b843a3053 72 void sSystem::setMaxAnalogOut(int value) {
mkarlsso 8:872b843a3053 73
mkarlsso 8:872b843a3053 74 }
mkarlsso 8:872b843a3053 75
mkarlsso 0:8dbd6bd9167f 76 void sSystem::resumeInterrupts() {
mkarlsso 0:8dbd6bd9167f 77
mkarlsso 0:8dbd6bd9167f 78 }
mkarlsso 0:8dbd6bd9167f 79
mkarlsso 0:8dbd6bd9167f 80 int sSystem::getPendingFunctionTriggers(uint16_t *bufferPtr) {
mkarlsso 0:8dbd6bd9167f 81 return 0;
mkarlsso 0:8dbd6bd9167f 82 }
mkarlsso 0:8dbd6bd9167f 83
mkarlsso 0:8dbd6bd9167f 84 uint32_t sSystem::getDigitalOutputChangeFlags() {
mkarlsso 0:8dbd6bd9167f 85
mkarlsso 0:8dbd6bd9167f 86 }
mkarlsso 0:8dbd6bd9167f 87
mkarlsso 0:8dbd6bd9167f 88 uint32_t sSystem::getDigitalInputChangeFlags() {
mkarlsso 0:8dbd6bd9167f 89
mkarlsso 0:8dbd6bd9167f 90 }
mkarlsso 7:5fe7329751d4 91 //-----------------------------------------------------
mkarlsso 7:5fe7329751d4 92 sAnalogOut::sAnalogOut() {
mkarlsso 7:5fe7329751d4 93
mkarlsso 7:5fe7329751d4 94 }
mkarlsso 7:5fe7329751d4 95
mkarlsso 7:5fe7329751d4 96 //------------------------------------------------------
mkarlsso 7:5fe7329751d4 97 sAnalogIn::sAnalogIn() {
mkarlsso 7:5fe7329751d4 98
mkarlsso 7:5fe7329751d4 99 }
mkarlsso 7:5fe7329751d4 100
mkarlsso 0:8dbd6bd9167f 101
mkarlsso 0:8dbd6bd9167f 102 //------------------------------------------------------
mkarlsso 0:8dbd6bd9167f 103 sDigitalOut::sDigitalOut() {
mkarlsso 0:8dbd6bd9167f 104
mkarlsso 0:8dbd6bd9167f 105 }
mkarlsso 0:8dbd6bd9167f 106
mkarlsso 0:8dbd6bd9167f 107 //----------------------------------------------------
mkarlsso 0:8dbd6bd9167f 108 sDigitalIn::sDigitalIn() {
mkarlsso 0:8dbd6bd9167f 109 lastDownEvent.triggered = false;
mkarlsso 0:8dbd6bd9167f 110 lastUpEvent.triggered = false;
mkarlsso 2:35266b266eaa 111 bufferedDownEvent.triggered = false;
mkarlsso 2:35266b266eaa 112 bufferedUpEvent.triggered = false;
mkarlsso 2:35266b266eaa 113 updating = false;
mkarlsso 0:8dbd6bd9167f 114 }
mkarlsso 0:8dbd6bd9167f 115
mkarlsso 0:8dbd6bd9167f 116 void sDigitalIn::addStateChange(int newState, uint32_t timeStamp) {
mkarlsso 0:8dbd6bd9167f 117
mkarlsso 0:8dbd6bd9167f 118 //With levers and beam breaks, there will be flutter when triggers happen.
mkarlsso 0:8dbd6bd9167f 119 //The goal is to capture the initial event time, so we ignore extra triggers
mkarlsso 0:8dbd6bd9167f 120 //until it has been processed
mkarlsso 2:35266b266eaa 121 if (!updating) {
mkarlsso 2:35266b266eaa 122 if ((newState == 0) && (!lastDownEvent.triggered)){
mkarlsso 2:35266b266eaa 123 lastDownEvent.timeStamp = timeStamp;
mkarlsso 2:35266b266eaa 124 lastDownEvent.triggered = true;
mkarlsso 2:35266b266eaa 125 } else if ((newState == 1) && (!lastUpEvent.triggered)) {
mkarlsso 2:35266b266eaa 126 lastUpEvent.timeStamp = timeStamp;
mkarlsso 2:35266b266eaa 127 lastUpEvent.triggered = true;
mkarlsso 2:35266b266eaa 128 }
mkarlsso 2:35266b266eaa 129 } else {
mkarlsso 2:35266b266eaa 130 //If we are currently checking this input, then we buffer the trigger and deal with it after
mkarlsso 2:35266b266eaa 131 if (newState == 0){
mkarlsso 2:35266b266eaa 132 bufferedDownEvent.timeStamp = timeStamp;
mkarlsso 7:5fe7329751d4 133 bufferedDownEvent.triggered = true;
mkarlsso 2:35266b266eaa 134 } else if (newState == 1) {
mkarlsso 2:35266b266eaa 135 bufferedUpEvent.timeStamp = timeStamp;
mkarlsso 7:5fe7329751d4 136 bufferedUpEvent.triggered = true;
mkarlsso 2:35266b266eaa 137 }
mkarlsso 2:35266b266eaa 138 }
mkarlsso 2:35266b266eaa 139 /*
mkarlsso 0:8dbd6bd9167f 140 if ((newState == 0) && (!lastDownEvent.triggered)){
mkarlsso 0:8dbd6bd9167f 141 lastDownEvent.timeStamp = timeStamp;
mkarlsso 0:8dbd6bd9167f 142 lastDownEvent.triggered = true;
mkarlsso 0:8dbd6bd9167f 143 } else if ((newState == 1) && (!lastUpEvent.triggered)) {
mkarlsso 0:8dbd6bd9167f 144 lastUpEvent.timeStamp = timeStamp;
mkarlsso 0:8dbd6bd9167f 145 lastUpEvent.triggered = true;
mkarlsso 2:35266b266eaa 146 }*/
mkarlsso 2:35266b266eaa 147 }
mkarlsso 2:35266b266eaa 148
mkarlsso 2:35266b266eaa 149 void sDigitalIn::setUpdate(bool state) {
mkarlsso 2:35266b266eaa 150 updating = state; //If true, then we buffer any trigger events until the update check is done.
mkarlsso 2:35266b266eaa 151 if (!updating) {
mkarlsso 2:35266b266eaa 152 if (bufferedUpEvent.triggered) {
mkarlsso 2:35266b266eaa 153 lastUpEvent = bufferedUpEvent;
mkarlsso 2:35266b266eaa 154 }
mkarlsso 2:35266b266eaa 155 if (bufferedDownEvent.triggered) {
mkarlsso 2:35266b266eaa 156 lastDownEvent = bufferedDownEvent;
mkarlsso 2:35266b266eaa 157 }
mkarlsso 2:35266b266eaa 158 bufferedDownEvent.triggered = false;
mkarlsso 2:35266b266eaa 159 bufferedUpEvent.triggered = false;
mkarlsso 0:8dbd6bd9167f 160 }
mkarlsso 0:8dbd6bd9167f 161 }
mkarlsso 0:8dbd6bd9167f 162
mkarlsso 0:8dbd6bd9167f 163 //-----------------------------------------------------
mkarlsso 0:8dbd6bd9167f 164 sSerialPort::sSerialPort() {
mkarlsso 0:8dbd6bd9167f 165
mkarlsso 0:8dbd6bd9167f 166 }
mkarlsso 0:8dbd6bd9167f 167
mkarlsso 0:8dbd6bd9167f 168 //------------------------------------------------------
mkarlsso 0:8dbd6bd9167f 169
mkarlsso 0:8dbd6bd9167f 170 sSound::sSound(void):
mkarlsso 0:8dbd6bd9167f 171 fileNameExists(false),
mkarlsso 0:8dbd6bd9167f 172 volumePtr(NULL),
mkarlsso 0:8dbd6bd9167f 173 volume(-1),
mkarlsso 0:8dbd6bd9167f 174 play(true),
mkarlsso 0:8dbd6bd9167f 175 reset(false) {
mkarlsso 0:8dbd6bd9167f 176 }
mkarlsso 0:8dbd6bd9167f 177
mkarlsso 0:8dbd6bd9167f 178 void sSound::setFile(string fileNameIn) {
mkarlsso 0:8dbd6bd9167f 179 for (int i = 0; i < 20; i++) {
mkarlsso 0:8dbd6bd9167f 180 fileName[i] = NULL;
mkarlsso 0:8dbd6bd9167f 181 }
mkarlsso 0:8dbd6bd9167f 182 size_t length = fileNameIn.size();
mkarlsso 0:8dbd6bd9167f 183 if (length <= 20) {
mkarlsso 0:8dbd6bd9167f 184 fileNameIn.copy(fileName, length, 0);
mkarlsso 0:8dbd6bd9167f 185 fileNameExists = true;
mkarlsso 0:8dbd6bd9167f 186 }
mkarlsso 0:8dbd6bd9167f 187 }
mkarlsso 0:8dbd6bd9167f 188 void sSound::setVolume(int volumeIn) {
mkarlsso 0:8dbd6bd9167f 189
mkarlsso 0:8dbd6bd9167f 190 if ((volumeIn >= 0) && (volumeIn < 256)) {
mkarlsso 0:8dbd6bd9167f 191 volume = volumeIn;
mkarlsso 0:8dbd6bd9167f 192 volumePtr = NULL;
mkarlsso 0:8dbd6bd9167f 193 }
mkarlsso 0:8dbd6bd9167f 194 }
mkarlsso 0:8dbd6bd9167f 195
mkarlsso 0:8dbd6bd9167f 196 void sSound::setVolume(int* volumeIn) {
mkarlsso 0:8dbd6bd9167f 197
mkarlsso 0:8dbd6bd9167f 198 volume = -1;
mkarlsso 0:8dbd6bd9167f 199 volumePtr = volumeIn;
mkarlsso 0:8dbd6bd9167f 200
mkarlsso 0:8dbd6bd9167f 201 }
mkarlsso 0:8dbd6bd9167f 202
mkarlsso 0:8dbd6bd9167f 203 void sSound::setPlayback(bool playIn) {
mkarlsso 0:8dbd6bd9167f 204 play = playIn;
mkarlsso 0:8dbd6bd9167f 205 }
mkarlsso 0:8dbd6bd9167f 206
mkarlsso 0:8dbd6bd9167f 207 void sSound::setReset() {
mkarlsso 0:8dbd6bd9167f 208 reset = true;
mkarlsso 0:8dbd6bd9167f 209 }
mkarlsso 0:8dbd6bd9167f 210
mkarlsso 0:8dbd6bd9167f 211
mkarlsso 0:8dbd6bd9167f 212 //-----------------------------------------------------
mkarlsso 0:8dbd6bd9167f 213 outputStream::outputStream(int bufferSizeIn):
mkarlsso 0:8dbd6bd9167f 214 readHead(0),
mkarlsso 0:8dbd6bd9167f 215 writeHead(0),
mkarlsso 0:8dbd6bd9167f 216 totalWriteHead(0),
mkarlsso 0:8dbd6bd9167f 217 totalReadHead(0),
mkarlsso 0:8dbd6bd9167f 218 bufferSize(bufferSizeIn),
mkarlsso 0:8dbd6bd9167f 219 unsentData(false),
mkarlsso 0:8dbd6bd9167f 220 serialPtr(NULL) {
mkarlsso 0:8dbd6bd9167f 221
mkarlsso 0:8dbd6bd9167f 222 outputBuffer = new char[bufferSize];
mkarlsso 0:8dbd6bd9167f 223
mkarlsso 0:8dbd6bd9167f 224 }
mkarlsso 0:8dbd6bd9167f 225
mkarlsso 0:8dbd6bd9167f 226 outputStream::~outputStream() {
mkarlsso 0:8dbd6bd9167f 227 delete[] outputBuffer;
mkarlsso 0:8dbd6bd9167f 228 }
mkarlsso 0:8dbd6bd9167f 229
mkarlsso 0:8dbd6bd9167f 230 void outputStream::setSerial(sSerialPort *s) {
mkarlsso 0:8dbd6bd9167f 231 serialPtr = s;
mkarlsso 0:8dbd6bd9167f 232 }
mkarlsso 0:8dbd6bd9167f 233
mkarlsso 0:8dbd6bd9167f 234 //used to immediately write to serial port
mkarlsso 0:8dbd6bd9167f 235 void outputStream::flush() {
mkarlsso 0:8dbd6bd9167f 236 if (serialPtr != NULL) {
mkarlsso 0:8dbd6bd9167f 237 while(unsentData) {
mkarlsso 0:8dbd6bd9167f 238 serialPtr->writeChar(getNextChar());
mkarlsso 0:8dbd6bd9167f 239 }
mkarlsso 0:8dbd6bd9167f 240 }
mkarlsso 0:8dbd6bd9167f 241 }
mkarlsso 0:8dbd6bd9167f 242
mkarlsso 0:8dbd6bd9167f 243 //adds text to the buffer
mkarlsso 3:d7b0a0890d96 244 void outputStream::send(const string &outputString) {
mkarlsso 0:8dbd6bd9167f 245 int strLen = outputString.size();
mkarlsso 0:8dbd6bd9167f 246
mkarlsso 0:8dbd6bd9167f 247 int total = 0;
mkarlsso 0:8dbd6bd9167f 248 int chunk = 0;
mkarlsso 0:8dbd6bd9167f 249 if (totalWriteHead+strLen > (totalReadHead + bufferSize)) {
mkarlsso 0:8dbd6bd9167f 250 //We don't have enough space in the buffer, so flush it
mkarlsso 0:8dbd6bd9167f 251 flush();
mkarlsso 0:8dbd6bd9167f 252 }
mkarlsso 0:8dbd6bd9167f 253 if (!(totalWriteHead+strLen > (totalReadHead + bufferSize))) {
mkarlsso 0:8dbd6bd9167f 254 while (strLen - total > 0) {
mkarlsso 0:8dbd6bd9167f 255 chunk = min((bufferSize - writeHead), strLen - total);
mkarlsso 0:8dbd6bd9167f 256 outputString.copy(outputBuffer + writeHead, chunk, total);
mkarlsso 0:8dbd6bd9167f 257 writeHead = (writeHead + chunk) % bufferSize;
mkarlsso 0:8dbd6bd9167f 258 totalWriteHead += chunk;
mkarlsso 0:8dbd6bd9167f 259 total += chunk;
mkarlsso 0:8dbd6bd9167f 260 }
mkarlsso 0:8dbd6bd9167f 261 if (total > 0) {
mkarlsso 0:8dbd6bd9167f 262 unsentData = true;
mkarlsso 0:8dbd6bd9167f 263 }
mkarlsso 0:8dbd6bd9167f 264 }
mkarlsso 0:8dbd6bd9167f 265 }
mkarlsso 0:8dbd6bd9167f 266
mkarlsso 3:d7b0a0890d96 267 //adds text to the buffer
mkarlsso 3:d7b0a0890d96 268 void outputStream::send(const char *s) {
mkarlsso 3:d7b0a0890d96 269 int strLen = strlen(s);
mkarlsso 3:d7b0a0890d96 270
mkarlsso 3:d7b0a0890d96 271 int total = 0;
mkarlsso 3:d7b0a0890d96 272 //int chunk = 0;
mkarlsso 3:d7b0a0890d96 273 if (totalWriteHead+strLen > (totalReadHead + bufferSize)) {
mkarlsso 3:d7b0a0890d96 274 //We don't have enough space in the buffer, so flush it
mkarlsso 3:d7b0a0890d96 275 flush();
mkarlsso 3:d7b0a0890d96 276 }
mkarlsso 3:d7b0a0890d96 277 if (!(totalWriteHead+strLen > (totalReadHead + bufferSize))) {
mkarlsso 3:d7b0a0890d96 278 while (strLen - total > 0) {
mkarlsso 3:d7b0a0890d96 279 strncpy(outputBuffer + writeHead, s+total,1);
mkarlsso 3:d7b0a0890d96 280 total++;
mkarlsso 3:d7b0a0890d96 281 writeHead = (writeHead + 1) % bufferSize;
mkarlsso 3:d7b0a0890d96 282 totalWriteHead += 1;
mkarlsso 3:d7b0a0890d96 283
mkarlsso 3:d7b0a0890d96 284 /*
mkarlsso 3:d7b0a0890d96 285 chunk = min((bufferSize - writeHead), strLen - total);
mkarlsso 3:d7b0a0890d96 286 strncpy(outputBuffer + writeHead,);
mkarlsso 3:d7b0a0890d96 287 outputString.copy(outputBuffer + writeHead, chunk, total);
mkarlsso 3:d7b0a0890d96 288 writeHead = (writeHead + chunk) % bufferSize;
mkarlsso 3:d7b0a0890d96 289 totalWriteHead += chunk;
mkarlsso 3:d7b0a0890d96 290 total += chunk;
mkarlsso 3:d7b0a0890d96 291 */
mkarlsso 3:d7b0a0890d96 292 }
mkarlsso 3:d7b0a0890d96 293 if (total > 0) {
mkarlsso 3:d7b0a0890d96 294 unsentData = true;
mkarlsso 3:d7b0a0890d96 295 }
mkarlsso 3:d7b0a0890d96 296 }
mkarlsso 3:d7b0a0890d96 297 }
mkarlsso 3:d7b0a0890d96 298
mkarlsso 0:8dbd6bd9167f 299 void outputStream::debug(const char *s) {
mkarlsso 0:8dbd6bd9167f 300 //send to serial immediately, but only if debugOut is true
mkarlsso 0:8dbd6bd9167f 301 if (debugOut) {
mkarlsso 0:8dbd6bd9167f 302 string tmpString = string(s);
mkarlsso 0:8dbd6bd9167f 303 send(tmpString);
mkarlsso 0:8dbd6bd9167f 304 flush();
mkarlsso 0:8dbd6bd9167f 305 }
mkarlsso 0:8dbd6bd9167f 306 }
mkarlsso 0:8dbd6bd9167f 307
mkarlsso 0:8dbd6bd9167f 308 //Overloaded << operator to for debugging output. This eliminates the
mkarlsso 0:8dbd6bd9167f 309 //need for printf statements
mkarlsso 3:d7b0a0890d96 310 outputStream& outputStream::operator<<(const string &outputString) {
mkarlsso 0:8dbd6bd9167f 311 send(outputString);
mkarlsso 3:d7b0a0890d96 312
mkarlsso 0:8dbd6bd9167f 313 return *this;
mkarlsso 0:8dbd6bd9167f 314 }
mkarlsso 0:8dbd6bd9167f 315
mkarlsso 0:8dbd6bd9167f 316 outputStream& outputStream::operator<<(const char* s) {
mkarlsso 3:d7b0a0890d96 317 //string tmpString = string(s);
mkarlsso 3:d7b0a0890d96 318 //send(tmpString);
mkarlsso 3:d7b0a0890d96 319 send(s);
mkarlsso 0:8dbd6bd9167f 320 return *this;
mkarlsso 0:8dbd6bd9167f 321 }
mkarlsso 0:8dbd6bd9167f 322
mkarlsso 0:8dbd6bd9167f 323 outputStream& outputStream::operator<<(int outputNum) {
mkarlsso 0:8dbd6bd9167f 324 ostringstream varConvert;
mkarlsso 0:8dbd6bd9167f 325 varConvert << outputNum;
mkarlsso 0:8dbd6bd9167f 326 send(varConvert.str());
mkarlsso 0:8dbd6bd9167f 327 return *this;
mkarlsso 0:8dbd6bd9167f 328 }
mkarlsso 0:8dbd6bd9167f 329
mkarlsso 0:8dbd6bd9167f 330 outputStream& outputStream::operator<<(uint32_t outputNum) {
mkarlsso 0:8dbd6bd9167f 331 ostringstream varConvert;
mkarlsso 0:8dbd6bd9167f 332 varConvert << outputNum;
mkarlsso 0:8dbd6bd9167f 333 send(varConvert.str());
mkarlsso 0:8dbd6bd9167f 334 return *this;
mkarlsso 0:8dbd6bd9167f 335 }
mkarlsso 0:8dbd6bd9167f 336 //the main loop gets one character per loop and write it to the serial port
mkarlsso 0:8dbd6bd9167f 337 char outputStream::getNextChar() {
mkarlsso 0:8dbd6bd9167f 338
mkarlsso 0:8dbd6bd9167f 339
mkarlsso 0:8dbd6bd9167f 340 if (totalReadHead < totalWriteHead) {
mkarlsso 0:8dbd6bd9167f 341 tmpOut = *(outputBuffer+readHead);
mkarlsso 0:8dbd6bd9167f 342 readHead = (readHead+1) % bufferSize;
mkarlsso 0:8dbd6bd9167f 343 totalReadHead++;
mkarlsso 0:8dbd6bd9167f 344 if (totalReadHead >= totalWriteHead) {
mkarlsso 0:8dbd6bd9167f 345 unsentData = false;
mkarlsso 0:8dbd6bd9167f 346 }
mkarlsso 0:8dbd6bd9167f 347 }
mkarlsso 0:8dbd6bd9167f 348 return tmpOut;
mkarlsso 0:8dbd6bd9167f 349
mkarlsso 0:8dbd6bd9167f 350 }
mkarlsso 0:8dbd6bd9167f 351
mkarlsso 0:8dbd6bd9167f 352