summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-22 16:00:53 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-22 16:00:53 +1000
commitdb9e5cce1fff82149a609939709a94ae02f349a8 (patch)
tree5dd6f5a636eb2e87bca84d7ceabbf09c893f23e1 /src/ui
parent5b99267cb9f0344e519956096867aea5468ecf9f (diff)
downloadtangara-fw-db9e5cce1fff82149a609939709a94ae02f349a8.tar.gz
Improve handling of the display
- Blank the display when locking to prevent burn-in - Delay turning the display on until *exactly* after the first lvgl flush - Init the display in the ui task to avoid blocking the rest of boot
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/include/ui_events.hpp7
-rw-r--r--src/ui/include/ui_fsm.hpp1
-rw-r--r--src/ui/lvgl_task.cpp1
-rw-r--r--src/ui/ui_fsm.cpp23
4 files changed, 22 insertions, 10 deletions
diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp
index 81e0543a..3d794edc 100644
--- a/src/ui/include/ui_events.hpp
+++ b/src/ui/include/ui_events.hpp
@@ -8,7 +8,9 @@
#include <memory>
#include "database.hpp"
+#include "gpios.hpp"
#include "index.hpp"
+#include "nvs.hpp"
#include "screen.hpp"
#include "tinyfsm.hpp"
@@ -32,6 +34,11 @@ struct DumpLuaStack : tinyfsm::Event {};
namespace internal {
+struct InitDisplay : tinyfsm::Event {
+ drivers::IGpios& gpios;
+ drivers::NvsStorage& nvs;
+};
+
struct ReindexDatabase : tinyfsm::Event {};
struct BackPressed : tinyfsm::Event {};
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 8eafc6e0..325aea8f 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -70,6 +70,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
void react(const system_fsm::KeyLockChanged&);
void react(const system_fsm::SamdUsbStatusChanged&);
+ void react(const internal::InitDisplay&);
void react(const internal::DismissAlerts&);
void react(const database::event::UpdateStarted&);
diff --git a/src/ui/lvgl_task.cpp b/src/ui/lvgl_task.cpp
index 4cf25c15..51da0179 100644
--- a/src/ui/lvgl_task.cpp
+++ b/src/ui/lvgl_task.cpp
@@ -84,7 +84,6 @@ auto UiTask::Main() -> void {
}
auto UiTask::input(std::shared_ptr<input::LvglInputDriver> input) -> void {
- assert(current_screen_);
input_ = input;
}
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index 1305e764..ceeb194d 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -267,6 +267,15 @@ lua::Property UiState::sUsbMassStorageBusy{false};
auto UiState::InitBootSplash(drivers::IGpios& gpios, drivers::NvsStorage& nvs)
-> bool {
+ events::Ui().Dispatch(internal::InitDisplay{
+ .gpios = gpios,
+ .nvs = nvs,
+ });
+ sTask.reset(UiTask::Start());
+ return true;
+}
+
+void UiState::react(const internal::InitDisplay& ev) {
// Init LVGL first, since the display driver registers itself with LVGL.
lv_init();
@@ -275,19 +284,15 @@ auto UiState::InitBootSplash(drivers::IGpios& gpios, drivers::NvsStorage& nvs)
// HACK: correct the display size for our prototypes.
// nvs.DisplaySize({161, 130});
- auto actual_size = nvs.DisplaySize();
+ auto actual_size = ev.nvs.DisplaySize();
init_data.width = actual_size.first.value_or(init_data.width);
init_data.height = actual_size.second.value_or(init_data.height);
-
- sDisplay.reset(drivers::Display::Create(gpios, init_data));
- if (sDisplay == nullptr) {
- return false;
- }
+ sDisplay.reset(drivers::Display::Create(ev.gpios, init_data));
sCurrentScreen.reset(new screens::Splash());
- sTask.reset(UiTask::Start());
- sDisplay->SetDisplayOn(!gpios.IsLocked());
- return true;
+
+ // Display will only actually come on after LVGL finishes its first flush.
+ sDisplay->SetDisplayOn(!ev.gpios.IsLocked());
}
void UiState::PushScreen(std::shared_ptr<Screen> screen) {