Merge pull request #909 from bernd-herzog/dfu_menu

Dfu menu
This commit is contained in:
jLynx 2023-04-24 10:26:11 +12:00 committed by GitHub
commit 55c300ac4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 269 additions and 4 deletions

View File

@ -230,6 +230,7 @@ set(CPPSRC
apps/ui_nrf_rx.cpp
apps/ui_aprs_tx.cpp
apps/ui_bht_tx.cpp
apps/ui_dfu_menu.cpp
apps/ui_coasterp.cpp
apps/ui_debug.cpp
apps/ui_encoders.cpp

View File

@ -0,0 +1,105 @@
/*
* Copyright (C) 2023 Bernd Herzog
*
* 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_dfu_menu.hpp"
#include "portapack_shared_memory.hpp"
namespace ui {
DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) {
add_children({
&text_head,
&labels,
&text_info_line_1,
&text_info_line_2,
&text_info_line_3,
&text_info_line_4,
&text_info_line_5,
&text_info_line_6,
&text_info_line_7
});
}
void DfuMenu::paint(Painter& painter) {
auto now = chTimeNow();
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
static systime_t last_time;
static systime_t last_last_time;
auto time_elapsed = now - last_time;
auto idle_elapsed = idle_ticks - last_last_time;
last_time = now;
last_last_time = idle_ticks;
text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6));
text_info_line_2.set(to_string_dec_uint((uint32_t)get_free_stack_space(), 6));
text_info_line_3.set(to_string_dec_uint((time_elapsed - idle_elapsed) / 10, 6));
text_info_line_4.set(to_string_dec_uint(shared_memory.m4_heap_usage, 6));
text_info_line_5.set(to_string_dec_uint(shared_memory.m4_stack_usage, 6));
text_info_line_6.set(to_string_dec_uint(shared_memory.m4_cpu_usage, 6));
text_info_line_7.set(to_string_dec_uint(chTimeNow()/1000, 6));
constexpr auto margin = 5;
painter.fill_rectangle(
{
{6 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin},
{15 * CHARACTER_WIDTH + margin * 2, 9 * LINE_HEIGHT + margin * 2}
},
ui::Color::black()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin},
{CHARACTER_WIDTH, 9 * LINE_HEIGHT + margin * 2}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{21 * CHARACTER_WIDTH + margin, 3 * LINE_HEIGHT - margin},
{CHARACTER_WIDTH, 9 * LINE_HEIGHT + margin * 2}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin - 8},
{17 * CHARACTER_WIDTH + margin * 2, 8}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, 12 * LINE_HEIGHT + margin},
{17 * CHARACTER_WIDTH + margin * 2, 8}
},
ui::Color::dark_cyan()
);
}
} /* namespace ui */

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2023 Bernd Herzog
*
* 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_DFU_MENU_H__
#define __UI_DFU_MENU_H__
#include <cstdint>
#include "ui_widget.hpp"
#include "event_m0.hpp"
#include "debug.hpp"
#include "string_format.hpp"
#define LINE_HEIGHT 16
#define CHARACTER_WIDTH 8
namespace ui {
class NavigationView;
class DfuMenu : public View {
public:
DfuMenu(NavigationView& nav);
~DfuMenu() = default;
void paint(Painter& painter) override;
private:
NavigationView& nav_;
Text text_head {{ 6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT, 11 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, "Performance"};
Labels labels {
{ { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT }, "M0 heap:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 6 * LINE_HEIGHT }, "M0 stack:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 7 * LINE_HEIGHT }, "M0 cpu %:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 8 * LINE_HEIGHT }, "M4 heap:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 9 * LINE_HEIGHT }, "M4 stack:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH,10 * LINE_HEIGHT }, "M4 cpu %:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH,11 * LINE_HEIGHT }, "uptime:", Color::dark_cyan() }
};
Text text_info_line_1 {{ 15 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_2 {{ 15 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_3 {{ 15 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_4 {{ 15 * CHARACTER_WIDTH, 8 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_5 {{ 15 * CHARACTER_WIDTH, 9 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_6 {{ 15 * CHARACTER_WIDTH,10 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_7 {{ 15 * CHARACTER_WIDTH,11 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
};
} /* namespace ui */
#endif/*__UI_DFU_MENU_H__*/

View File

@ -43,6 +43,7 @@ using namespace lpc43xx;
#include <array>
#include "ui_font_fixed_8x16.hpp"
#include "ui_navigation.hpp"
extern "C" {
@ -262,6 +263,8 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) {
void EventDispatcher::handle_lcd_frame_sync() {
DisplayFrameSyncMessage message;
message_map.send(&message);
static_cast<ui::SystemView *>(top_widget)->paint_overlay();
painter.paint_widget_tree(top_widget);
portapack::backlight()->on();
@ -304,7 +307,12 @@ void EventDispatcher::handle_switches() {
if( switches_state[i] ) {
const auto event = static_cast<ui::KeyEvent>(i);
if( !event_bubble_key(event) ) {
context.focus_manager().update(top_widget, event);
if (switches_state[(size_t)ui::KeyEvent::Dfu]) {
static_cast<ui::SystemView *>(top_widget)->toggle_overlay();
}
else {
context.focus_manager().update(top_widget, event);
}
}
in_key_event = true;

View File

@ -145,14 +145,14 @@ Continuous (Fox-oring)
rffc507x::RFFC507x first_if;
static void event_loop() {
ui::Context context;
ui::SystemView system_view {
static ui::Context context;
static ui::SystemView system_view {
context,
portapack::display.screen_rect()
};
EventDispatcher event_dispatcher { &system_view, context };
MessageHandlerRegistration message_handler_display_sleep {
static MessageHandlerRegistration message_handler_display_sleep {
Message::ID::DisplaySleep,
[&event_dispatcher](const Message* const) {
event_dispatcher.set_display_sleep(true);

View File

@ -29,6 +29,7 @@
#include "bmp_splash.hpp"
#include "bmp_modal_warning.hpp"
#include "portapack_persistent_memory.hpp"
#include "portapack_shared_memory.hpp"
#include "ui_about_simple.hpp"
#include "ui_adsb_rx.hpp"
@ -748,6 +749,36 @@ Context& SystemView::context() const {
return context_;
}
void SystemView::toggle_overlay() {
if (overlay_active){
this->remove_child(&this->overlay);
this->set_dirty();
shared_memory.request_m4_performance_counter = 0;
}
else{
this->add_child(&this->overlay);
this->set_dirty();
shared_memory.request_m4_performance_counter = 1;
shared_memory.m4_cpu_usage = 0;
shared_memory.m4_heap_usage = 0;
shared_memory.m4_stack_usage = 0;
}
overlay_active = !overlay_active;
}
void SystemView::paint_overlay() {
static bool last_paint_state = false;
if (overlay_active){
// paint background only every other second
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
last_paint_state = !last_paint_state;
this->overlay.set_dirty();
}
}
/* ***********************************************************************/
void BMPView::focus() {

View File

@ -33,6 +33,7 @@
#include "ui_channel.hpp"
#include "ui_audio.hpp"
#include "ui_sd_card_status_view.hpp"
#include "ui_dfu_menu.hpp"
#include "bitmap.hpp"
#include "ff.h"
@ -290,10 +291,15 @@ namespace ui
const Rect parent_rect);
Context &context() const override;
void toggle_overlay();
void paint_overlay();
private:
bool overlay_active {false};
SystemStatusView status_view{navigation_view};
InformationView info_view{navigation_view};
DfuMenu overlay{navigation_view};
NavigationView navigation_view{};
Context &context_;
};

View File

@ -508,6 +508,8 @@
}
#endif
/**
* @brief System tick event hook.
* @details This hook is invoked in the system tick handler immediately
@ -516,6 +518,8 @@
#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__)
#define SYSTEM_TICK_EVENT_HOOK() { \
/* System tick event code here.*/ \
extern void update_performance_counters(); \
update_performance_counters(); \
}
#endif

View File

@ -116,5 +116,35 @@ CH_IRQ_HANDLER(HardFaultVector) {
#endif
}
void update_performance_counters() {
auto performance_counter_active = shared_memory.request_m4_performance_counter;
if (performance_counter_active == 0x00)
return;
static bool last_paint_state = false;
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
last_paint_state = !last_paint_state;
auto now = chTimeNow();
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
static systime_t last_time;
static systime_t last_last_time;
auto time_elapsed = now - last_time;
auto idle_elapsed = idle_ticks - last_last_time;
last_time = now;
last_last_time = idle_ticks;
auto cpu_usage = (time_elapsed - idle_elapsed) / 10;
auto free_stack = (uint32_t)get_free_stack_space();
auto free_heap = chCoreStatus();
shared_memory.m4_cpu_usage = cpu_usage;
shared_memory.m4_stack_usage = free_stack;
shared_memory.m4_heap_usage = free_heap;
}
} /* extern "C" */

View File

@ -20,6 +20,7 @@
*/
#include "event_m4.hpp"
#include "debug.hpp"
#include "portapack_shared_memory.hpp"
@ -120,3 +121,4 @@ void EventDispatcher::handle_spectrum() {
const UpdateSpectrumMessage message;
baseband_processor->on_message(&message);
}

View File

@ -45,3 +45,5 @@ int main() {
return 0;
}
void update_performance_counters() {}

View File

@ -64,6 +64,11 @@ struct SharedMemory {
JammerChannel jammer_channels[24];
uint8_t data[512];
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
uint8_t volatile request_m4_performance_counter{ 0 };
uint8_t volatile m4_cpu_usage{ 0 };
uint16_t volatile m4_stack_usage{ 0 };
uint16_t volatile m4_heap_usage{ 0 };
};
extern SharedMemory& shared_memory;