Fix smartsleep (#535)

* Make smartSleep send heartbeat before sleeping

Sending the heartbeat (and waiting) after waking up would delay
processing inputs. For example, a switch could be back to the
open state before the wait is over.

* Fix typos in comments in smartSleep methods
This commit is contained in:
Martin Hjelmare
2016-08-02 22:21:14 +02:00
committed by Olivier
parent 99973a346e
commit b293f47a7f
+6 -10
View File
@@ -463,12 +463,11 @@ int8_t sleep(unsigned long ms) {
} }
int8_t smartSleep(unsigned long ms) { int8_t smartSleep(unsigned long ms) {
int8_t ret = sleep(ms); // notify controller about going to sleep
// notifiy controller about wake up
sendHeartbeat(); sendHeartbeat();
// listen for incoming messages // listen for incoming messages
wait(MY_SMART_SLEEP_WAIT_DURATION); wait(MY_SMART_SLEEP_WAIT_DURATION);
return ret; return sleep(ms);
} }
int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) { int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
@@ -496,12 +495,11 @@ int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
} }
int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) { int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
int8_t ret = sleep(interrupt, mode, ms); // notify controller about going to sleep
// notifiy controller about wake up
sendHeartbeat(); sendHeartbeat();
// listen for incoming messages // listen for incoming messages
wait(MY_SMART_SLEEP_WAIT_DURATION); wait(MY_SMART_SLEEP_WAIT_DURATION);
return ret; return sleep(interrupt, mode, ms);
} }
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) { int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
@@ -531,12 +529,11 @@ int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode
} }
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) { int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
int8_t ret = sleep(interrupt1, mode1, interrupt2, mode2, ms); // notify controller about going to sleep
// notifiy controller about wake up
sendHeartbeat(); sendHeartbeat();
// listen for incoming messages // listen for incoming messages
wait(MY_SMART_SLEEP_WAIT_DURATION); wait(MY_SMART_SLEEP_WAIT_DURATION);
return ret; return sleep(interrupt1, mode1, interrupt2, mode2, ms);
} }
#ifdef MY_NODE_LOCK_FEATURE #ifdef MY_NODE_LOCK_FEATURE
@@ -559,4 +556,3 @@ void nodeLock(const char* str) {
} }
} }
#endif #endif