mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
change screen into a periodictask, so it can be used with the scheduler
This commit is contained in:
parent
a6b98bec1f
commit
20461807f3
@ -472,7 +472,7 @@ void setup()
|
|||||||
ssd1306_found = false; // forget we even have the hardware
|
ssd1306_found = false; // forget we even have the hardware
|
||||||
|
|
||||||
if (ssd1306_found)
|
if (ssd1306_found)
|
||||||
screen_setup();
|
screen.setup();
|
||||||
|
|
||||||
// Init GPS
|
// Init GPS
|
||||||
gps.setup();
|
gps.setup();
|
||||||
@ -531,8 +531,12 @@ 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?
|
||||||
|
|
||||||
gps.loop();
|
gps.loop();
|
||||||
msecstosleep = min(screen_loop(), msecstosleep);
|
screen.loop();
|
||||||
service.loop();
|
service.loop();
|
||||||
|
|
||||||
|
if (nodeDB.updateGUI || nodeDB.updateTextMessage)
|
||||||
|
screen.doWakeScreen();
|
||||||
|
|
||||||
ledPeriodic.loop();
|
ledPeriodic.loop();
|
||||||
// axpDebugOutput.loop();
|
// axpDebugOutput.loop();
|
||||||
loopBLE();
|
loopBLE();
|
||||||
|
@ -51,6 +51,15 @@ OLEDDisplayUi ui(&dispdev);
|
|||||||
// A text message frame + debug frame + all the node infos
|
// A text message frame + debug frame + all the node infos
|
||||||
FrameCallback nonBootFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
|
FrameCallback nonBootFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
|
||||||
|
|
||||||
|
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 wakeScreen;
|
||||||
|
static bool showingBootScreen = true; // start by showing the bootscreen
|
||||||
|
|
||||||
|
uint32_t lastPressMs;
|
||||||
|
|
||||||
bool is_screen_on() { return screenOn; }
|
bool is_screen_on() { return screenOn; }
|
||||||
|
|
||||||
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState *state)
|
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState *state)
|
||||||
@ -521,7 +530,15 @@ void screen_print(const char *text)
|
|||||||
// ui.update();
|
// ui.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void screen_setup()
|
|
||||||
|
|
||||||
|
|
||||||
|
void Screen::doWakeScreen() {
|
||||||
|
wakeScreen = true;
|
||||||
|
setPeriod(1); // wake asap
|
||||||
|
}
|
||||||
|
|
||||||
|
void Screen::setup()
|
||||||
{
|
{
|
||||||
#ifdef I2C_SDA
|
#ifdef I2C_SDA
|
||||||
// Display instance
|
// Display instance
|
||||||
@ -572,13 +589,6 @@ void screen_setup()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
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 wakeScreen;
|
|
||||||
static bool showingBootScreen = true; // start by showing the bootscreen
|
|
||||||
|
|
||||||
uint32_t lastPressMs;
|
|
||||||
|
|
||||||
/// Turn off the screen this many ms after last press or wake
|
/// Turn off the screen this many ms after last press or wake
|
||||||
#define SCREEN_SLEEP_MS (60 * 1000)
|
#define SCREEN_SLEEP_MS (60 * 1000)
|
||||||
@ -588,20 +598,26 @@ uint32_t lastPressMs;
|
|||||||
|
|
||||||
static uint32_t targetFramerate = IDLE_FRAMERATE;
|
static uint32_t targetFramerate = IDLE_FRAMERATE;
|
||||||
|
|
||||||
uint32_t screen_loop()
|
|
||||||
{
|
|
||||||
if (!disp) // If we don't have a screen, don't ever spend any CPU for us
|
|
||||||
return UINT32_MAX;
|
|
||||||
|
|
||||||
if (wakeScreen || nodeDB.updateTextMessage) // If a new text message arrived, turn the screen on immedately
|
|
||||||
|
void Screen::doTask()
|
||||||
|
{
|
||||||
|
if (!disp) { // If we don't have a screen, don't ever spend any CPU for us
|
||||||
|
setPeriod(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wakeScreen) // If a new text message arrived, turn the screen on immedately
|
||||||
{
|
{
|
||||||
lastPressMs = millis(); // if we were told to wake the screen, reset the press timeout
|
lastPressMs = millis(); // if we were told to wake the screen, reset the press timeout
|
||||||
screen_on(); // make sure the screen is not asleep
|
screen_on(); // make sure the screen is not asleep
|
||||||
wakeScreen = false;
|
wakeScreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!screenOn) // If we didn't just wake and the screen is still off, then bail
|
if (!screenOn) { // If we didn't just wake and the screen is still off, then stop updating until it is on again
|
||||||
return UINT32_MAX;
|
setPeriod(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Switch to a low framerate (to save CPU) when we are not in transition
|
// Switch to a low framerate (to save CPU) when we are not in transition
|
||||||
// but we should only call setTargetFPS when framestate changes, because otherwise that breaks
|
// but we should only call setTargetFPS when framestate changes, because otherwise that breaks
|
||||||
@ -649,7 +665,7 @@ uint32_t screen_loop()
|
|||||||
// If we are scrolling we need to be called soon, otherwise just 1 fps (to save CPU)
|
// If we are scrolling we need to be called soon, otherwise just 1 fps (to save CPU)
|
||||||
// We also ask to be called twice as fast as we really need so that any rounding errors still result
|
// We also ask to be called twice as fast as we really need so that any rounding errors still result
|
||||||
// with the correct framerate
|
// with the correct framerate
|
||||||
return 1000 / targetFramerate / 2;
|
setPeriod(1000 / targetFramerate / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the bluetooth PIN screen
|
// Show the bluetooth PIN screen
|
||||||
@ -661,7 +677,7 @@ void screen_start_bluetooth(uint32_t pin)
|
|||||||
|
|
||||||
DEBUG_MSG("showing bluetooth screen\n");
|
DEBUG_MSG("showing bluetooth screen\n");
|
||||||
showingBluetooth = true;
|
showingBluetooth = true;
|
||||||
wakeScreen = true;
|
screen.doWakeScreen();
|
||||||
|
|
||||||
ui.setFrames(btFrames, 1); // Just show the bluetooth frame
|
ui.setFrames(btFrames, 1); // Just show the bluetooth frame
|
||||||
// we rely on our main loop to show this screen (because we are invoked deep inside of bluetooth callbacks)
|
// we rely on our main loop to show this screen (because we are invoked deep inside of bluetooth callbacks)
|
||||||
@ -703,7 +719,7 @@ void screen_press()
|
|||||||
// screen_start_bluetooth(123456);
|
// screen_start_bluetooth(123456);
|
||||||
|
|
||||||
lastPressMs = millis();
|
lastPressMs = millis();
|
||||||
wakeScreen = true;
|
screen.doWakeScreen();
|
||||||
|
|
||||||
// If screen was off, just wake it, otherwise advance to next frame
|
// If screen was off, just wake it, otherwise advance to next frame
|
||||||
// If we are in a transition, the press must have bounced, drop it.
|
// If we are in a transition, the press must have bounced, drop it.
|
||||||
|
24
src/screen.h
24
src/screen.h
@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "PeriodicTask.h"
|
||||||
|
|
||||||
void screen_print(const char * text);
|
void screen_print(const char * text);
|
||||||
|
|
||||||
/// @return how many msecs can we sleep before we want service again
|
void screen_on(), screen_off(), screen_press();
|
||||||
uint32_t screen_loop();
|
|
||||||
|
|
||||||
void screen_setup(), screen_on(), screen_off(), screen_press();
|
|
||||||
|
|
||||||
// Show the bluetooth PIN screen
|
// Show the bluetooth PIN screen
|
||||||
void screen_start_bluetooth(uint32_t pin);
|
void screen_start_bluetooth(uint32_t pin);
|
||||||
@ -14,3 +13,20 @@ void screen_start_bluetooth(uint32_t pin);
|
|||||||
void screen_set_frames();
|
void screen_set_frames();
|
||||||
|
|
||||||
bool is_screen_on();
|
bool is_screen_on();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slowly I'm moving screen crap into this class
|
||||||
|
*/
|
||||||
|
class Screen : public PeriodicTask
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
void setup();
|
||||||
|
|
||||||
|
virtual void doTask();
|
||||||
|
|
||||||
|
/// Turn on the screen asap
|
||||||
|
void doWakeScreen();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Screen screen;
|
Loading…
Reference in New Issue
Block a user