From be328c5f389f6d55cc0ad4aa5d8ea43700820fd2 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 18 Jan 2016 13:41:19 -0800 Subject: [PATCH] Rearrange TPMS app/UI code. --- firmware/application/tpms_app.cpp | 31 +++++++++++++++++-------------- firmware/application/tpms_app.hpp | 12 +++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 9b02c388d..37534b4b4 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -28,15 +28,6 @@ using namespace portapack; #include "string_format.hpp" -TPMSModel::TPMSModel() { - receiver_model.set_baseband_configuration({ - .mode = 5, - .sampling_rate = 2457600, - .decimation_factor = 1, - }); - receiver_model.set_baseband_bandwidth(1750000); -} - ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { const ManchesterDecoder decoder(message.packet, 1); const auto hex_formatted = format_manchester(decoder); @@ -55,8 +46,10 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { namespace ui { -void TPMSAppView::on_show() { - Console::on_show(); +TPMSAppView::TPMSAppView() { + add_children({ { + &console, + } }); EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket, [this](Message* const p) { @@ -64,16 +57,26 @@ void TPMSAppView::on_show() { this->log(this->model.on_packet(*message)); } ); + + receiver_model.set_baseband_configuration({ + .mode = 5, + .sampling_rate = 2457600, + .decimation_factor = 1, + }); + receiver_model.set_baseband_bandwidth(1750000); } -void TPMSAppView::on_hide() { +TPMSAppView::~TPMSAppView() { EventDispatcher::message_map().unregister_handler(Message::ID::TPMSPacket); +} - Console::on_hide(); +void TPMSAppView::set_parent_rect(const Rect new_parent_rect) { + View::set_parent_rect(new_parent_rect); + console.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() }); } void TPMSAppView::log(const ManchesterFormatted& formatted) { - writeln(formatted.data.substr(0, 240 / 8)); + console.writeln(formatted.data.substr(0, 240 / 8)); } } /* namespace ui */ diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index f1ac771c2..d4a36747a 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -30,8 +30,6 @@ class TPMSModel { public: - TPMSModel(); - ManchesterFormatted on_packet(const TPMSPacketMessage& message); private: @@ -40,14 +38,18 @@ private: namespace ui { -class TPMSAppView : public Console { +class TPMSAppView : public View { public: - void on_show() override; - void on_hide() override; + TPMSAppView(); + ~TPMSAppView(); + + void set_parent_rect(const Rect new_parent_rect) override; private: TPMSModel model; + Console console; + void log(const ManchesterFormatted& formatted); };