summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-07 10:30:33 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-07 10:30:33 +1000
commit2a568846bd8f1c9e23e86e7570557eed6f18cf9f (patch)
tree3c152311311233eda762bb8b441ad44b50800cb8 /src/ui
parent610991455d335663de1dd6c0c6a3e0247ffd46df (diff)
downloadtangara-fw-2a568846bd8f1c9e23e86e7570557eed6f18cf9f.tar.gz
Cute brightness fade to avoid ugly startup :)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/include/ui_fsm.hpp17
-rw-r--r--src/ui/ui_fsm.cpp46
2 files changed, 36 insertions, 27 deletions
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index da6263b7..8b80f162 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -21,9 +21,7 @@ namespace ui {
class UiState : public tinyfsm::Fsm<UiState> {
public:
- static auto Init(drivers::GpioExpander* gpio_expander,
- const std::weak_ptr<drivers::RelativeWheel>& touchwheel,
- const std::weak_ptr<drivers::Display>& display) -> void;
+ static auto Init(drivers::GpioExpander* gpio_expander) -> bool;
virtual ~UiState() {}
@@ -42,23 +40,18 @@ class UiState : public tinyfsm::Fsm<UiState> {
protected:
static drivers::GpioExpander* sGpioExpander;
- static std::weak_ptr<drivers::RelativeWheel> sTouchWheel;
- static std::weak_ptr<drivers::Display> sDisplay;
+ static std::shared_ptr<drivers::TouchWheel> sTouchWheel;
+ static std::shared_ptr<drivers::RelativeWheel> sRelativeWheel;
+ static std::shared_ptr<drivers::Display> sDisplay;
static std::shared_ptr<Screen> sCurrentScreen;
};
namespace states {
-class PreBoot : public UiState {
- public:
- void react(const system_fsm::DisplayReady&) override;
- using UiState::react;
-};
-
class Splash : public UiState {
public:
- void entry() override;
+ void exit() override;
void react(const system_fsm::BootComplete&) override;
using UiState::react;
};
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index 5c59cf22..bdc1f89f 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -5,6 +5,8 @@
*/
#include "ui_fsm.hpp"
+#include <memory>
+#include "core/lv_obj.h"
#include "display.hpp"
#include "lvgl_task.hpp"
#include "relative_wheel.hpp"
@@ -17,33 +19,47 @@
namespace ui {
drivers::GpioExpander* UiState::sGpioExpander;
-std::weak_ptr<drivers::RelativeWheel> UiState::sTouchWheel;
-std::weak_ptr<drivers::Display> UiState::sDisplay;
+std::shared_ptr<drivers::TouchWheel> UiState::sTouchWheel;
+std::shared_ptr<drivers::RelativeWheel> UiState::sRelativeWheel;
+std::shared_ptr<drivers::Display> UiState::sDisplay;
std::shared_ptr<Screen> UiState::sCurrentScreen;
-auto UiState::Init(drivers::GpioExpander* gpio_expander,
- const std::weak_ptr<drivers::RelativeWheel>& touchwheel,
- const std::weak_ptr<drivers::Display>& display) -> void {
- assert(!touchwheel.expired());
- assert(!display.expired());
+auto UiState::Init(drivers::GpioExpander* gpio_expander) -> bool {
sGpioExpander = gpio_expander;
- sTouchWheel = touchwheel;
- sDisplay = display;
+
+ lv_init();
+ sDisplay.reset(
+ drivers::Display::Create(gpio_expander, drivers::displays::kST7735R));
+ if (sDisplay == nullptr) {
+ return false;
+ }
+
+ sTouchWheel.reset(drivers::TouchWheel::Create());
+ if (sTouchWheel != nullptr) {
+ sRelativeWheel.reset(new drivers::RelativeWheel(sTouchWheel.get()));
+ }
sCurrentScreen.reset(new screens::Splash());
- StartLvgl(sTouchWheel, sDisplay);
+ // Start the UI task even if init ultimately failed, so that we can show some
+ // kind of error screen to the user.
+ StartLvgl(sRelativeWheel, sDisplay);
+
+ if (sTouchWheel == nullptr) {
+ return false;
+ }
+ return true;
}
namespace states {
-void PreBoot::react(const system_fsm::DisplayReady& ev) {
- transit<Splash>();
+void Splash::exit() {
+ if (sDisplay != nullptr) {
+ sDisplay->SetDisplayOn(true);
+ }
}
-void Splash::entry() {}
-
void Splash::react(const system_fsm::BootComplete& ev) {
transit<Interactive>();
}
@@ -55,4 +71,4 @@ void Interactive::entry() {
} // namespace states
} // namespace ui
-FSM_INITIAL_STATE(ui::UiState, ui::states::PreBoot)
+FSM_INITIAL_STATE(ui::UiState, ui::states::Splash)