From 53765298e1c5c2f455ac95aeb344e711cfb5a515 Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 18 Mar 2020 15:00:17 -0700 Subject: [PATCH] add a real BOOT state, to avoid glitch from redrawing bootscreen twice also its the right thing to do ;-) --- src/PowerFSM.cpp | 13 ++++++++++--- src/PowerFSM.h | 4 ++-- src/main.cpp | 13 ++++++++----- src/screen.cpp | 18 +++++++++++++++--- src/screen.h | 3 +++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 7080bb4ad..0115008fc 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -25,7 +25,7 @@ static void sdsEnter() static void lsEnter() { - DEBUG_MSG("lsEnter begin\n"); + DEBUG_MSG("lsEnter begin, ls_secs=%u\n", radioConfig.preferences.ls_secs); screen.setOn(false); while (!service.radio.rf95.canSleep()) @@ -124,16 +124,23 @@ static void screenPress() screen.onPress(); } + +static void bootEnter() { +} + State stateSDS(sdsEnter, NULL, NULL, "SDS"); State stateLS(lsEnter, lsIdle, lsExit, "LS"); State stateNB(nbEnter, NULL, NULL, "NB"); State stateDARK(darkEnter, NULL, NULL, "DARK"); +State stateBOOT(bootEnter , NULL, NULL, "BOOT"); State stateON(onEnter, NULL, NULL, "ON"); -Fsm powerFSM(&stateDARK); +Fsm powerFSM(&stateBOOT); void PowerFSM_setup() { - powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot"); + powerFSM.add_timed_transition(&stateBOOT, &stateON, 3 * 1000, NULL, + "boot timeout"); + powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer"); // Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it diff --git a/src/PowerFSM.h b/src/PowerFSM.h index f8a013dd2..c1bb7a87f 100644 --- a/src/PowerFSM.h +++ b/src/PowerFSM.h @@ -4,12 +4,12 @@ // See sw-design.md for documentation -#define EVENT_PRESS 1 +#define EVENT_PRESS 1 #define EVENT_WAKE_TIMER 2 #define EVENT_RECEIVED_PACKET 3 #define EVENT_PACKET_FOR_PHONE 4 #define EVENT_RECEIVED_TEXT_MSG 5 -#define EVENT_BOOT 6 +// #define EVENT_BOOT 6 // now done with a timed transition #define EVENT_BLUETOOTH_PAIR 7 #define EVENT_NODEDB_UPDATED 8 // NodeDB has a big enough change that we think you should turn on the screen #define EVENT_CONTACT_FROM_PHONE 9 // the phone just talked to us over bluetooth diff --git a/src/main.cpp b/src/main.cpp index 28785228b..5d4a35784 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,18 +243,21 @@ void setup() if (ssd1306_found) screen.setup(); + screen.showBootscreen(); + + // Now that the screen is on, show our bootscreen + screen_print("Started...\n"); + // Init GPS gps.setup(); - screen_print("Started...\n"); - service.init(); + // This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values + PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS + // setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state 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 } void initBluetooth() diff --git a/src/screen.cpp b/src/screen.cpp index 977ef2d83..915b17dae 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -57,7 +57,7 @@ Screen screen; static bool showingBluetooth; /// If set to true (possibly from an ISR), we should turn on the screen the next time our idle loop runs. -static bool showingBootScreen = true; // start by showing the bootscreen +static bool showingBootScreen = false; // start by showing the bootscreen bool Screen::isOn() { return screenOn; } @@ -584,7 +584,7 @@ void Screen::setup() // Scroll buffer dispdev.setLogBuffer(3, 32); - setOn(true); // update our screenOn bool + setOn(false); // start with the screen off #ifdef BICOLOR_DISPLAY dispdev.flipScreenVertically(); // looks better without this on lora32 @@ -593,10 +593,22 @@ void Screen::setup() // dispdev.setFont(Custom_ArialMT_Plain_10); ui.disableAutoTransition(); // we now require presses - ui.update(); // force an immediate draw of the bootscreen, because on some ssd1306 clones, the first draw command is discarded #endif } +void Screen::showBootscreen() { + if(!disp) + return; + + showingBootScreen = true; + setOn(true); + + // Add frames - we subtract one from the framecount so there won't be a visual glitch when we take the boot screen out of the sequence. + ui.setFrames(bootFrames, bootFrameCount); + + ui.update(); // force an immediate draw of the bootscreen, because on some ssd1306 clones, the first draw command is discarded +} + #define TRANSITION_FRAMERATE 30 // fps #define IDLE_FRAMERATE 10 // in fps diff --git a/src/screen.h b/src/screen.h index 9637f9284..1e4431da5 100644 --- a/src/screen.h +++ b/src/screen.h @@ -38,6 +38,9 @@ public: /// Rebuilt our list of screens void setFrames(); + + /// Show our logo (and turn the screen on) + void showBootscreen(); private: };