Skip to content

Commit

Permalink
Added sleepInterrupted Flag to determine if SleepNode was Interrupted
Browse files Browse the repository at this point in the history
if (network.sleepInterrupted) {
   // do something, like write a different packet
   }
  • Loading branch information
dsbaha committed Jan 31, 2015
1 parent ee34bf1 commit ce3b522
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <avr/sleep.h>
#include <avr/power.h>
volatile byte sleep_cycles_remaining;
volatile bool wasInterrupted;
#endif


Expand Down Expand Up @@ -1253,8 +1254,8 @@ uint64_t pipe_address( uint16_t node, uint8_t pipe )
#if !defined(__arm__) && !defined(__ARDUINO_X86__)

void wakeUp(){
sleep_disable();
sleep_cycles_remaining = 0;
wasInterrupted = true;
}

ISR(WDT_vect){
Expand All @@ -1269,6 +1270,8 @@ void RF24Network::sleepNode( unsigned int cycles, int interruptPin ){
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
if(interruptPin != 255){
wasInterrupted = false; //Reset Flag
sleepInterrupted = false; //Reset Flag
attachInterrupt(interruptPin,wakeUp, LOW);
}
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
Expand All @@ -1286,6 +1289,8 @@ void RF24Network::sleepNode( unsigned int cycles, int interruptPin ){
#else
WDTCSR &= ~_BV(WDIE);
#endif

if (wasInterrupted) sleepInterrupted = true;
}

void RF24Network::setup_watchdog(uint8_t prescalar){
Expand Down
5 changes: 5 additions & 0 deletions RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ class RF24Network
*/
bool write(RF24NetworkHeader& header,const void* message, size_t len, uint16_t writeDirect);

#if defined ENABLE_SLEEP_MODE

/**
* Sleep this node - For AVR devices only
* @note NEW - Nodes can now be slept while the radio is not actively transmitting. This must be manually enabled by uncommenting
Expand Down Expand Up @@ -463,6 +465,9 @@ class RF24Network
*/
void setup_watchdog(uint8_t prescalar);

bool sleepInterrupted;

#endif

/**
* This node's parent address
Expand Down

0 comments on commit ce3b522

Please sign in to comment.