From 0c36a74351df9145ca96729d843d70d96e40cd13 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 1 Dec 2015 10:45:34 -0800 Subject: [PATCH] Add SD card status view to receiver UI. --- firmware/application/Makefile | 1 + firmware/application/ui_navigation.cpp | 2 + firmware/application/ui_navigation.hpp | 3 + .../application/ui_sd_card_status_view.cpp | 85 +++++++++++++++++++ .../application/ui_sd_card_status_view.hpp | 50 +++++++++++ 5 files changed, 141 insertions(+) create mode 100644 firmware/application/ui_sd_card_status_view.cpp create mode 100644 firmware/application/ui_sd_card_status_view.hpp diff --git a/firmware/application/Makefile b/firmware/application/Makefile index f02db587b..94687405f 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -162,6 +162,7 @@ CPPSRC = main.cpp \ ui_setup.cpp \ ui_debug.cpp \ ui_baseband_stats_view.cpp \ + ui_sd_card_status_view.cpp \ ui_console.cpp \ ui_receiver.cpp \ ui_spectrum.cpp \ diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 5b3bdb8cb..f603c3cc0 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -37,7 +37,9 @@ namespace ui { SystemStatusView::SystemStatusView() { add_children({ { &portapack, + &sd_card_status_view, } }); + sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 }); } /* Navigation ************************************************************/ diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index fae713e57..7307aed92 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -30,6 +30,7 @@ #include "ui_rssi.hpp" #include "ui_channel.hpp" #include "ui_audio.hpp" +#include "ui_sd_card_status_view.hpp" #include @@ -44,6 +45,8 @@ private: { 0, 0, 9 * 8, 1 * 16 }, "PortaPack", }; + + SDCardStatusView sd_card_status_view; }; class NavigationView : public View { diff --git a/firmware/application/ui_sd_card_status_view.cpp b/firmware/application/ui_sd_card_status_view.cpp new file mode 100644 index 000000000..1c7698539 --- /dev/null +++ b/firmware/application/ui_sd_card_status_view.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "ui_sd_card_status_view.hpp" + +#include +#include + +namespace ui { + +/* SDCardStatusView *****************************************************/ + +SDCardStatusView::SDCardStatusView() { + add_children({ { + &text_status, + } }); + + text_status.set("XX"); +} + +void SDCardStatusView::on_show() { + sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) { + this->on_status(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("??"); + + 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); +} + +} /* namespace ui */ diff --git a/firmware/application/ui_sd_card_status_view.hpp b/firmware/application/ui_sd_card_status_view.hpp new file mode 100644 index 000000000..dd542f3c2 --- /dev/null +++ b/firmware/application/ui_sd_card_status_view.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __UI_SD_CARD_STATUS_VIEW_H__ +#define __UI_SD_CARD_STATUS_VIEW_H__ + +#include "ui_widget.hpp" +#include "sd_card.hpp" + +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 }, + "", + }; + + SignalToken sd_card_status_signal_token; + + void on_status(const sd_card::Status status); +}; + +} /* namespace ui */ + +#endif/*__UI_SD_CARD_STATUS_VIEW_H__*/