diff --git a/firmware/application/apps/ui_battinfo.cpp b/firmware/application/apps/ui_battinfo.cpp index 4d46367e..5f64d38b 100644 --- a/firmware/application/apps/ui_battinfo.cpp +++ b/firmware/application/apps/ui_battinfo.cpp @@ -31,6 +31,7 @@ using namespace portapack; namespace ui { +bool BattinfoView::needRun = true; void BattinfoView::focus() { button_exit.focus(); } @@ -99,6 +100,25 @@ BattinfoView::BattinfoView(NavigationView& nav) }; update_result(); + needRun = true; + thread = chThdCreateFromHeap(NULL, 512, NORMALPRIO + 10, BattinfoView::static_fn, this); } +msg_t BattinfoView::static_fn(void* arg) { + auto obj = static_cast(arg); + while (needRun) { + chThdSleepMilliseconds(16); + obj->on_timer(); + } + return 0; +} + +BattinfoView::~BattinfoView() { + needRun = false; + if (thread) { + chThdTerminate(thread); + chThdWait(thread); + thread = nullptr; + } +} } // namespace ui diff --git a/firmware/application/apps/ui_battinfo.hpp b/firmware/application/apps/ui_battinfo.hpp index dc5c3261..91e514c0 100644 --- a/firmware/application/apps/ui_battinfo.hpp +++ b/firmware/application/apps/ui_battinfo.hpp @@ -31,7 +31,13 @@ namespace ui { class BattinfoView : public View { public: + ~BattinfoView(); BattinfoView(NavigationView& nav); + BattinfoView(const BattinfoView&) = delete; + BattinfoView(BattinfoView&&) = delete; + BattinfoView& operator=(const BattinfoView&) = delete; + BattinfoView& operator=(BattinfoView&&) = delete; + void focus() override; std::string title() const override { return "Battery"; }; @@ -70,12 +76,9 @@ class BattinfoView : public View { Button button_exit{ {72, 17 * 16, 96, 32}, "Back"}; - - MessageHandlerRegistration message_handler_frame_sync{ - Message::ID::DisplayFrameSync, - [this](const Message* const) { - this->on_timer(); - }}; + static msg_t static_fn(void* arg); + static bool needRun; + Thread* thread{nullptr}; }; } /* namespace ui */