MsgDblReg fix (#2144)

This commit is contained in:
Totoo 2024-05-11 10:52:35 +02:00 committed by GitHub
parent 963c6e5238
commit e666eb1797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 6 deletions

View File

@ -31,6 +31,7 @@ using namespace portapack;
namespace ui { namespace ui {
bool BattinfoView::needRun = true;
void BattinfoView::focus() { void BattinfoView::focus() {
button_exit.focus(); button_exit.focus();
} }
@ -99,6 +100,25 @@ BattinfoView::BattinfoView(NavigationView& nav)
}; };
update_result(); 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<BattinfoView*>(arg);
while (needRun) {
chThdSleepMilliseconds(16);
obj->on_timer();
}
return 0;
}
BattinfoView::~BattinfoView() {
needRun = false;
if (thread) {
chThdTerminate(thread);
chThdWait(thread);
thread = nullptr;
}
}
} // namespace ui } // namespace ui

View File

@ -31,7 +31,13 @@
namespace ui { namespace ui {
class BattinfoView : public View { class BattinfoView : public View {
public: public:
~BattinfoView();
BattinfoView(NavigationView& nav); BattinfoView(NavigationView& nav);
BattinfoView(const BattinfoView&) = delete;
BattinfoView(BattinfoView&&) = delete;
BattinfoView& operator=(const BattinfoView&) = delete;
BattinfoView& operator=(BattinfoView&&) = delete;
void focus() override; void focus() override;
std::string title() const override { return "Battery"; }; std::string title() const override { return "Battery"; };
@ -70,12 +76,9 @@ class BattinfoView : public View {
Button button_exit{ Button button_exit{
{72, 17 * 16, 96, 32}, {72, 17 * 16, 96, 32},
"Back"}; "Back"};
static msg_t static_fn(void* arg);
MessageHandlerRegistration message_handler_frame_sync{ static bool needRun;
Message::ID::DisplayFrameSync, Thread* thread{nullptr};
[this](const Message* const) {
this->on_timer();
}};
}; };
} /* namespace ui */ } /* namespace ui */