Merge pull request #476 from tekka007/WaitEnhancement

Add return value to wait()
This commit is contained in:
Henrik Ekblad
2016-06-15 21:59:18 +02:00
committed by GitHub
2 changed files with 7 additions and 3 deletions
+5 -2
View File
@@ -388,16 +388,19 @@ void wait(unsigned long ms) {
}
}
void wait(unsigned long ms, uint8_t cmd, uint8_t msgtype) {
bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype) {
unsigned long enter = hwMillis();
// invalidate msg type
_msg.type = !msgtype;
while ( (hwMillis() - enter < ms) && !(mGetCommand(_msg)==cmd && _msg.type==msgtype) ) {
bool expectedResponse = false;
while ( (hwMillis() - enter < ms) && !expectedResponse ) {
_process();
#if defined(MY_GATEWAY_ESP8266)
yield();
#endif
expectedResponse = (mGetCommand(_msg) == cmd && _msg.type == msgtype);
}
return expectedResponse;
}
+2 -1
View File
@@ -177,8 +177,9 @@ void wait(unsigned long ms);
* @param ms Number of milliseconds to sleep.
* @param cmd Command of incoming message.
* @param msgtype Message type.
* @return True if specified message received
*/
void wait(unsigned long ms, uint8_t cmd, uint8_t msgtype);
bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype);
/**
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer.