Rearrange TPMS app/UI code.

This commit is contained in:
Jared Boone 2016-01-18 13:41:19 -08:00
parent 1a280149e2
commit be328c5f38
2 changed files with 24 additions and 19 deletions

View File

@ -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 */

View File

@ -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);
};