|
|
|
|
@@ -57,21 +57,21 @@ static bool isPowered()
|
|
|
|
|
|
|
|
|
|
static void sdsEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: SDS");
|
|
|
|
|
LOG_POWERFSM("State: SDS");
|
|
|
|
|
// FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw
|
|
|
|
|
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lowBattSDSEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: Lower batt SDS");
|
|
|
|
|
LOG_POWERFSM("State: Lower batt SDS");
|
|
|
|
|
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, true);
|
|
|
|
|
}
|
|
|
|
|
extern Power *power;
|
|
|
|
|
|
|
|
|
|
static void shutdownEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: SHUTDOWN");
|
|
|
|
|
LOG_POWERFSM("State: SHUTDOWN");
|
|
|
|
|
shutdownAtMsec = millis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -81,7 +81,7 @@ static uint32_t secsSlept;
|
|
|
|
|
|
|
|
|
|
static void lsEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_INFO("lsEnter begin, ls_secs=%u", config.power.ls_secs);
|
|
|
|
|
LOG_POWERFSM("lsEnter begin, ls_secs=%u", config.power.ls_secs);
|
|
|
|
|
if (screen)
|
|
|
|
|
screen->setOn(false);
|
|
|
|
|
secsSlept = 0; // How long have we been sleeping this time
|
|
|
|
|
@@ -155,12 +155,12 @@ static void lsIdle()
|
|
|
|
|
|
|
|
|
|
static void lsExit()
|
|
|
|
|
{
|
|
|
|
|
LOG_INFO("Exit state: LS");
|
|
|
|
|
LOG_POWERFSM("State: lsExit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void nbEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: NB");
|
|
|
|
|
LOG_POWERFSM("State: nbEnter");
|
|
|
|
|
if (screen)
|
|
|
|
|
screen->setOn(false);
|
|
|
|
|
#ifdef ARCH_ESP32
|
|
|
|
|
@@ -173,6 +173,7 @@ static void nbEnter()
|
|
|
|
|
|
|
|
|
|
static void darkEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_POWERFSM("State: darkEnter");
|
|
|
|
|
setBluetoothEnable(true);
|
|
|
|
|
if (screen)
|
|
|
|
|
screen->setOn(false);
|
|
|
|
|
@@ -180,7 +181,7 @@ static void darkEnter()
|
|
|
|
|
|
|
|
|
|
static void serialEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: SERIAL");
|
|
|
|
|
LOG_POWERFSM("State: serialEnter");
|
|
|
|
|
setBluetoothEnable(false);
|
|
|
|
|
if (screen) {
|
|
|
|
|
screen->setOn(true);
|
|
|
|
|
@@ -189,13 +190,14 @@ static void serialEnter()
|
|
|
|
|
|
|
|
|
|
static void serialExit()
|
|
|
|
|
{
|
|
|
|
|
LOG_POWERFSM("State: serialExit");
|
|
|
|
|
// Turn bluetooth back on when we leave serial stream API
|
|
|
|
|
setBluetoothEnable(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void powerEnter()
|
|
|
|
|
{
|
|
|
|
|
// LOG_DEBUG("State: POWER");
|
|
|
|
|
LOG_POWERFSM("State: powerEnter");
|
|
|
|
|
if (!isPowered()) {
|
|
|
|
|
// If we got here, we are in the wrong state - we should be in powered, let that state handle things
|
|
|
|
|
LOG_INFO("Loss of power in Powered");
|
|
|
|
|
@@ -210,6 +212,7 @@ static void powerEnter()
|
|
|
|
|
|
|
|
|
|
static void powerIdle()
|
|
|
|
|
{
|
|
|
|
|
// LOG_POWERFSM("State: powerIdle"); // very chatty
|
|
|
|
|
if (!isPowered()) {
|
|
|
|
|
// If we got here, we are in the wrong state
|
|
|
|
|
LOG_INFO("Loss of power in Powered");
|
|
|
|
|
@@ -219,12 +222,13 @@ static void powerIdle()
|
|
|
|
|
|
|
|
|
|
static void powerExit()
|
|
|
|
|
{
|
|
|
|
|
LOG_POWERFSM("State: powerExit");
|
|
|
|
|
setBluetoothEnable(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void onEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: ON");
|
|
|
|
|
LOG_POWERFSM("State: onEnter");
|
|
|
|
|
if (screen)
|
|
|
|
|
screen->setOn(true);
|
|
|
|
|
setBluetoothEnable(true);
|
|
|
|
|
@@ -232,6 +236,7 @@ static void onEnter()
|
|
|
|
|
|
|
|
|
|
static void onIdle()
|
|
|
|
|
{
|
|
|
|
|
LOG_POWERFSM("State: onIdle");
|
|
|
|
|
if (isPowered()) {
|
|
|
|
|
// If we got here, we are in the wrong state - we should be in powered, let that state handle things
|
|
|
|
|
powerFSM.trigger(EVENT_POWER_CONNECTED);
|
|
|
|
|
@@ -240,7 +245,7 @@ static void onIdle()
|
|
|
|
|
|
|
|
|
|
static void bootEnter()
|
|
|
|
|
{
|
|
|
|
|
LOG_DEBUG("State: BOOT");
|
|
|
|
|
LOG_POWERFSM("State: bootEnter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
State stateSHUTDOWN(shutdownEnter, NULL, NULL, "SHUTDOWN");
|
|
|
|
|
@@ -317,11 +322,6 @@ void PowerFSM_setup()
|
|
|
|
|
// if any packet destined for phone arrives, turn on bluetooth at least
|
|
|
|
|
powerFSM.add_transition(&stateNB, &stateDARK, EVENT_PACKET_FOR_PHONE, NULL, "Packet for phone");
|
|
|
|
|
|
|
|
|
|
// Removed 2.7: we don't show the nodes individually for every node on the screen anymore
|
|
|
|
|
// powerFSM.add_transition(&stateNB, &stateON, EVENT_NODEDB_UPDATED, NULL, "NodeDB update");
|
|
|
|
|
// powerFSM.add_transition(&stateDARK, &stateON, EVENT_NODEDB_UPDATED, NULL, "NodeDB update");
|
|
|
|
|
// powerFSM.add_transition(&stateON, &stateON, EVENT_NODEDB_UPDATED, NULL, "NodeDB update");
|
|
|
|
|
|
|
|
|
|
// Show the received text message
|
|
|
|
|
powerFSM.add_transition(&stateLS, &stateON, EVENT_RECEIVED_MSG, NULL, "Received text");
|
|
|
|
|
powerFSM.add_transition(&stateNB, &stateON, EVENT_RECEIVED_MSG, NULL, "Received text");
|
|
|
|
|
|