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_debug.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "radio.hpp"
|
2015-12-02 16:38:17 -05:00
|
|
|
#include "string_format.hpp"
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2015-12-13 14:50:55 -05:00
|
|
|
/* DebugMemoryView *******************************************************/
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
DebugMemoryView::DebugMemoryView(NavigationView& nav) {
|
|
|
|
add_children({ {
|
|
|
|
&text_title,
|
|
|
|
&text_label_m0_free,
|
|
|
|
&text_label_m0_free_value,
|
|
|
|
&text_label_m0_heap_fragmented_free,
|
|
|
|
&text_label_m0_heap_fragmented_free_value,
|
|
|
|
&text_label_m0_heap_fragments,
|
|
|
|
&text_label_m0_heap_fragments_value,
|
|
|
|
&button_done
|
|
|
|
} });
|
|
|
|
|
|
|
|
const auto m0_free = chCoreStatus();
|
|
|
|
text_label_m0_free_value.set(to_string_dec_uint(m0_free, 5));
|
|
|
|
|
|
|
|
size_t m0_fragmented_free_space = 0;
|
|
|
|
const auto m0_fragments = chHeapStatus(NULL, &m0_fragmented_free_space);
|
|
|
|
text_label_m0_heap_fragmented_free_value.set(to_string_dec_uint(m0_fragmented_free_space, 5));
|
|
|
|
text_label_m0_heap_fragments_value.set(to_string_dec_uint(m0_fragments, 5));
|
|
|
|
|
|
|
|
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugMemoryView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
2015-12-17 01:36:51 -05:00
|
|
|
/* TemperatureWidget *****************************************************/
|
|
|
|
|
|
|
|
void TemperatureWidget::paint(Painter& painter) {
|
2015-12-17 15:16:26 -05:00
|
|
|
const auto logger = portapack::temperature_logger;
|
2015-12-17 01:36:51 -05:00
|
|
|
|
|
|
|
const auto rect = screen_rect();
|
2015-12-17 23:36:58 -05:00
|
|
|
const Color color_background { 0, 0, 64 };
|
|
|
|
const Color color_foreground = Color::green();
|
|
|
|
const Color color_reticle { 128, 128, 128 };
|
|
|
|
|
|
|
|
const Dim graph_width = logger.capacity() * bar_width;
|
|
|
|
const Dim graph_height = rect.height() - 16;
|
|
|
|
const Rect graph_rect {
|
|
|
|
rect.left() + (rect.width() - graph_width) / 2, rect.top() + 8,
|
|
|
|
graph_width, rect.height()
|
|
|
|
};
|
|
|
|
const Rect frame_rect {
|
|
|
|
graph_rect.left() - 1, graph_rect.top() - 1,
|
|
|
|
graph_rect.width() + 2, graph_rect.height() + 2
|
|
|
|
};
|
|
|
|
painter.draw_rectangle(frame_rect, color_reticle);
|
|
|
|
painter.fill_rectangle(graph_rect, color_background);
|
2015-12-17 15:18:25 -05:00
|
|
|
|
2015-12-17 15:16:26 -05:00
|
|
|
const auto history = logger.history();
|
2015-12-17 01:36:51 -05:00
|
|
|
for(size_t i=0; i<history.size(); i++) {
|
2015-12-17 23:36:58 -05:00
|
|
|
const Coord x = graph_rect.right() - (history.size() - i) * bar_width;
|
2015-12-17 01:36:51 -05:00
|
|
|
const auto sample = history[i];
|
2015-12-17 23:36:58 -05:00
|
|
|
const auto temp = temperature(sample);
|
|
|
|
const auto y = screen_y(temp, graph_rect);
|
|
|
|
const Dim bar_height = graph_rect.bottom() - y;
|
|
|
|
painter.fill_rectangle({ x, y, bar_width, bar_height }, color_foreground);
|
2015-12-17 01:36:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !history.empty() ) {
|
2015-12-17 23:36:58 -05:00
|
|
|
const auto sample = history.back();
|
|
|
|
const auto temp = temperature(sample);
|
|
|
|
const auto last_y = screen_y(temp, graph_rect);
|
|
|
|
const Coord x = graph_rect.right() + 8;
|
|
|
|
const Coord y = last_y - 8;
|
|
|
|
|
|
|
|
painter.draw_string({ x, y }, style(), temperature_str(temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto display_temp_max = display_temp_min + (graph_rect.height() / display_temp_scale);
|
|
|
|
for(auto temp=display_temp_min; temp<=display_temp_max; temp+=10) {
|
|
|
|
const int32_t tick_length = 6;
|
|
|
|
const auto tick_x = graph_rect.left() - tick_length;
|
|
|
|
const auto tick_y = screen_y(temp, graph_rect);
|
|
|
|
painter.fill_rectangle({ tick_x, tick_y, tick_length, 1 }, color_reticle);
|
|
|
|
const auto text_x = graph_rect.left() - temp_len * 8 - 8;
|
|
|
|
const auto text_y = tick_y - 8;
|
|
|
|
painter.draw_string({ text_x, text_y }, style(), temperature_str(temp));
|
2015-12-17 01:36:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 23:36:58 -05:00
|
|
|
TemperatureWidget::temperature_t TemperatureWidget::temperature(const sample_t sensor_value) const {
|
|
|
|
return -45 + sensor_value * 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TemperatureWidget::temperature_str(const temperature_t temperature) const {
|
|
|
|
return to_string_dec_int(temperature, temp_len - 1) + "C";
|
|
|
|
}
|
|
|
|
|
|
|
|
Coord TemperatureWidget::screen_y(
|
|
|
|
const temperature_t temperature,
|
|
|
|
const Rect& rect
|
|
|
|
) const {
|
|
|
|
const Coord y_raw = rect.bottom() - ((temperature - display_temp_min) * display_temp_scale);
|
|
|
|
const auto y_limit = std::min(rect.bottom(), std::max(rect.top(), y_raw));
|
|
|
|
return y_limit;
|
2015-12-17 15:14:28 -05:00
|
|
|
}
|
|
|
|
|
2015-12-17 01:36:51 -05:00
|
|
|
/* TemperatureView *******************************************************/
|
|
|
|
|
|
|
|
TemperatureView::TemperatureView(NavigationView& nav) {
|
|
|
|
add_children({ {
|
2015-12-17 23:36:58 -05:00
|
|
|
&text_title,
|
2015-12-17 01:36:51 -05:00
|
|
|
&temperature_widget,
|
|
|
|
&button_done,
|
|
|
|
} });
|
|
|
|
|
|
|
|
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
void TemperatureView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
/* RegistersWidget *******************************************************/
|
2015-12-13 14:50:55 -05:00
|
|
|
|
2015-12-14 14:30:24 -05:00
|
|
|
RegistersWidget::RegistersWidget(
|
|
|
|
RegistersWidgetConfig&& config,
|
|
|
|
std::function<uint32_t(const size_t register_number)>&& reader
|
|
|
|
) : Widget { },
|
|
|
|
config(std::move(config)),
|
|
|
|
reader(std::move(reader))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
void RegistersWidget::update() {
|
2015-12-13 14:50:06 -05:00
|
|
|
set_dirty();
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
void RegistersWidget::paint(Painter& painter) {
|
2015-12-14 14:47:43 -05:00
|
|
|
const Coord left = (size().w - config.row_width()) / 2;
|
2015-12-13 14:50:06 -05:00
|
|
|
|
2015-12-14 14:47:43 -05:00
|
|
|
draw_legend(left, painter);
|
|
|
|
draw_values(left, painter);
|
2015-12-13 14:50:06 -05:00
|
|
|
}
|
|
|
|
|
2015-12-14 14:47:43 -05:00
|
|
|
void RegistersWidget::draw_legend(const Coord left, Painter& painter) {
|
2015-12-17 01:36:51 -05:00
|
|
|
const auto pos = screen_pos();
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
for(size_t i=0; i<config.registers_count; i+=config.registers_per_row) {
|
2015-12-13 14:50:06 -05:00
|
|
|
const Point offset {
|
2015-12-14 14:47:43 -05:00
|
|
|
left, static_cast<Coord>((i / config.registers_per_row) * row_height)
|
2015-12-13 14:50:06 -05:00
|
|
|
};
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
const auto text = to_string_hex(i, config.legend_length);
|
2015-12-13 14:50:06 -05:00
|
|
|
painter.draw_string(
|
2015-12-17 01:36:51 -05:00
|
|
|
pos + offset,
|
2015-12-14 14:24:48 -05:00
|
|
|
style().invert(),
|
2015-12-13 14:50:06 -05:00
|
|
|
text
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
void RegistersWidget::draw_values(
|
2015-12-14 14:47:43 -05:00
|
|
|
const Coord left,
|
2015-12-13 16:22:09 -05:00
|
|
|
Painter& painter
|
2015-12-13 14:50:06 -05:00
|
|
|
) {
|
2015-12-17 01:36:51 -05:00
|
|
|
const auto pos = screen_pos();
|
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
for(size_t i=0; i<config.registers_count; i++) {
|
2015-12-13 14:50:06 -05:00
|
|
|
const Point offset = {
|
2015-12-14 14:47:43 -05:00
|
|
|
static_cast<Coord>(left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8)),
|
2015-12-13 16:22:09 -05:00
|
|
|
static_cast<Coord>((i / config.registers_per_row) * row_height)
|
2015-12-13 14:50:06 -05:00
|
|
|
};
|
|
|
|
|
2015-12-14 00:28:39 -05:00
|
|
|
const auto value = reader(i);
|
2015-12-13 14:50:06 -05:00
|
|
|
|
2015-12-13 16:22:09 -05:00
|
|
|
const auto text = to_string_hex(value, config.value_length);
|
2015-12-13 15:34:51 -05:00
|
|
|
painter.draw_string(
|
2015-12-17 01:36:51 -05:00
|
|
|
pos + offset,
|
2015-12-13 15:34:51 -05:00
|
|
|
style(),
|
|
|
|
text
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 14:30:24 -05:00
|
|
|
/* RegistersView *********************************************************/
|
|
|
|
|
|
|
|
RegistersView::RegistersView(
|
|
|
|
NavigationView& nav,
|
|
|
|
const std::string& title,
|
|
|
|
RegistersWidgetConfig&& config,
|
|
|
|
std::function<uint32_t(const size_t register_number)>&& reader
|
|
|
|
) : registers_widget { std::move(config), std::move(reader) }
|
|
|
|
{
|
|
|
|
add_children({ {
|
|
|
|
&text_title,
|
|
|
|
®isters_widget,
|
|
|
|
&button_update,
|
|
|
|
&button_done,
|
|
|
|
} });
|
|
|
|
|
|
|
|
button_update.on_select = [this](Button&){
|
|
|
|
this->registers_widget.update();
|
|
|
|
};
|
|
|
|
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
|
|
|
|
|
|
|
registers_widget.set_parent_rect({ 0, 48, 240, 192 });
|
|
|
|
|
|
|
|
text_title.set_parent_rect({
|
|
|
|
static_cast<Coord>((240 - title.size() * 8) / 2), 16,
|
|
|
|
static_cast<Dim>(title.size() * 8), 16
|
|
|
|
});
|
|
|
|
text_title.set(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegistersView::focus() {
|
|
|
|
button_done.focus();
|
|
|
|
}
|
|
|
|
|
2015-12-13 14:50:55 -05:00
|
|
|
/* DebugMenuView *********************************************************/
|
2015-07-08 11:39:24 -04:00
|
|
|
|
|
|
|
DebugMenuView::DebugMenuView(NavigationView& nav) {
|
2015-12-17 01:36:51 -05:00
|
|
|
add_items<8>({ {
|
2015-12-14 14:18:59 -05:00
|
|
|
{ "Memory", [&nav](){ nav.push<DebugMemoryView>(); } },
|
|
|
|
{ "Radio State", [&nav](){ nav.push<NotImplementedView>(); } },
|
|
|
|
{ "SD Card", [&nav](){ nav.push<NotImplementedView>(); } },
|
2015-12-14 13:22:42 -05:00
|
|
|
{ "RFFC5072", [&nav](){ nav.push<RegistersView>(
|
2015-12-14 14:18:59 -05:00
|
|
|
"RFFC5072", RegistersWidgetConfig { 31, 2, 4, 4 },
|
2015-12-14 00:28:39 -05:00
|
|
|
[](const size_t register_number) { return radio::first_if.read(register_number); }
|
2015-12-14 13:22:42 -05:00
|
|
|
); } },
|
|
|
|
{ "MAX2837", [&nav](){ nav.push<RegistersView>(
|
2015-12-14 14:18:59 -05:00
|
|
|
"MAX2837", RegistersWidgetConfig { 32, 2, 3, 4 },
|
2015-12-14 00:28:39 -05:00
|
|
|
[](const size_t register_number) { return radio::second_if.read(register_number); }
|
2015-12-14 13:22:42 -05:00
|
|
|
); } },
|
|
|
|
{ "Si5351C", [&nav](){ nav.push<RegistersView>(
|
2015-12-14 14:18:59 -05:00
|
|
|
"Si5351C", RegistersWidgetConfig { 96, 2, 2, 8 },
|
2015-12-14 00:28:39 -05:00
|
|
|
[](const size_t register_number) { return portapack::clock_generator.read_register(register_number); }
|
2015-12-14 13:22:42 -05:00
|
|
|
); } },
|
2015-12-14 15:09:31 -05:00
|
|
|
{ "WM8731", [&nav](){ nav.push<RegistersView>(
|
|
|
|
"WM8731", RegistersWidgetConfig { wolfson::wm8731::reg_count, 1, 3, 4 },
|
|
|
|
[](const size_t register_number) { return portapack::audio_codec.read(register_number); }
|
|
|
|
); } },
|
2015-12-17 01:36:51 -05:00
|
|
|
{ "Temperature", [&nav](){ nav.push<TemperatureView>(); } },
|
2015-07-08 11:39:24 -04:00
|
|
|
} });
|
|
|
|
on_left = [&nav](){ nav.pop(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|