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
Diff: hardwareInterface.cpp
- Revision:
- 3:d7b0a0890d96
- Parent:
- 2:35266b266eaa
- Child:
- 6:6a6761a47951
--- a/hardwareInterface.cpp Wed Jun 03 23:41:16 2015 +0000 +++ b/hardwareInterface.cpp Sat Oct 10 22:37:17 2015 +0000 @@ -32,7 +32,23 @@ //--------------------------------------------------------- sSystem::sSystem() { + for (int i=0;i<32;i++) { + ignorePortUpdates[i] = false; + } +} +//The user can toggle whether a particular port triggers a state update report every time it changes +//This is useful for inputs that toggle continuously. +void sSystem::setPortUpdatesOff(int portNum) { + ignorePortUpdates[portNum] = true; +} + +void sSystem::setPortUpdatesOn(int portNum) { + ignorePortUpdates[portNum] = false; +} + +bool* sSystem::getIgnoreUpdates() { + return ignorePortUpdates; } void sSystem::immediateClockReset() { @@ -207,7 +223,7 @@ } //adds text to the buffer -void outputStream::send(string outputString) { +void outputStream::send(const string &outputString) { int strLen = outputString.size(); int total = 0; @@ -230,6 +246,38 @@ } } +//adds text to the buffer +void outputStream::send(const char *s) { + int strLen = strlen(s); + + int total = 0; + //int chunk = 0; + if (totalWriteHead+strLen > (totalReadHead + bufferSize)) { + //We don't have enough space in the buffer, so flush it + flush(); + } + if (!(totalWriteHead+strLen > (totalReadHead + bufferSize))) { + while (strLen - total > 0) { + strncpy(outputBuffer + writeHead, s+total,1); + total++; + writeHead = (writeHead + 1) % bufferSize; + totalWriteHead += 1; + + /* + chunk = min((bufferSize - writeHead), strLen - total); + strncpy(outputBuffer + writeHead,); + outputString.copy(outputBuffer + writeHead, chunk, total); + writeHead = (writeHead + chunk) % bufferSize; + totalWriteHead += chunk; + total += chunk; + */ + } + if (total > 0) { + unsentData = true; + } + } +} + void outputStream::debug(const char *s) { //send to serial immediately, but only if debugOut is true if (debugOut) { @@ -241,14 +289,16 @@ //Overloaded << operator to for debugging output. This eliminates the //need for printf statements -outputStream& outputStream::operator<<(string outputString) { +outputStream& outputStream::operator<<(const string &outputString) { send(outputString); + return *this; } outputStream& outputStream::operator<<(const char* s) { - string tmpString = string(s); - send(tmpString); + //string tmpString = string(s); + //send(tmpString); + send(s); return *this; }