From 37cfcb0d5c513c0bdda09077f1bca6c9cfdbda27 Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 13 Mar 2023 22:55:48 +0100 Subject: [PATCH 1/4] added focusable ability to rssi field --- firmware/application/ui/ui_rssi.cpp | 47 +++++++++ firmware/application/ui/ui_rssi.hpp | 148 +++++++++++++++------------- 2 files changed, 125 insertions(+), 70 deletions(-) diff --git a/firmware/application/ui/ui_rssi.cpp b/firmware/application/ui/ui_rssi.cpp index 8c4f483a..1cfc2d0f 100644 --- a/firmware/application/ui/ui_rssi.cpp +++ b/firmware/application/ui/ui_rssi.cpp @@ -162,6 +162,14 @@ namespace ui { if (pitch_rssi_enabled) { baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true); } + if( has_focus() || highlighted() ) + { + const Rect r6 { r.left(), r.top(), r.width(), r.height() }; + painter.draw_rectangle( + r6, + Color::white() + ); + } } int32_t RSSI::get_min() @@ -317,4 +325,43 @@ namespace ui { set_dirty(); } + void RSSI::on_focus() { + if( on_highlight ) + on_highlight(*this); + } + + bool RSSI::on_key(const KeyEvent key) { + if( key == KeyEvent::Select ) { + if( on_select ) { + on_select(*this); + return true; + } + } else { + if( on_dir ) { + return on_dir(*this, key); + } + } + return false; + } + + bool RSSI::on_touch(const TouchEvent event) { + switch(event.type) { + case TouchEvent::Type::Start: + set_highlighted(true); + set_dirty(); + if( on_touch_press) { + on_touch_press(*this); + } + return true; + case TouchEvent::Type::End: + set_highlighted(false); + set_dirty(); + if( on_touch_release) { + on_touch_release(*this); + } + return true; + default: + return false; + } + } } /* namespace ui */ diff --git a/firmware/application/ui/ui_rssi.hpp b/firmware/application/ui/ui_rssi.hpp index f3062e44..bd64244f 100644 --- a/firmware/application/ui/ui_rssi.hpp +++ b/firmware/application/ui/ui_rssi.hpp @@ -25,88 +25,96 @@ #include "ui.hpp" #include "ui_widget.hpp" #include "ui_painter.hpp" - #include "event_m0.hpp" - #include "message.hpp" - #include namespace ui { -class RSSI : public Widget { -public: - RSSI( - const Rect parent_rect - ) : Widget { parent_rect }, - min_ { 0 }, - avg_ { 0 }, - max_ { 0 } - { - } + class RSSI : public Widget { + public: + std::function on_select { }; + std::function on_touch_release { }; // Executed when releasing touch, after on_select. + std::function on_touch_press { }; // Executed when touching, before on_select. + std::function on_dir { }; + std::function on_highlight { }; - void paint(Painter& painter) override; - int32_t get_min(); - int32_t get_avg(); - int32_t get_max(); - int32_t get_delta(); - void set_vertical_rssi(bool enabled); - void set_peak(bool enabled, size_t duration); - -private: - int32_t min_; - int32_t avg_; - int32_t max_; - int32_t peak_ = 0 ; - size_t peak_duration_ = 0 ; - - bool pitch_rssi_enabled = false; - bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top] - // instead of [horizontally/from left to right] - bool peak_enabled = false; - size_t peak_duration = 1000; // peak duration in msec before being reset to actual max_rssi + RSSI( + const Rect parent_rect + ) : Widget { parent_rect }, + min_ { 0 }, + avg_ { 0 }, + max_ { 0 } + { + } - MessageHandlerRegistration message_handler_stats { - Message::ID::RSSIStatistics, - [this](const Message* const p) { - this->on_statistics_update(static_cast(p)->statistics); - } - }; - - MessageHandlerRegistration message_handler_pitch_rssi { - Message::ID::PitchRSSIConfigure, - [this](const Message* const p) { - const auto message = *reinterpret_cast(p); - this->set_pitch_rssi(message.enabled); - } - }; + int32_t get_min(); + int32_t get_avg(); + int32_t get_max(); + int32_t get_delta(); + void set_vertical_rssi(bool enabled); + void set_peak(bool enabled, size_t duration); + + void paint(Painter& painter) override; + void on_focus() override; + bool on_key(const KeyEvent key) override; + bool on_touch(const TouchEvent event) override; - void on_statistics_update(const RSSIStatistics& statistics); - void set_pitch_rssi(bool enabled); -}; + private: + int32_t min_; + int32_t avg_; + int32_t max_; + int32_t peak_ = 0 ; + size_t peak_duration_ = 0 ; + bool instant_exec_ { false }; -struct RSSIGraph_entry { - int32_t rssi_min { 0 }; - int32_t rssi_avg { 0 }; - int32_t rssi_max { 0 }; - int32_t db { 0 }; -}; + bool pitch_rssi_enabled = false; + bool vertical_rssi_enabled = false; // scale [vertically/from bottom to top] + // instead of [horizontally/from left to right] + bool peak_enabled = false; + size_t peak_duration = 1000; // peak duration in msec before being reset to actual max_rssi -using RSSIGraphList = std::vector; + MessageHandlerRegistration message_handler_stats { + Message::ID::RSSIStatistics, + [this](const Message* const p) { + this->on_statistics_update(static_cast(p)->statistics); + } + }; -class RSSIGraph : public Widget { -public: - RSSIGraph( - const Rect parent_rect - ) : Widget { parent_rect } - { - } - void paint(Painter& painter) override; - void add_values(int32_t rssi_min, int32_t rssi_avg, int32_t rssi_max, int32_t db ); - -private: - RSSIGraphList graph_list { } ; -}; + MessageHandlerRegistration message_handler_pitch_rssi { + Message::ID::PitchRSSIConfigure, + [this](const Message* const p) { + const auto message = *reinterpret_cast(p); + this->set_pitch_rssi(message.enabled); + } + }; + + void on_statistics_update(const RSSIStatistics& statistics); + void set_pitch_rssi(bool enabled); + }; + + struct RSSIGraph_entry { + int32_t rssi_min { 0 }; + int32_t rssi_avg { 0 }; + int32_t rssi_max { 0 }; + int32_t db { 0 }; + }; + + using RSSIGraphList = std::vector; + + class RSSIGraph : public Widget { + public: + RSSIGraph( + const Rect parent_rect + ) : Widget { parent_rect } + { + } + void paint(Painter& painter) override; + void add_values(int32_t rssi_min, int32_t rssi_avg, int32_t rssi_max, int32_t db ); + + private: + RSSIGraphList graph_list { } ; + }; } From 8db44d1a9284e0b7ec2f85d69970c69db47b45d1 Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 13 Mar 2023 22:56:47 +0100 Subject: [PATCH 2/4] fixed a text size, used new rssi focusable property so you can launch the level app by touching or selecting and clicking the rssi bars --- firmware/application/apps/ui_recon.cpp | 17 +++++++++++++++-- firmware/application/apps/ui_recon.hpp | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index 9f185e94..170ed044 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -524,15 +524,21 @@ namespace ui { if(frequency_list[index].description.size() > 0) desc_cycle.set( frequency_list[index].description ); //Show new description } big_display.set_style(&style_white); + if( !userpause ) + button_pause.set_text(""); + else + button_pause.set_text(""); } else if( freq_lock == 1 && recon_lock_nb_match != 1 ) { //STARTING LOCK FREQ big_display.set_style(&style_yellow); + button_pause.set_text(""); } else if( index < 1000 && freq_lock >= recon_thread -> get_lock_nb_match() ) { big_display.set_style( &style_green); + button_pause.set_text(""); //FREQ IS STRONG: GREEN and recon will pause when on_statistics_update() if( (!scanner_mode) && autosave && last_freq != freq ) { @@ -874,6 +880,13 @@ namespace ui { nav_.pop(); nav_.push(); }; + + rssi.set_focusable(true); + rssi.on_select = [this](RSSI&) { + recon_thread->stop(); + nav_.pop(); + nav_.push(); + }; button_mic_app.on_select = [this](Button&) { recon_thread->stop(); @@ -1653,7 +1666,7 @@ namespace ui { void ReconView::user_pause() { timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq. - button_pause.set_text(""); //PAUSED, show resume + //button_pause.set_text(""); //PAUSED, show resume userpause=true; continuous_lock=false; recon_pause(); @@ -1661,7 +1674,7 @@ namespace ui { void ReconView::user_resume() { timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq. - button_pause.set_text(""); //Show button for pause + //button_pause.set_text(""); //Show button for pause userpause=false; // Resume recon continuous_lock=false; recon_resume(); diff --git a/firmware/application/apps/ui_recon.hpp b/firmware/application/apps/ui_recon.hpp index 1bfaf6e0..0783928d 100644 --- a/firmware/application/apps/ui_recon.hpp +++ b/firmware/application/apps/ui_recon.hpp @@ -31,6 +31,7 @@ #include "analog_audio_app.hpp" #include "audio.hpp" #include "ui_mictx.hpp" +#include "ui_level.hpp" #include "portapack_persistent_memory.hpp" #include "baseband_api.hpp" #include "string_format.hpp" @@ -307,10 +308,9 @@ namespace ui { }; Text file_name { //Show file used - { 0 , 8 * 16 + 4 , 20 * 8, 16 }, + { 0 , 8 * 16 + 4 , 21 * 8, 16 }, }; - ButtonWithEncoder button_manual_start { { 0 * 8, 11 * 16, 11 * 8, 28 }, "" From ad4cfe5a44b99104ed99dde524edbffb27f1371f Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 13 Mar 2023 23:12:46 +0100 Subject: [PATCH 3/4] adding header guard --- firmware/application/apps/ui_looking_glass_app.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/ui_looking_glass_app.hpp b/firmware/application/apps/ui_looking_glass_app.hpp index df93a819..33e4c937 100644 --- a/firmware/application/apps/ui_looking_glass_app.hpp +++ b/firmware/application/apps/ui_looking_glass_app.hpp @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +#ifndef _UI_GLASS +#define _UI_GLASS + #include "ui.hpp" #include "portapack.hpp" #include "baseband_api.hpp" @@ -184,4 +187,4 @@ }; } - +#endif From f7df4f3575a24e7206f0e5e57c96319c574aa056 Mon Sep 17 00:00:00 2001 From: GullCode Date: Mon, 13 Mar 2023 23:14:06 +0100 Subject: [PATCH 4/4] Use rssi focusable, added shortcut to level app, glass app, cut buttons a bit better in the ui, better pause/resume/skiplock/unlock button --- firmware/application/apps/ui_recon.cpp | 10 +++++++++- firmware/application/apps/ui_recon.hpp | 14 ++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/firmware/application/apps/ui_recon.cpp b/firmware/application/apps/ui_recon.cpp index 170ed044..3b05a147 100644 --- a/firmware/application/apps/ui_recon.cpp +++ b/firmware/application/apps/ui_recon.cpp @@ -666,6 +666,7 @@ namespace ui { &field_lock_wait, &button_recon_setup, &button_scanner_mode, + &button_looking_glass, &file_name, &rssi, &text_cycle, @@ -880,6 +881,13 @@ namespace ui { nav_.pop(); nav_.push(); }; + + button_looking_glass.on_select = [this](Button&) { + recon_thread->stop(); + nav_.pop(); + nav_.push(); + }; + rssi.set_focusable(true); rssi.on_select = [this](RSSI&) { @@ -1104,7 +1112,7 @@ namespace ui { show_max(); /* display step information */ text_cycle.set( "MANUAL SEARCH" ); button_scanner_mode.set_style( &style_white ); - button_scanner_mode.set_text( "M-SEARCH" ); + button_scanner_mode.set_text( "MSEARCH" ); file_name.set_style( &style_white ); file_name.set( "USE: MANUAL RANGE" ); diff --git a/firmware/application/apps/ui_recon.hpp b/firmware/application/apps/ui_recon.hpp index 0783928d..c3196cbe 100644 --- a/firmware/application/apps/ui_recon.hpp +++ b/firmware/application/apps/ui_recon.hpp @@ -32,6 +32,7 @@ #include "audio.hpp" #include "ui_mictx.hpp" #include "ui_level.hpp" +#include "ui_looking_glass_app.hpp" #include "portapack_persistent_memory.hpp" #include "baseband_api.hpp" #include "string_format.hpp" @@ -286,15 +287,15 @@ namespace ui { }; */ Text big_display { //Show frequency in text mode - { 0, 5 * 16 , 28 * 8, 16 }, + { 0, 5 * 16 , 21 * 8, 16 }, }; Text freq_stats { //Show frequency stats in text mode - { 0, 6 * 16 , 28 * 8, 16 }, + { 0, 6 * 16 , 21 * 8, 16 }, }; Text text_timer { //Show frequency stats in text mode - { 0, 7 * 16 , 28 * 8, 16 }, + { 0, 7 * 16 , 21 * 8, 16 }, }; Button button_recon_setup { @@ -302,8 +303,13 @@ namespace ui { "OPT" }; + Button button_looking_glass { + { 240 - 5 * 8 , 6 * 16 , 5 * 8, 28 }, + "GLASS" + }; + Button button_scanner_mode { - { 21 * 8 , 8 * 16 , 9 * 8, 28 }, + { 240 - 8 * 8 , 8 * 16 , 8 * 8, 28 }, "RECON" };