2015-07-08 15:39:24 +00: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-17 02:39:44 +00:00
|
|
|
#include "portapack.hpp"
|
2015-07-08 15:39:24 +00:00
|
|
|
#include "receiver_model.hpp"
|
2015-08-23 03:08:38 +00:00
|
|
|
#include "transmitter_model.hpp"
|
2015-09-04 18:37:27 +00:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include "splash.hpp"
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
#include "ui_setup.hpp"
|
|
|
|
#include "ui_debug.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
2015-08-23 03:08:38 +00:00
|
|
|
#include "ui_rds.hpp"
|
2015-08-28 18:50:42 +00:00
|
|
|
#include "ui_lcr.hpp"
|
2015-09-10 18:36:39 +00:00
|
|
|
#include "ui_whistle.hpp"
|
2015-11-13 00:19:05 +00:00
|
|
|
#include "ui_jammer.hpp"
|
2015-11-20 06:59:09 +00:00
|
|
|
#include "ui_loadmodule.hpp"
|
2016-01-03 06:24:30 +00:00
|
|
|
#include "ui_afskrx.hpp"
|
|
|
|
#include "ui_xylos.hpp"
|
|
|
|
#include "ui_sigfrx.hpp"
|
2015-07-08 15:39:24 +00:00
|
|
|
|
2015-08-01 20:42:27 +00:00
|
|
|
#include "portapack.hpp"
|
2015-08-01 21:43:48 +00:00
|
|
|
#include "m4_startup.hpp"
|
|
|
|
#include "spi_image.hpp"
|
2015-11-20 06:59:09 +00:00
|
|
|
|
|
|
|
#include "modules.h"
|
|
|
|
|
2015-08-01 21:43:48 +00:00
|
|
|
using namespace portapack;
|
2015-07-08 15:39:24 +00:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* SystemStatusView ******************************************************/
|
|
|
|
|
|
|
|
SystemStatusView::SystemStatusView() {
|
|
|
|
add_children({ {
|
|
|
|
&portapack,
|
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Navigation ************************************************************/
|
|
|
|
|
|
|
|
NavigationView::NavigationView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationView::push(View* new_view) {
|
|
|
|
// TODO: Trap nullptr?
|
|
|
|
// TODO: Trap push of object already on stack?
|
|
|
|
view_stack.push_back(new_view);
|
|
|
|
set_view(new_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationView::pop() {
|
|
|
|
// Can't pop last item from stack.
|
|
|
|
if( view_stack.size() > 1 ) {
|
|
|
|
const auto old_view = view_stack.back();
|
|
|
|
view_stack.pop_back();
|
|
|
|
const auto new_view = view_stack.back();
|
|
|
|
set_view(new_view);
|
|
|
|
delete old_view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* NavigationView::view() const {
|
|
|
|
return children_.empty() ? nullptr : children_[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationView::set_view(Widget* const new_view) {
|
|
|
|
const auto old_view = view();
|
|
|
|
if( old_view ) {
|
|
|
|
remove_child(old_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Allow new_view == nullptr?!
|
|
|
|
if( new_view ) {
|
|
|
|
add_child(new_view);
|
|
|
|
new_view->set_parent_rect({ {0, 0}, size() });
|
|
|
|
focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
set_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationView::focus() {
|
|
|
|
if( view() ) {
|
|
|
|
view()->focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SystemMenuView ********************************************************/
|
|
|
|
|
|
|
|
SystemMenuView::SystemMenuView(NavigationView& nav) {
|
2016-01-05 19:17:55 +00:00
|
|
|
add_items<11>({ {
|
2015-11-20 06:59:09 +00:00
|
|
|
{ "Play dead", ui::Color::red(), [&nav](){ nav.push(new PlayDeadView { nav, false }); } },
|
2016-01-05 19:17:55 +00:00
|
|
|
{ "Receiver", ui::Color::cyan(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new ReceiverView { nav, receiver_model }}); } },
|
2015-11-20 06:59:09 +00:00
|
|
|
//{ "Nordic/BTLE RX", ui::Color::cyan(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
2016-01-05 19:17:55 +00:00
|
|
|
{ "Jammer", ui::Color::white(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new JammerView { nav, transmitter_model }}); } },
|
2016-01-03 06:24:30 +00:00
|
|
|
//{ "Audio file TX", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
2015-11-20 06:59:09 +00:00
|
|
|
//{ "Encoder TX", ui::Color::green(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
2016-01-05 19:17:55 +00:00
|
|
|
{ "Whistle", ui::Color::purple(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new WhistleView { nav, transmitter_model }}); } },
|
|
|
|
//{ "SIGFOX RX", ui::Color::orange(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new SIGFRXView { nav, receiver_model }}); } },
|
|
|
|
{ "RDS TX", ui::Color::yellow(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new RDSView { nav, transmitter_model }}); } },
|
|
|
|
{ "Xylos TX", ui::Color::orange(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new XylosView { nav, transmitter_model }}); } },
|
|
|
|
//{ "AFSK RX", ui::Color::cyan(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new AFSKRXView { nav, receiver_model }}); } },
|
|
|
|
{ "TEDI/LCR TX", ui::Color::yellow(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new LCRView { nav, transmitter_model }}); } },
|
2015-11-20 06:59:09 +00:00
|
|
|
{ "Setup", ui::Color::white(), [&nav](){ nav.push(new SetupMenuView { nav }); } },
|
|
|
|
{ "About", ui::Color::white(), [&nav](){ nav.push(new AboutView { nav }); } },
|
|
|
|
{ "Debug", ui::Color::white(), [&nav](){ nav.push(new DebugMenuView { nav }); } },
|
|
|
|
{ "HackRF", ui::Color::white(), [&nav](){ nav.push(new HackRFFirmwareView { nav }); } },
|
2015-07-08 15:39:24 +00: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 19:07:38 +00:00
|
|
|
context_(context)
|
2015-07-08 15:39:24 +00:00
|
|
|
{
|
|
|
|
style_ = &style_default;
|
|
|
|
|
|
|
|
constexpr ui::Dim status_view_height = 16;
|
|
|
|
|
|
|
|
add_child(&status_view);
|
|
|
|
status_view.set_parent_rect({
|
|
|
|
{ 0, 0 },
|
|
|
|
{ parent_rect.width(), status_view_height }
|
|
|
|
});
|
|
|
|
|
|
|
|
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) }
|
|
|
|
});
|
|
|
|
|
|
|
|
// Initial view.
|
|
|
|
// TODO: Restore from non-volatile memory?
|
2015-09-15 20:34:36 +00:00
|
|
|
|
2015-09-16 13:43:43 +00:00
|
|
|
//if (persistent_memory::playing_dead() == 0x59)
|
|
|
|
// navigation_view.push(new PlayDeadView { navigation_view, true });
|
|
|
|
//else
|
2016-01-03 06:24:30 +00:00
|
|
|
// navigation_view.push(new BMPView { navigation_view });
|
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
navigation_view.push(new BMPView { navigation_view });
|
2015-07-08 15:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Context& SystemView::context() const {
|
|
|
|
return context_;
|
|
|
|
}
|
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
/* ***********************************************************************/
|
|
|
|
|
|
|
|
void BMPView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
BMPView::BMPView(NavigationView& nav) {
|
|
|
|
add_children({ {
|
|
|
|
&text_info,
|
|
|
|
&button_done
|
|
|
|
} });
|
|
|
|
|
|
|
|
button_done.on_select = [this,&nav](Button&){
|
|
|
|
nav.pop();
|
|
|
|
nav.push(new SystemMenuView { nav });
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void BMPView::paint(Painter& painter) {
|
2016-01-05 10:47:46 +00:00
|
|
|
(void)painter;
|
2016-01-03 06:24:30 +00:00
|
|
|
portapack::display.drawBMP({(240-185)/2, 0}, splash_bmp);
|
2015-09-04 18:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PlayDeadView **********************************************************/
|
|
|
|
|
|
|
|
void PlayDeadView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
PlayDeadView::PlayDeadView(NavigationView& nav, bool booting) {
|
|
|
|
_booting = booting;
|
2015-09-15 20:34:36 +00:00
|
|
|
persistent_memory::set_playing_dead(0x59);
|
2015-09-10 18:36:39 +00:00
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
add_children({ {
|
|
|
|
&text_playdead1,
|
|
|
|
&text_playdead2,
|
|
|
|
&button_done,
|
|
|
|
} });
|
|
|
|
|
|
|
|
button_done.on_dir = [this,&nav](Button&, KeyEvent key){
|
|
|
|
sequence = (sequence<<3) | static_cast<std::underlying_type<KeyEvent>::type>(key);
|
|
|
|
};
|
|
|
|
|
|
|
|
button_done.on_select = [this,&nav](Button&){
|
2015-09-10 18:36:39 +00:00
|
|
|
if (sequence == persistent_memory::playdead_sequence()) {
|
|
|
|
persistent_memory::set_playing_dead(0);
|
|
|
|
if (_booting) {
|
|
|
|
nav.pop();
|
|
|
|
nav.push(new SystemMenuView { nav });
|
|
|
|
} else {
|
|
|
|
nav.pop();
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-04 18:37:27 +00:00
|
|
|
sequence = 0;
|
2015-09-10 18:36:39 +00:00
|
|
|
}
|
2015-09-04 18:37:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-08-01 20:46:15 +00:00
|
|
|
/* HackRFFirmwareView ****************************************************/
|
|
|
|
|
|
|
|
HackRFFirmwareView::HackRFFirmwareView(NavigationView& nav) {
|
|
|
|
button_yes.on_select = [&nav](Button&){
|
2015-08-21 01:03:49 +00:00
|
|
|
m4_request_shutdown();
|
2015-08-01 20:46:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
button_no.on_select = [&nav](Button&){
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&text_title,
|
2015-09-02 03:23:11 +00:00
|
|
|
&text_description_1,
|
|
|
|
&text_description_2,
|
|
|
|
&text_description_3,
|
|
|
|
&text_description_4,
|
2015-08-01 20:46:15 +00:00
|
|
|
&button_yes,
|
|
|
|
&button_no,
|
|
|
|
} });
|
|
|
|
}
|
|
|
|
|
|
|
|
void HackRFFirmwareView::focus() {
|
|
|
|
button_no.focus();
|
|
|
|
}
|
|
|
|
|
2015-07-08 15:39:24 +00: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 */
|