WIP light sleep kinda works

1.2-legacy
geeksville 2020-02-22 14:45:58 -08:00
rodzic fe2ca65a11
commit ca37e50362
3 zmienionych plików z 24 dodań i 8 usunięć

Wyświetl plik

@ -34,14 +34,21 @@ static void lsEnter()
delay(msecstosleep);
} */
while (!service.radio.rf95.canSleep())
delay(10); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives)
gps.prepareSleep(); // abandon in-process parsing
setGPSPower(false); // kill GPS power
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
}
static void lsIdle()
{
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
// FIXME - blink led when we occasionally wake from timer, then go back to light sleep
// Regardless of why we woke (for now) just transition to NB
powerFSM.trigger(EVENT_WAKE_TIMER);
}
static void lsExit()
@ -53,6 +60,8 @@ static void lsExit()
static void nbEnter()
{
setBluetoothEnable(false);
// FIXME - check if we already have packets for phone and immediately trigger EVENT_PACKETS_FOR_PHONE
}
static void darkEnter()
@ -90,10 +99,15 @@ void PowerFSM_setup()
{
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
// powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
powerFSM.add_transition(&stateNB, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet, resetting win wake");
powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
// powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers

Wyświetl plik

@ -207,7 +207,7 @@ void setBluetoothEnable(bool on)
*
* Returns (after restoring hw state) when the user presses a button or we get a LoRa interrupt
*/
void doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
{
DEBUG_MSG("Enter light sleep\n");
uint64_t sleepUsec = sleepMsec * 1000LL;
@ -225,10 +225,11 @@ void doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
#ifdef PMU_IRQ
gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq
#endif
esp_sleep_enable_gpio_wakeup();
esp_sleep_enable_timer_wakeup(sleepUsec);
esp_light_sleep_start();
assert(esp_sleep_enable_gpio_wakeup() == ESP_OK);
assert(esp_sleep_enable_timer_wakeup(sleepUsec) == ESP_OK);
assert(esp_light_sleep_start() == ESP_OK);
DEBUG_MSG("Exit light sleep\n");
return esp_sleep_get_wakeup_cause();
}
#if 0

Wyświetl plik

@ -1,9 +1,10 @@
#pragma once
#include "Arduino.h"
#include "esp_sleep.h"
void doDeepSleep(uint64_t msecToWake);
void doLightSleep(uint64_t msecToWake);
esp_sleep_wakeup_cause_t doLightSleep(uint64_t msecToWake);
void setBluetoothEnable(bool on);
void setGPSPower(bool on);