diff --git a/src/didacticNet.cpp b/src/didacticNet.cpp index 5cb507084c785422e19b3731f2afe66f58ddf9a8..40030397fee7b67e4c466b72f8c61aeac6a99e2b 100644 --- a/src/didacticNet.cpp +++ b/src/didacticNet.cpp @@ -343,39 +343,6 @@ bool didacticPSNetClient::valueChanged(int vcValue, int vcThreshold){ return false; } -//************************************************************************** -//LITTLE HELPERS FOR CLIENTS ;-) -//************************************************************************* -bool didacticPSNetClient::timeElapsed(long teDelayTime){ - static long teLastTime = 0L; - long currentTime = millis(); - - if(teLastTime + (teDelayTime-1) < currentTime){ - teLastTime = currentTime; - return true; - } - return false; -} - -int didacticPSNetClient::readSerialData(Stream& rsStream, char* rsDataArray, char rsEndSign) { - static int rsCounter = 0; - - if (rsStream.available()) { - char charBuffer = rsStream.read(); - rsDataArray[rsCounter] = charBuffer; - - if (charBuffer == rsEndSign) { - rsDataArray[rsCounter] = '\0'; - int nrOfChars = rsCounter; - rsCounter = 0; - return nrOfChars; - } else { - rsCounter++; - } - } - return 0; -} - //************************************************************************** //Broker @@ -474,3 +441,42 @@ int didacticPSNetBroker::getFreeTopicNr() { } return -1; } + + +//************************************************************************** +//LITTLE HELPERS FOR CLIENTS ;-) +//************************************************************************* + +unblockingTimer::unblockingTimer(){} +unblockingTimer::~unblockingTimer(){} + +bool unblockingTimer::timeElapsed(long delayTime){ + long currentTime = millis(); + + if(lastTime + (delayTime-1) < currentTime){ + lastTime = currentTime; + return true; + } + return false; +} + +serialReader::serialReader(){} +serialReader::~serialReader(){} + +int serialReader::readSerialData(Stream& rsStream, char* rsDataArray, char rsEndSign) { + + if (rsStream.available()) { + char charBuffer = rsStream.read(); + rsDataArray[charCounter] = charBuffer; + + if (charBuffer == rsEndSign) { + rsDataArray[charCounter] = '\0'; + int nrOfChars = charCounter; + charCounter = 0; + return nrOfChars; + } else { + charCounter++; + } + } + return 0; +} \ No newline at end of file diff --git a/src/didacticNet.h b/src/didacticNet.h index da688cb08e20ca5ea6af791e84264f27788a65dc..63f1d6d0fd837087c68688b34a6e07864d00cc5b 100644 --- a/src/didacticNet.h +++ b/src/didacticNet.h @@ -123,10 +123,6 @@ class didacticPSNetClient : public didacticPSNet int subscribe(char*, int); bool unsubscribe(char*); bool unsubscribe(char*, int); - - //little helpers - bool timeElapsed(long); - int readSerialData(Stream&, char*, char); }; @@ -150,5 +146,25 @@ class didacticPSNetBroker: public didacticPSNet bool update(char*, int, char*, int); +}; + + +class unblockingTimer +{ + private: + long lastTime = 0L; + + public: + bool timeElapsed(long); + +}; +class serialReader +{ + private: + int charCounter = 0; + + public: + int readSerialData(Stream&, char*, char); + }; #endif