mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
WIP light sleep kinda works
This commit is contained in:
parent
fe2ca65a11
commit
ca37e50362
@ -34,14 +34,21 @@ static void lsEnter()
|
|||||||
delay(msecstosleep);
|
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
|
gps.prepareSleep(); // abandon in-process parsing
|
||||||
setGPSPower(false); // kill GPS power
|
setGPSPower(false); // kill GPS power
|
||||||
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lsIdle()
|
static void lsIdle()
|
||||||
{
|
{
|
||||||
|
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
|
||||||
|
|
||||||
// FIXME - blink led when we occasionally wake from timer, then go back to light sleep
|
// 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()
|
static void lsExit()
|
||||||
@ -53,6 +60,8 @@ static void lsExit()
|
|||||||
static void nbEnter()
|
static void nbEnter()
|
||||||
{
|
{
|
||||||
setBluetoothEnable(false);
|
setBluetoothEnable(false);
|
||||||
|
|
||||||
|
// FIXME - check if we already have packets for phone and immediately trigger EVENT_PACKETS_FOR_PHONE
|
||||||
}
|
}
|
||||||
|
|
||||||
static void darkEnter()
|
static void darkEnter()
|
||||||
@ -90,10 +99,15 @@ void PowerFSM_setup()
|
|||||||
{
|
{
|
||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
||||||
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
|
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(&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(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateDARK, &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
|
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers
|
||||||
|
@ -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
|
* 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");
|
DEBUG_MSG("Enter light sleep\n");
|
||||||
uint64_t sleepUsec = sleepMsec * 1000LL;
|
uint64_t sleepUsec = sleepMsec * 1000LL;
|
||||||
@ -225,10 +225,11 @@ void doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
|
|||||||
#ifdef PMU_IRQ
|
#ifdef PMU_IRQ
|
||||||
gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq
|
gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq
|
||||||
#endif
|
#endif
|
||||||
esp_sleep_enable_gpio_wakeup();
|
assert(esp_sleep_enable_gpio_wakeup() == ESP_OK);
|
||||||
esp_sleep_enable_timer_wakeup(sleepUsec);
|
assert(esp_sleep_enable_timer_wakeup(sleepUsec) == ESP_OK);
|
||||||
esp_light_sleep_start();
|
assert(esp_light_sleep_start() == ESP_OK);
|
||||||
DEBUG_MSG("Exit light sleep\n");
|
DEBUG_MSG("Exit light sleep\n");
|
||||||
|
return esp_sleep_get_wakeup_cause();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "esp_sleep.h"
|
||||||
|
|
||||||
void doDeepSleep(uint64_t msecToWake);
|
void doDeepSleep(uint64_t msecToWake);
|
||||||
void doLightSleep(uint64_t msecToWake);
|
esp_sleep_wakeup_cause_t doLightSleep(uint64_t msecToWake);
|
||||||
void setBluetoothEnable(bool on);
|
void setBluetoothEnable(bool on);
|
||||||
void setGPSPower(bool on);
|
void setGPSPower(bool on);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user