Skip to content

Commit

Permalink
Fix #2: allow LMIC to finish up before sleeping
Browse files Browse the repository at this point in the history
Otherwise during joins and other unexepected events, we'll sleep before the LMIC is ready.
  • Loading branch information
terrillmoore authored Feb 10, 2022
1 parent 7b38ec1 commit 54f0e4c
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions catena4618m201_simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,35 @@ void doDeepSleep(osjob_t *pJob)
fDeepSleepTest ? CATCFG_T_CYCLE_TEST : gTxCycle
);

/* ok... now it's time for a deep sleep */
gLed.Set(LedPattern::Off);
deepSleepPrepare();
/* wait for LMIC to settle down */
while (sleepInterval > 0)
{
if (! os_queryTimeCriticalJobs(sec2osticks(sleepInterval)))
break;

/* can't sleep yet, just idle */
for (unsigned i = 1000; i > 0; --i)
{
os_runloop_once();
gCatena.poll();
delay(1);
}
sleepInterval -= 1;
}

/* sleep */
gCatena.Sleep(sleepInterval);
/* the LMIC is idle, or the sleep interval is exhausted. if idle and there's still time to sleep, sleep */
if (sleepInterval > 0)
{
/* ok... now it's time for a deep sleep */
gLed.Set(LedPattern::Off);
deepSleepPrepare();

/* recover from sleep */
deepSleepRecovery();
gCatena.Sleep(sleepInterval);

/* recover from sleep */
deepSleepRecovery();
}

/* and now... we're awake again. trigger another measurement */
sleepDoneCb(pJob);
}
Expand Down

0 comments on commit 54f0e4c

Please sign in to comment.