mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 19:05:44 +00:00
fsm WIP might work
This commit is contained in:
parent
509f9b6e2b
commit
c7894f3bc5
@ -15,7 +15,7 @@ From lower to higher power consumption.
|
|||||||
|
|
||||||
* light-sleep (LS) - CPU is suspended (RAM stays alive), radio is on, bluetooth is off, GPS is off. Note: currently GPS is not turned
|
* light-sleep (LS) - CPU is suspended (RAM stays alive), radio is on, bluetooth is off, GPS is off. Note: currently GPS is not turned
|
||||||
off during light sleep, but there is a TODO item to fix this.
|
off during light sleep, but there is a TODO item to fix this.
|
||||||
onEntry: setBluetoothOn(false), setGPSPower(false) - happens inside doLightSleep()
|
onEntry: setBluetoothOn(false), setGPSPower(false), doLightSleep()
|
||||||
onIdle: (if we wake because our led blink timer has expired) blink the led then go back to sleep until we sleep for ls_secs
|
onIdle: (if we wake because our led blink timer has expired) blink the led then go back to sleep until we sleep for ls_secs
|
||||||
onExit: setGPSPower(true), start trying to get gps lock: gps.startLock(), once lock arrives service.sendPosition(BROADCAST)
|
onExit: setGPSPower(true), start trying to get gps lock: gps.startLock(), once lock arrives service.sendPosition(BROADCAST)
|
||||||
|
|
||||||
|
@ -137,6 +137,12 @@ void GPS::doTask()
|
|||||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100);
|
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPS::startLock()
|
||||||
|
{
|
||||||
|
wantNewLocation = true;
|
||||||
|
setPeriod(1);
|
||||||
|
}
|
||||||
|
|
||||||
String GPS::getTimeStr()
|
String GPS::getTimeStr()
|
||||||
{
|
{
|
||||||
static char t[12]; // used to sprintf for Serial output
|
static char t[12]; // used to sprintf for Serial output
|
||||||
|
@ -38,6 +38,9 @@ public:
|
|||||||
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
|
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
|
||||||
void prepareSleep();
|
void prepareSleep();
|
||||||
|
|
||||||
|
/// Restart our lock attempt - try to get and broadcast a GPS reading ASAP
|
||||||
|
void startLock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readFromRTC();
|
void readFromRTC();
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
|
#include "GPS.h"
|
||||||
|
|
||||||
static void sdsEnter()
|
static void sdsEnter()
|
||||||
{
|
{
|
||||||
@ -23,7 +24,7 @@ static void sdsEnter()
|
|||||||
|
|
||||||
static void lsEnter()
|
static void lsEnter()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
// while we have bluetooth on, we can't do light sleep, but once off stay in light_sleep all the time
|
// while we have bluetooth on, we can't do light sleep, but once off stay in light_sleep all the time
|
||||||
// we will wake from light sleep on button press or interrupt from the RF95 radio
|
// we will wake from light sleep on button press or interrupt from the RF95 radio
|
||||||
if (!bluetoothOn && !is_screen_on() && service.radio.rf95.canSleep() && gps.canSleep())
|
if (!bluetoothOn && !is_screen_on() && service.radio.rf95.canSleep() && gps.canSleep())
|
||||||
@ -33,6 +34,8 @@ static void lsEnter()
|
|||||||
delay(msecstosleep);
|
delay(msecstosleep);
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
gps.prepareSleep(); // abandon in-process parsing
|
||||||
|
setGPSPower(false); // kill GPS power
|
||||||
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
|
doLightSleep(radioConfig.preferences.ls_secs * 1000LL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +46,8 @@ static void lsIdle()
|
|||||||
|
|
||||||
static void lsExit()
|
static void lsExit()
|
||||||
{
|
{
|
||||||
// nothing
|
setGPSPower(true); // restore GPS power
|
||||||
|
gps.startLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nbEnter()
|
static void nbEnter()
|
||||||
@ -54,7 +58,7 @@ static void nbEnter()
|
|||||||
static void darkEnter()
|
static void darkEnter()
|
||||||
{
|
{
|
||||||
DEBUG_MSG("screen timeout, turn it off for now...\n");
|
DEBUG_MSG("screen timeout, turn it off for now...\n");
|
||||||
screen.setOn(true);
|
screen.setOn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onEnter()
|
static void onEnter()
|
||||||
@ -76,31 +80,33 @@ static void screenPress()
|
|||||||
screen.onPress();
|
screen.onPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
State stateSDS(sdsEnter, NULL, NULL);
|
State stateSDS(sdsEnter, NULL, NULL, "SDS");
|
||||||
State stateLS(lsEnter, lsIdle, lsExit);
|
State stateLS(lsEnter, lsIdle, lsExit, "LS");
|
||||||
State stateNB(nbEnter, NULL, NULL);
|
State stateNB(nbEnter, NULL, NULL, "NB");
|
||||||
State stateDARK(darkEnter, NULL, NULL);
|
State stateDARK(darkEnter, NULL, NULL, "DARK");
|
||||||
State stateON(onEnter, NULL, onExit);
|
State stateON(onEnter, NULL, onExit, "ON");
|
||||||
Fsm powerFSM(&stateDARK);
|
Fsm powerFSM(&stateDARK);
|
||||||
|
|
||||||
void PowerFSM_setup()
|
void PowerFSM_setup()
|
||||||
{
|
{
|
||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL);
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
||||||
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing);
|
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
|
||||||
powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL);
|
powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
|
||||||
|
|
||||||
powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL);
|
powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL);
|
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL);
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress); // reenter On to restart our timers
|
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers
|
||||||
|
|
||||||
powerFSM.add_transition(&stateLS, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL);
|
powerFSM.add_transition(&stateLS, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL, "Received text");
|
||||||
powerFSM.add_transition(&stateNB, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL);
|
powerFSM.add_transition(&stateNB, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL, "Received text");
|
||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL);
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_RECEIVED_TEXT_MSG, NULL, "Received text");
|
||||||
|
|
||||||
powerFSM.add_transition(&stateNB, &stateDARK, EVENT_PACKET_FOR_PHONE, NULL);
|
powerFSM.add_transition(&stateNB, &stateDARK, EVENT_PACKET_FOR_PHONE, NULL, "Packet for phone");
|
||||||
|
|
||||||
powerFSM.add_timed_transition(&stateON, &stateDARK, radioConfig.preferences.screen_on_secs, NULL);
|
powerFSM.add_timed_transition(&stateON, &stateDARK, radioConfig.preferences.screen_on_secs, NULL, "Screen-on timeout");
|
||||||
|
|
||||||
powerFSM.add_timed_transition(&stateDARK, &stateNB, radioConfig.preferences.phone_timeout_secs, NULL);
|
powerFSM.add_timed_transition(&stateDARK, &stateNB, radioConfig.preferences.phone_timeout_secs, NULL, "Phone timeout");
|
||||||
|
|
||||||
|
powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state
|
||||||
}
|
}
|
@ -12,3 +12,5 @@
|
|||||||
#define EVENT_BOOT 6
|
#define EVENT_BOOT 6
|
||||||
|
|
||||||
extern Fsm powerFSM;
|
extern Fsm powerFSM;
|
||||||
|
|
||||||
|
void PowerFSM_setup();
|
@ -50,7 +50,6 @@ bool isUSBPowered = false;
|
|||||||
bool ssd1306_found = false;
|
bool ssd1306_found = false;
|
||||||
bool axp192_found = false;
|
bool axp192_found = false;
|
||||||
|
|
||||||
|
|
||||||
#define xstr(s) str(s)
|
#define xstr(s) str(s)
|
||||||
#define str(s) #s
|
#define str(s) #s
|
||||||
|
|
||||||
@ -58,7 +57,6 @@ bool axp192_found = false;
|
|||||||
// Application
|
// Application
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
void scanI2Cdevice(void)
|
void scanI2Cdevice(void)
|
||||||
{
|
{
|
||||||
byte err, addr;
|
byte err, addr;
|
||||||
@ -188,7 +186,6 @@ void axp192Init()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *getDeviceName()
|
const char *getDeviceName()
|
||||||
{
|
{
|
||||||
uint8_t dmac[6];
|
uint8_t dmac[6];
|
||||||
@ -208,7 +205,6 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
initDeepSleep();
|
initDeepSleep();
|
||||||
// delay(1000); FIXME - remove
|
|
||||||
|
|
||||||
#ifdef VEXT_ENABLE
|
#ifdef VEXT_ENABLE
|
||||||
pinMode(VEXT_ENABLE, OUTPUT);
|
pinMode(VEXT_ENABLE, OUTPUT);
|
||||||
@ -267,6 +263,9 @@ void setup()
|
|||||||
|
|
||||||
setBluetoothEnable(false);
|
setBluetoothEnable(false);
|
||||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||||
|
|
||||||
|
PowerFSM_setup();
|
||||||
|
powerFSM.trigger(EVENT_BOOT); // transition to ON, FIXME, only do this for cold boots, not waking from SDS
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ledBlinker()
|
uint32_t ledBlinker()
|
||||||
@ -303,6 +302,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop?
|
uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop?
|
||||||
|
|
||||||
|
powerFSM.run_machine();
|
||||||
gps.loop();
|
gps.loop();
|
||||||
screen.loop();
|
screen.loop();
|
||||||
service.loop();
|
service.loop();
|
||||||
|
@ -213,8 +213,6 @@ void doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
|
|||||||
uint64_t sleepUsec = sleepMsec * 1000LL;
|
uint64_t sleepUsec = sleepMsec * 1000LL;
|
||||||
|
|
||||||
setBluetoothEnable(false); // has to be off before calling light sleep
|
setBluetoothEnable(false); // has to be off before calling light sleep
|
||||||
gps.prepareSleep(); // abandon in-process parsing
|
|
||||||
setGPSPower(false); // kill GPS power
|
|
||||||
setLed(false); // Never leave led on while in light sleep
|
setLed(false); // Never leave led on while in light sleep
|
||||||
|
|
||||||
// NOTE! ESP docs say we must disable bluetooth and wifi before light sleep
|
// NOTE! ESP docs say we must disable bluetooth and wifi before light sleep
|
||||||
@ -231,8 +229,6 @@ void doLightSleep(uint64_t sleepMsec) // FIXME, use a more reasonable default
|
|||||||
esp_sleep_enable_timer_wakeup(sleepUsec);
|
esp_sleep_enable_timer_wakeup(sleepUsec);
|
||||||
esp_light_sleep_start();
|
esp_light_sleep_start();
|
||||||
DEBUG_MSG("Exit light sleep\n");
|
DEBUG_MSG("Exit light sleep\n");
|
||||||
|
|
||||||
setGPSPower(true); // restore GPS power
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
void doDeepSleep(uint64_t msecToWake);
|
void doDeepSleep(uint64_t msecToWake);
|
||||||
void doLightSleep(uint64_t msecToWake);
|
void doLightSleep(uint64_t msecToWake);
|
||||||
void setBluetoothEnable(bool on);
|
void setBluetoothEnable(bool on);
|
||||||
|
void setGPSPower(bool on);
|
||||||
|
|
||||||
// Perform power on init that we do on each wake from deep sleep
|
// Perform power on init that we do on each wake from deep sleep
|
||||||
void initDeepSleep();
|
void initDeepSleep();
|
||||||
|
Loading…
Reference in New Issue
Block a user