2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* 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_navigation.hpp"
|
|
|
|
|
2015-10-16 22:39:44 -04:00
|
|
|
#include "portapack.hpp"
|
2016-01-27 23:33:54 -05:00
|
|
|
#include "event_m0.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
#include "ui_setup.hpp"
|
|
|
|
#include "ui_debug.hpp"
|
|
|
|
|
2016-01-31 12:13:44 -05:00
|
|
|
#include "analog_audio_app.hpp"
|
2016-01-25 01:38:36 -05:00
|
|
|
#include "ais_app.hpp"
|
|
|
|
#include "ert_app.hpp"
|
|
|
|
#include "tpms_app.hpp"
|
2016-04-11 13:59:55 -04:00
|
|
|
#include "capture_app.hpp"
|
2016-01-25 01:38:36 -05:00
|
|
|
|
2016-02-16 14:09:00 -05:00
|
|
|
#include "core_control.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2016-04-20 13:22:05 -04:00
|
|
|
#include "file.hpp"
|
2016-02-19 18:34:02 -05:00
|
|
|
#include "png_writer.hpp"
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* SystemStatusView ******************************************************/
|
|
|
|
|
|
|
|
SystemStatusView::SystemStatusView() {
|
|
|
|
add_children({ {
|
2016-01-25 14:13:19 -05:00
|
|
|
&button_back,
|
2016-01-26 16:04:44 -05:00
|
|
|
&title,
|
2016-02-19 00:35:46 -05:00
|
|
|
&button_camera,
|
2016-01-27 23:33:54 -05:00
|
|
|
&button_sleep,
|
2015-12-01 13:45:34 -05:00
|
|
|
&sd_card_status_view,
|
2015-07-08 11:39:24 -04:00
|
|
|
} });
|
2016-01-25 14:13:19 -05:00
|
|
|
|
|
|
|
button_back.on_select = [this](Button&){
|
|
|
|
if( this->on_back ) {
|
|
|
|
this->on_back();
|
|
|
|
}
|
|
|
|
};
|
2016-01-27 23:33:54 -05:00
|
|
|
|
2016-02-19 00:35:46 -05:00
|
|
|
button_camera.on_select = [this](ImageButton&) {
|
|
|
|
this->on_camera();
|
|
|
|
};
|
|
|
|
|
2016-02-03 19:04:23 -05:00
|
|
|
button_sleep.on_select = [this](ImageButton&) {
|
2016-01-27 23:33:54 -05:00
|
|
|
DisplaySleepMessage message;
|
|
|
|
EventDispatcher::message_map().send(&message);
|
|
|
|
};
|
2016-01-25 14:13:19 -05:00
|
|
|
}
|
|
|
|
|
2016-02-07 13:33:15 -05:00
|
|
|
void SystemStatusView::set_back_enabled(bool new_value) {
|
|
|
|
button_back.set_text(new_value ? back_text_enabled : back_text_disabled);
|
|
|
|
button_back.set_focusable(new_value);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2016-01-26 16:04:44 -05:00
|
|
|
void SystemStatusView::set_title(const std::string new_value) {
|
|
|
|
if( new_value.empty() ) {
|
|
|
|
title.set(default_title);
|
|
|
|
} else {
|
|
|
|
title.set(new_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-19 00:35:46 -05:00
|
|
|
void SystemStatusView::on_camera() {
|
2016-04-29 14:27:12 -04:00
|
|
|
const auto filename_stem = next_filename_stem_matching_pattern("SCR_????");
|
|
|
|
if( filename_stem.empty() ) {
|
2016-04-20 13:22:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-29 14:27:12 -04:00
|
|
|
PNGWriter png { filename_stem + ".PNG" };
|
2016-02-19 18:34:02 -05:00
|
|
|
|
|
|
|
for(int i=0; i<320; i++) {
|
|
|
|
std::array<ColorRGB888, 240> row;
|
|
|
|
portapack::display.read_pixels({ 0, i, 240, 1 }, row);
|
|
|
|
png.write_scanline(row);
|
|
|
|
}
|
2016-02-19 00:35:46 -05:00
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
/* Navigation ************************************************************/
|
|
|
|
|
2016-01-25 14:13:19 -05:00
|
|
|
bool NavigationView::is_top() const {
|
|
|
|
return view_stack.size() == 1;
|
|
|
|
}
|
|
|
|
|
2015-12-14 14:11:49 -05:00
|
|
|
View* NavigationView::push_view(std::unique_ptr<View> new_view) {
|
2015-12-14 13:52:08 -05:00
|
|
|
free_view();
|
|
|
|
|
2015-12-14 14:11:49 -05:00
|
|
|
const auto p = new_view.get();
|
|
|
|
view_stack.emplace_back(std::move(new_view));
|
2015-12-14 13:52:08 -05:00
|
|
|
|
|
|
|
update_view();
|
2015-12-14 14:11:49 -05:00
|
|
|
|
|
|
|
return p;
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationView::pop() {
|
|
|
|
// Can't pop last item from stack.
|
|
|
|
if( view_stack.size() > 1 ) {
|
2015-12-14 13:52:08 -05:00
|
|
|
free_view();
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
view_stack.pop_back();
|
2015-12-14 13:52:08 -05:00
|
|
|
|
|
|
|
update_view();
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 13:52:08 -05:00
|
|
|
void NavigationView::free_view() {
|
|
|
|
remove_child(view());
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2015-12-14 13:52:08 -05:00
|
|
|
void NavigationView::update_view() {
|
2015-12-14 14:11:49 -05:00
|
|
|
const auto new_view = view_stack.back().get();
|
2015-12-14 13:52:08 -05:00
|
|
|
add_child(new_view);
|
|
|
|
new_view->set_parent_rect({ {0, 0}, size() });
|
|
|
|
focus();
|
2015-07-08 11:39:24 -04:00
|
|
|
set_dirty();
|
2016-01-25 14:13:19 -05:00
|
|
|
|
|
|
|
if( on_view_changed ) {
|
2016-01-26 16:04:44 -05:00
|
|
|
on_view_changed(*new_view);
|
2016-01-25 14:13:19 -05:00
|
|
|
}
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2015-12-14 13:52:08 -05:00
|
|
|
Widget* NavigationView::view() const {
|
|
|
|
return children_.empty() ? nullptr : children_[0];
|
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
void NavigationView::focus() {
|
|
|
|
if( view() ) {
|
|
|
|
view()->focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-25 01:38:36 -05:00
|
|
|
/* TransceiversMenuView **************************************************/
|
|
|
|
|
|
|
|
TranspondersMenuView::TranspondersMenuView(NavigationView& nav) {
|
|
|
|
add_items<3>({ {
|
|
|
|
{ "AIS: Boats", [&nav](){ nav.push<AISAppView>(); } },
|
|
|
|
{ "ERT: Utility Meters", [&nav](){ nav.push<ERTAppView>(); } },
|
|
|
|
{ "TPMS: Cars", [&nav](){ nav.push<TPMSAppView>(); } },
|
|
|
|
} });
|
2016-02-04 15:17:10 -05:00
|
|
|
on_left = [&nav](){ nav.pop(); };
|
2016-01-25 01:38:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ReceiverMenuView ******************************************************/
|
|
|
|
|
|
|
|
ReceiverMenuView::ReceiverMenuView(NavigationView& nav) {
|
|
|
|
add_items<2>({ {
|
2016-01-31 12:13:44 -05:00
|
|
|
{ "Audio", [&nav](){ nav.push<AnalogAudioView>(); } },
|
2016-01-25 01:38:36 -05:00
|
|
|
{ "Transponders", [&nav](){ nav.push<TranspondersMenuView>(); } },
|
|
|
|
} });
|
2016-02-04 15:17:10 -05:00
|
|
|
on_left = [&nav](){ nav.pop(); };
|
2016-01-25 01:38:36 -05:00
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
/* SystemMenuView ********************************************************/
|
|
|
|
|
|
|
|
SystemMenuView::SystemMenuView(NavigationView& nav) {
|
2015-08-01 16:46:15 -04:00
|
|
|
add_items<7>({ {
|
2016-01-25 01:38:36 -05:00
|
|
|
{ "Receiver", [&nav](){ nav.push<ReceiverMenuView>(); } },
|
2016-04-11 13:59:55 -04:00
|
|
|
{ "Capture", [&nav](){ nav.push<CaptureAppView>(); } },
|
2015-12-14 14:18:59 -05:00
|
|
|
{ "Analyze", [&nav](){ nav.push<NotImplementedView>(); } },
|
|
|
|
{ "Setup", [&nav](){ nav.push<SetupMenuView>(); } },
|
|
|
|
{ "About", [&nav](){ nav.push<AboutView>(); } },
|
|
|
|
{ "Debug", [&nav](){ nav.push<DebugMenuView>(); } },
|
|
|
|
{ "HackRF", [&nav](){ nav.push<HackRFFirmwareView>(); } },
|
2015-07-08 11:39:24 -04:00
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SystemView ************************************************************/
|
|
|
|
|
|
|
|
static constexpr ui::Style style_default {
|
|
|
|
.font = ui::font::fixed_8x16,
|
|
|
|
.background = ui::Color::black(),
|
|
|
|
.foreground = ui::Color::white(),
|
|
|
|
};
|
|
|
|
|
|
|
|
SystemView::SystemView(
|
|
|
|
Context& context,
|
|
|
|
const Rect parent_rect
|
|
|
|
) : View { parent_rect },
|
2015-07-17 15:07:38 -04:00
|
|
|
context_(context)
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
2016-02-07 13:40:06 -05:00
|
|
|
set_style(&style_default);
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
constexpr ui::Dim status_view_height = 16;
|
|
|
|
|
|
|
|
add_child(&status_view);
|
|
|
|
status_view.set_parent_rect({
|
|
|
|
{ 0, 0 },
|
|
|
|
{ parent_rect.width(), status_view_height }
|
|
|
|
});
|
2016-01-25 14:13:19 -05:00
|
|
|
status_view.on_back = [this]() {
|
|
|
|
this->navigation_view.pop();
|
|
|
|
};
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
add_child(&navigation_view);
|
|
|
|
navigation_view.set_parent_rect({
|
|
|
|
{ 0, status_view_height },
|
|
|
|
{ parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - status_view_height) }
|
|
|
|
});
|
2016-01-26 16:04:44 -05:00
|
|
|
navigation_view.on_view_changed = [this](const View& new_view) {
|
2016-02-07 13:33:15 -05:00
|
|
|
this->status_view.set_back_enabled(!this->navigation_view.is_top());
|
2016-01-26 16:04:44 -05:00
|
|
|
this->status_view.set_title(new_view.title());
|
2016-01-25 14:13:19 -05:00
|
|
|
};
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
// Initial view.
|
|
|
|
// TODO: Restore from non-volatile memory?
|
2015-12-14 14:18:59 -05:00
|
|
|
navigation_view.push<SystemMenuView>();
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Context& SystemView::context() const {
|
|
|
|
return context_;
|
|
|
|
}
|
|
|
|
|
2015-08-01 16:46:15 -04:00
|
|
|
/* HackRFFirmwareView ****************************************************/
|
|
|
|
|
|
|
|
HackRFFirmwareView::HackRFFirmwareView(NavigationView& nav) {
|
|
|
|
button_yes.on_select = [&nav](Button&){
|
2015-08-20 21:03:49 -04:00
|
|
|
m4_request_shutdown();
|
2015-08-01 16:46:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
button_no.on_select = [&nav](Button&){
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&text_title,
|
2015-09-01 23:23:11 -04:00
|
|
|
&text_description_1,
|
|
|
|
&text_description_2,
|
|
|
|
&text_description_3,
|
|
|
|
&text_description_4,
|
2015-08-01 16:46:15 -04:00
|
|
|
&button_yes,
|
|
|
|
&button_no,
|
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
void HackRFFirmwareView::focus() {
|
|
|
|
button_no.focus();
|
|
|
|
}
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
/* NotImplementedView ****************************************************/
|
|
|
|
|
|
|
|
NotImplementedView::NotImplementedView(NavigationView& nav) {
|
|
|
|
button_done.on_select = [&nav](Button&){
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&text_title,
|
|
|
|
&button_done,
|
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotImplementedView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|