Hello peterm,
Thank you for the link, after reading what was discussed it seems that Heltec is doing that to make sure that all events are being processed before going to sleep… they must have a reason for implementing this… so to keep the same behavior and give back the proper behavior when using lowpowerHandler() which continues to execute code right where it slept… i propose the below solution, tell me what you all think?
void TimerLowPowerHandler(bool *wokeUp)
{
if (HasLoopedThroughMain < 5)
{
HasLoopedThroughMain++;
*wokeUp = false;
}
else
{
*wokeUp = true;
HasLoopedThroughMain = 0;
lowPowerHandler();
}
}
and then we would call the function as follow:
bool wokeUp;
LoRaWAN.sleep(&wokeUp);
if (wokeUp)
{
printf("\n Woke up from sleep let's continue the work");
}
update the sleep function in LoRaWan_APP.c as well and it’s corresponding header to:
void LoRaWanClass::sleep(bool *wokeUp)
{
// return TimerLowPowerHandler();
return TimerLowPowerHandler(wokeUp);
}
someone might ask why do we need to know that we have woken after a sleep. well consider the fact that if one decides to use the watchdog, which should be disabled before going to sleep and enabled while the system is awake… in that situation we could do this:
void setup(){
/* Enable the WDT, autofeed set to false we will feed it in the loop, if this is set to true the board will appear to neve go to sleep since the WDT will wake the board up every 2.4 sec i think to feed the WDT not a power friendly at all*/
innerWdtEnable(false);
//your code here...
}
void loop(){
....
case DEVICE_STATE_SLEEP:
{
CySysWdtDisable(); //disable the watchdog before going to sleep
bool wokeUp;
LoRaWAN.sleep(&wokeUp); //go to sleep and watch the wokeUp variable, should be true after we are woken up.
if (wokeUp)
{
CySysWdtEnable(); //enable the watchdog since we have woken up.
printf("\n Woke up from sleep let's continue the work");
}
break;
}
feedInnerWdt();// feed the WDT at the end of the loop so it the code locks up this won't trigger and the program resets.
}
What do you all think?