From e57659d4cf0fb3dfae601f5290fc58336fca1ed7 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 3 Feb 2016 13:24:38 -0800 Subject: [PATCH] Convert SD card view to show icon/color for status. --- .../application/ui_sd_card_status_view.cpp | 131 ++++++++++++------ .../application/ui_sd_card_status_view.hpp | 9 +- 2 files changed, 94 insertions(+), 46 deletions(-) diff --git a/firmware/application/ui_sd_card_status_view.cpp b/firmware/application/ui_sd_card_status_view.cpp index 5a254c87..95b82fec 100644 --- a/firmware/application/ui_sd_card_status_view.cpp +++ b/firmware/application/ui_sd_card_status_view.cpp @@ -28,58 +28,111 @@ namespace ui { /* SDCardStatusView *****************************************************/ -SDCardStatusView::SDCardStatusView() { - add_children({ { - &text_status, - } }); +namespace detail { + +static constexpr uint8_t bitmap_sd_card_ok_data[] = { + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f, + 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, + 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, + 0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, +}; + +static constexpr Bitmap bitmap_sd_card_ok { + { 16, 16 }, bitmap_sd_card_ok_data +}; + +static constexpr uint8_t bitmap_sd_card_unknown_data[] = { + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f, + 0x38, 0x1c, 0x98, 0x19, 0xf8, 0x19, 0xf8, 0x1c, + 0x78, 0x1e, 0x78, 0x1e, 0xf8, 0x1f, 0x78, 0x1e, + 0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, +}; + +static constexpr Bitmap bitmap_sd_card_unknown { + { 16, 16 }, bitmap_sd_card_unknown_data +}; + +static constexpr uint8_t bitmap_sd_card_error_data[] = { + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0xf0, 0x1f, + 0xf8, 0x1f, 0xf8, 0x1b, 0xf8, 0x19, 0xf8, 0x1c, + 0xf8, 0x1e, 0xf8, 0x1c, 0xf8, 0x19, 0xf8, 0x1b, + 0xf8, 0x1f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, +}; + +static constexpr Bitmap bitmap_sd_card_error { + { 16, 16 }, bitmap_sd_card_error_data +}; + +const Bitmap& bitmap_sd_card(const sd_card::Status status) { + switch(status) { + case sd_card::Status::IOError: + case sd_card::Status::MountError: + case sd_card::Status::ConnectError: + return bitmap_sd_card_error; + + case sd_card::Status::NotPresent: + return bitmap_sd_card_unknown; + + case sd_card::Status::Present: + return bitmap_sd_card_unknown; + + case sd_card::Status::Mounted: + return bitmap_sd_card_ok; + + default: + return bitmap_sd_card_unknown; + } } +static constexpr Color color_sd_card_error = Color::red(); +static constexpr Color color_sd_card_unknown = Color::yellow(); +static constexpr Color color_sd_card_ok = Color::green(); + +const Color color_sd_card(const sd_card::Status status) { + switch(status) { + case sd_card::Status::IOError: + case sd_card::Status::MountError: + case sd_card::Status::ConnectError: + return color_sd_card_error; + + case sd_card::Status::NotPresent: + return color_sd_card_unknown; + + case sd_card::Status::Present: + return color_sd_card_unknown; + + case sd_card::Status::Mounted: + return color_sd_card_ok; + + default: + return color_sd_card_unknown; + } +} + +} /* namespace detail */ + void SDCardStatusView::on_show() { sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) { this->on_status(status); }; - - on_status(sd_card::status()); } void SDCardStatusView::on_hide() { sd_card::status_signal -= sd_card_status_signal_token; } -void SDCardStatusView::on_status(const sd_card::Status status) { - std::string msg("??"); +void SDCardStatusView::paint(Painter& painter) { + const auto status = sd_card::status(); + painter.draw_bitmap( + screen_pos(), + detail::bitmap_sd_card(status), + detail::color_sd_card(status), + style().background + ); +} - switch(status) { - case sd_card::Status::IOError: - msg = "IO"; - break; - - case sd_card::Status::MountError: - msg = "MT"; - break; - - case sd_card::Status::ConnectError: - msg = "CN"; - break; - - case sd_card::Status::NotPresent: - msg = "XX"; - break; - - case sd_card::Status::Present: - msg = "OO"; - break; - - case sd_card::Status::Mounted: - msg = "OK"; - break; - - default: - msg = "--"; - break; - } - - text_status.set(msg); +void SDCardStatusView::on_status(const sd_card::Status) { + set_dirty(); } } /* namespace ui */ diff --git a/firmware/application/ui_sd_card_status_view.hpp b/firmware/application/ui_sd_card_status_view.hpp index dd542f3c..7c426260 100644 --- a/firmware/application/ui_sd_card_status_view.hpp +++ b/firmware/application/ui_sd_card_status_view.hpp @@ -29,17 +29,12 @@ namespace ui { class SDCardStatusView : public View { public: - SDCardStatusView(); - void on_show() override; void on_hide() override; -private: - Text text_status { - { 0 * 8, 0, 2 * 8, 1 * 16 }, - "", - }; + void paint(Painter& painter) override; +private: SignalToken sd_card_status_signal_token; void on_status(const sd_card::Status status);