From 2f54c11fea44244f0f82ab5954967b87a3454bbb Mon Sep 17 00:00:00 2001 From: dqs105 <69909636+dqs105@users.noreply.github.com> Date: Fri, 21 Aug 2020 23:18:53 +0800 Subject: [PATCH 1/7] Added TX Gain control & code simplification A bug that enabling audio RX resets the TX gain (perhaps because that changing to receiving mode modifies some registers) inspired me to add this gain control. Commented out some steps which don't require for the VU meter to work again. Moved some widgets for gain control. --- firmware/application/apps/ui_mictx.cpp | 23 ++++++++++++++--- firmware/application/apps/ui_mictx.hpp | 35 +++++++++++++++++++------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index 0d7b2367..955bd6eb 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -140,11 +140,13 @@ void MicTXView::rxaudio(bool is_on) { baseband::shutdown(); baseband::run_image(portapack::spi_flash::image_tag_mic_tx); audio::input::start(); - transmitter_model.enable(); +// transmitter_model.enable(); portapack::pin_i2s0_rx_sda.mode(3); - transmitting = false; +// transmitting = false; configure_baseband(); - transmitter_model.disable(); +// transmitter_model.disable(); + transmitter_model.set_tx_gain(transmitter_model.tx_gain()); + transmitter_model.set_rf_amp(transmitter_model.rf_amp()); } } @@ -172,6 +174,8 @@ MicTXView::MicTXView( &field_va_attack, &field_va_decay, &field_bw, + &field_rfgain, + &field_rfamp, &field_frequency, &options_tone_key, &check_rogerbeep, @@ -213,6 +217,17 @@ MicTXView::MicTXView( }; field_bw.set_value(10); + field_rfgain.on_change = [this](int32_t v) { + transmitter_model.set_tx_gain(v); + }; + field_rfgain.set_value(transmitter_model.tx_gain()); + + field_rfamp.on_change = [this](int32_t v) { + transmitter_model.set_rf_amp((bool)v); + }; + field_rfamp.set_value(transmitter_model.rf_amp() ? 14 : 0); + + check_va.on_select = [this](Checkbox&, bool v) { va_enabled = v; text_ptt.hidden(v); //hide / show PTT text @@ -241,7 +256,7 @@ MicTXView::MicTXView( field_va_decay.set_value(1000); check_rxactive.on_select = [this](Checkbox&, bool v) { - //vumeter.set_value(0); //Start with a clean vumeter +// vumeter.set_value(0); //Start with a clean vumeter rx_enabled = v; check_va.hidden(v); //Hide or show voice activation rxaudio(v); //Activate-Deactivate audio rx accordingly diff --git a/firmware/application/apps/ui_mictx.hpp b/firmware/application/apps/ui_mictx.hpp index 0f27206c..c97e913f 100644 --- a/firmware/application/apps/ui_mictx.hpp +++ b/firmware/application/apps/ui_mictx.hpp @@ -88,10 +88,12 @@ private: { { 3 * 8, 1 * 8 }, "MIC. GAIN:", Color::light_grey() }, { { 3 * 8, 3 * 8 }, "FREQUENCY:", Color::light_grey() }, { { 3 * 8, 5 * 8 }, "BANDWIDTH: kHz", Color::light_grey() }, - { { 7 * 8, 11 * 8 }, "LEVEL: /255", Color::light_grey() }, - { { 6 * 8, 13 * 8 }, "ATTACK: ms", Color::light_grey() }, - { { 7 * 8, 15 * 8 }, "DECAY: ms", Color::light_grey() }, - { { 4 * 8, 18 * 8 }, "TONE KEY:", Color::light_grey() }, + { { 3 * 8, 7 * 8 }, "RFGAIN:", Color::light_grey() }, + { {13 * 8, 7 * 8 }, "Amp:", Color::light_grey() }, + { { 7 * 8, 12 * 8 }, "LEVEL: /255", Color::light_grey() }, + { { 6 * 8, 14 * 8 }, "ATTACK: ms", Color::light_grey() }, + { { 7 * 8, 16 * 8 }, "DECAY: ms", Color::light_grey() }, + { { 4 * 8, ( 19 * 8 ) - 2 }, "TONE KEY:", Color::light_grey() }, { { 9 * 8, 30 * 8 }, "VOL:", Color::light_grey() }, { { 5 * 8, 32 * 8 }, "SQUELCH:", Color::light_grey() } }; @@ -124,29 +126,44 @@ private: ' ' }; + NumberField field_rfgain { + { 10 * 8, 7 * 8 }, + 2, + { 0, 47 }, + 1, + ' ' + }; + NumberField field_rfamp { + { 17 * 8, 7 * 8 }, + 2, + { 0, 14 }, + 14, + ' ' + }; + Checkbox check_va { - { 3 * 8, (9 * 8) - 4 }, + { 3 * 8, (10 * 8) - 4 }, 7, "Voice activation", false }; NumberField field_va_level { - { 13 * 8, 11 * 8 }, + { 13 * 8, 12 * 8 }, 3, { 0, 255 }, 2, ' ' }; NumberField field_va_attack { - { 13 * 8, 13 * 8 }, + { 13 * 8, 14 * 8 }, 3, { 0, 999 }, 20, ' ' }; NumberField field_va_decay { - { 13 * 8, 15 * 8 }, + { 13 * 8, 16 * 8 }, 4, { 0, 9999 }, 100, @@ -154,7 +171,7 @@ private: }; OptionsField options_tone_key { - { 10 * 8, 20 * 8 }, + { 10 * 8, ( 21 * 8 ) - 2 }, 23, { } }; From 4197b5c083d330cc29b2b9fa3711934ee0556ef4 Mon Sep 17 00:00:00 2001 From: dqs105 <69909636+dqs105@users.noreply.github.com> Date: Sat, 22 Aug 2020 14:57:55 +0800 Subject: [PATCH 2/7] Added RX gain control & UI modification Thanks @euquiq for a more common solution to the bug. Added RX gain control. Now we have full gain controls! Merged PTT and Voice activation into one option selector.(allowing RIGHT BUTTON to work with PTT off) --- firmware/application/apps/ui_mictx.cpp | 90 +++++++++++++++++++++++--- firmware/application/apps/ui_mictx.hpp | 70 ++++++++++++++++++-- 2 files changed, 144 insertions(+), 16 deletions(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index 955bd6eb..ce5514e1 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -65,6 +65,8 @@ void MicTXView::set_tx(bool enable) { rxaudio(false); //Then turn off audio RX transmitting = true; configure_baseband(); + transmitter_model.set_tx_gain(tx_gain); + transmitter_model.set_rf_amp(rf_amp); transmitter_model.enable(); portapack::pin_i2s0_rx_sda.mode(3); // This is already done in audio::init but gets changed by the CPLD overlay reprogramming } else { @@ -133,6 +135,9 @@ void MicTXView::rxaudio(bool is_on) { receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); receiver_model.set_tuning_frequency(field_frequency.value()); //probably this too can be commented out. + receiver_model.set_lna(rx_lna); + receiver_model.set_vga(rx_vga); + receiver_model.set_rf_amp(rx_amp); receiver_model.enable(); audio::output::start(); } else { //These incredibly convoluted steps are required for the vumeter to reappear when stopping RX. @@ -157,6 +162,12 @@ void MicTXView::on_headphone_volume_changed(int32_t v) { //} } +void MicTXView::set_ptt_visibility(bool v) { + text_ptt_1.hidden(!v); + text_ptt_2.hidden(!v); + text_ptt_3.hidden(!v); +} + MicTXView::MicTXView( NavigationView& nav ) @@ -169,7 +180,8 @@ MicTXView::MicTXView( &labels, &vumeter, &options_gain, - &check_va, +// &check_va, + &field_va, &field_va_level, &field_va_attack, &field_va_decay, @@ -182,7 +194,12 @@ MicTXView::MicTXView( &check_rxactive, &field_volume, &field_squelch, - &text_ptt + &field_rxlna, + &field_rxvga, + &field_rxamp, + &text_ptt_1, + &text_ptt_2, + &text_ptt_3 }); tone_keys_populate(options_tone_key); @@ -217,24 +234,57 @@ MicTXView::MicTXView( }; field_bw.set_value(10); + tx_gain = transmitter_model.tx_gain(); field_rfgain.on_change = [this](int32_t v) { - transmitter_model.set_tx_gain(v); + tx_gain = v; + }; - field_rfgain.set_value(transmitter_model.tx_gain()); - + field_rfgain.set_value(tx_gain); + + rf_amp = transmitter_model.rf_amp(); field_rfamp.on_change = [this](int32_t v) { - transmitter_model.set_rf_amp((bool)v); + rf_amp = (bool)v; }; - field_rfamp.set_value(transmitter_model.rf_amp() ? 14 : 0); - + field_rfamp.set_value(rf_amp ? 14 : 0); + /* check_va.on_select = [this](Checkbox&, bool v) { va_enabled = v; text_ptt.hidden(v); //hide / show PTT text check_rxactive.hidden(v); //hide / show the RX AUDIO set_dirty(); //Refresh display }; + */ + field_va.set_selected_index(1); + field_va.on_change = [this](size_t, int32_t v) { + switch(v) { + case 0: + va_enabled = 0; + this->set_ptt_visibility(0); + check_rxactive.hidden(0); + ptt_enabled = 0; + break; + case 1: + va_enabled = 0; + this->set_ptt_visibility(1); + check_rxactive.hidden(0); + ptt_enabled = 1; + break; + case 2: + if (!rx_enabled) { + va_enabled = 1; + this->set_ptt_visibility(0); + check_rxactive.hidden(1); + ptt_enabled = 0; + } else { + field_va.set_selected_index(1); + } + break; + } + set_dirty(); + }; + check_rogerbeep.on_select = [this](Checkbox&, bool v) { rogerbeep_enabled = v; }; @@ -258,7 +308,7 @@ MicTXView::MicTXView( check_rxactive.on_select = [this](Checkbox&, bool v) { // vumeter.set_value(0); //Start with a clean vumeter rx_enabled = v; - check_va.hidden(v); //Hide or show voice activation +// check_va.hidden(v); //Hide or show voice activation rxaudio(v); //Activate-Deactivate audio rx accordingly set_dirty(); //Refresh interface }; @@ -272,6 +322,28 @@ MicTXView::MicTXView( field_squelch.set_value(0); receiver_model.set_squelch_level(0); + + rx_lna = receiver_model.lna(); + field_rxlna.on_change = [this](int32_t v) { + rx_lna = v; + receiver_model.set_lna(v); + }; + field_rxlna.set_value(rx_lna); + + rx_vga = receiver_model.vga(); + field_rxvga.on_change = [this](int32_t v) { + rx_vga = v; + receiver_model.set_vga(v); + }; + field_rxvga.set_value(rx_vga); + + rx_amp = receiver_model.rf_amp(); + field_rxamp.on_change = [this](int32_t v) { + rx_amp = (bool)v; + receiver_model.set_rf_amp(rx_amp); + }; + field_rxamp.set_value(rx_amp ? 14 : 0); + transmitter_model.set_sampling_rate(sampling_rate); transmitter_model.set_baseband_bandwidth(1750000); diff --git a/firmware/application/apps/ui_mictx.hpp b/firmware/application/apps/ui_mictx.hpp index c97e913f..159bfbac 100644 --- a/firmware/application/apps/ui_mictx.hpp +++ b/firmware/application/apps/ui_mictx.hpp @@ -48,7 +48,7 @@ public: // PTT: Enable through KeyEvent (only works with presses), disable by polling :( bool on_key(const KeyEvent key) { - if ((key == KeyEvent::Right) && (!va_enabled)) { + if ((key == KeyEvent::Right) && (!va_enabled) && ptt_enabled) { set_tx(true); return true; } else @@ -70,9 +70,12 @@ private: void rxaudio(bool is_on); void on_headphone_volume_changed(int32_t v); + + void set_ptt_visibility(bool v); bool transmitting { false }; bool va_enabled { false }; + bool ptt_enabled { true }; bool rogerbeep_enabled { false }; bool rx_enabled { false }; uint32_t tone_key_index { }; @@ -83,6 +86,12 @@ private: uint32_t decay_ms { }; uint32_t attack_timer { 0 }; uint32_t decay_timer { 0 }; + int32_t tx_gain { 47 }; + bool rf_amp { false }; + int32_t rx_lna { 32 }; + int32_t rx_vga { 32 }; + bool rx_amp { false }; + Labels labels { { { 3 * 8, 1 * 8 }, "MIC. GAIN:", Color::light_grey() }, @@ -90,12 +99,16 @@ private: { { 3 * 8, 5 * 8 }, "BANDWIDTH: kHz", Color::light_grey() }, { { 3 * 8, 7 * 8 }, "RFGAIN:", Color::light_grey() }, { {13 * 8, 7 * 8 }, "Amp:", Color::light_grey() }, + { { 3 * 8, 10 * 8 }, "TX Activation:", Color::light_grey() }, { { 7 * 8, 12 * 8 }, "LEVEL: /255", Color::light_grey() }, { { 6 * 8, 14 * 8 }, "ATTACK: ms", Color::light_grey() }, { { 7 * 8, 16 * 8 }, "DECAY: ms", Color::light_grey() }, { { 4 * 8, ( 19 * 8 ) - 2 }, "TONE KEY:", Color::light_grey() }, { { 9 * 8, 30 * 8 }, "VOL:", Color::light_grey() }, - { { 5 * 8, 32 * 8 }, "SQUELCH:", Color::light_grey() } + { { 5 * 8, 32 * 8 }, "SQUELCH:", Color::light_grey() }, + { { 5 * 8, 34 * 8 }, "LNA:", Color::light_grey()}, + { {12 * 8, 34 * 8 }, "VGA:", Color::light_grey()}, + { {19 * 8, 34 * 8 }, "AMP:", Color::light_grey()} }; VuMeter vumeter { @@ -140,14 +153,25 @@ private: 14, ' ' }; - + /* Checkbox check_va { { 3 * 8, (10 * 8) - 4 }, 7, "Voice activation", false }; - + */ + + OptionsField field_va { + { 17 * 8, 10 * 8 }, + 3, + { + {" OFF", 0}, + {" PTT", 1}, + {"AUTO", 2} + } + }; + NumberField field_va_level { { 13 * 8, 12 * 8 }, 3, @@ -206,9 +230,41 @@ private: ' ', }; - Text text_ptt { - { 7 * 8, 35 * 8, 16 * 8, 16 }, - "PTT: RIGHT BUTTON" + NumberField field_rxlna { + { 9 * 8, 34 * 8 }, + 2, + { 0, 40 }, + 8, + ' ', + }; + + NumberField field_rxvga { + { 16 * 8, 34 * 8 }, + 2, + { 0, 62 }, + 2, + ' ', + }; + + NumberField field_rxamp { + { 23 * 8, 34 * 8 }, + 2, + { 0, 14 }, + 14, + ' ', + }; + + Text text_ptt_1 { + { 22 * 8, 13 * 8, 7 * 8, 8 }, + "PTT: " + }; + Text text_ptt_2 { + { 22 * 8, 15 * 8, 7 * 8, 8 }, + "RIGHT " + }; + Text text_ptt_3 { + { 22 * 8, 17 * 8, 7 * 8, 8 }, + "BUTTON" }; From 0f88efc44eab33635f6f7bad6b73318e189ad373 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Sun, 23 Aug 2020 17:41:31 +0800 Subject: [PATCH 3/7] Tx led fix & UI tweak & Rx frequency --- firmware/application/apps/ui_mictx.cpp | 59 ++++++++++++++++++++++---- firmware/application/apps/ui_mictx.hpp | 28 +++++++----- firmware/application/radio.cpp | 3 +- 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index ce5514e1..ca6d2662 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -37,7 +37,17 @@ using namespace portapack; namespace ui { void MicTXView::focus() { - field_frequency.focus(); + switch(focused_ui) { + case 0: + field_frequency.focus(); + break; + case 1: + field_rxfrequency.focus(); + break; + default: + field_frequency.focus(); + break; + } } void MicTXView::update_vumeter() { @@ -65,6 +75,7 @@ void MicTXView::set_tx(bool enable) { rxaudio(false); //Then turn off audio RX transmitting = true; configure_baseband(); + transmitter_model.set_tuning_frequency(tx_frequency); transmitter_model.set_tx_gain(tx_gain); transmitter_model.set_rf_amp(rf_amp); transmitter_model.enable(); @@ -120,11 +131,13 @@ void MicTXView::do_timing() { } } +/* Hmmmm. Maybe useless now. void MicTXView::on_tuning_frequency_changed(rf::Frequency f) { transmitter_model.set_tuning_frequency(f); //if ( rx_enabled ) receiver_model.set_tuning_frequency(f); //Update freq also for RX } +*/ void MicTXView::rxaudio(bool is_on) { if (is_on) { @@ -134,7 +147,8 @@ void MicTXView::rxaudio(bool is_on) { receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); receiver_model.set_sampling_rate(3072000); receiver_model.set_baseband_bandwidth(1750000); - receiver_model.set_tuning_frequency(field_frequency.value()); //probably this too can be commented out. +// receiver_model.set_tuning_frequency(field_frequency.value()); //probably this too can be commented out. + receiver_model.set_tuning_frequency(rx_frequency); // Now with seperate controls! receiver_model.set_lna(rx_lna); receiver_model.set_vga(rx_vga); receiver_model.set_rf_amp(rx_amp); @@ -150,8 +164,6 @@ void MicTXView::rxaudio(bool is_on) { // transmitting = false; configure_baseband(); // transmitter_model.disable(); - transmitter_model.set_tx_gain(transmitter_model.tx_gain()); - transmitter_model.set_rf_amp(transmitter_model.rf_amp()); } } @@ -194,6 +206,7 @@ MicTXView::MicTXView( &check_rxactive, &field_volume, &field_squelch, + &field_rxfrequency, &field_rxlna, &field_rxvga, &field_rxamp, @@ -214,16 +227,22 @@ MicTXView::MicTXView( }; options_gain.set_selected_index(1); // x1.0 + tx_frequency = transmitter_model.tuning_frequency(); field_frequency.set_value(transmitter_model.tuning_frequency()); field_frequency.set_step(receiver_model.frequency_step()); field_frequency.on_change = [this](rf::Frequency f) { - this->on_tuning_frequency_changed(f); + tx_frequency = f; + if(!rx_enabled) + transmitter_model.set_tuning_frequency(f); }; field_frequency.on_edit = [this, &nav]() { // TODO: Provide separate modal method/scheme? - auto new_view = nav.push(receiver_model.tuning_frequency()); + auto new_view = nav.push(tx_frequency); new_view->on_changed = [this](rf::Frequency f) { - this->on_tuning_frequency_changed(f); + focused_ui = 0; + tx_frequency = f; + if(!rx_enabled) + transmitter_model.set_tuning_frequency(f); this->field_frequency.set_value(f); set_dirty(); }; @@ -322,6 +341,27 @@ MicTXView::MicTXView( field_squelch.set_value(0); receiver_model.set_squelch_level(0); + rx_frequency = receiver_model.tuning_frequency(); + field_rxfrequency.set_value(rx_frequency); + field_rxfrequency.set_step(receiver_model.frequency_step()); + field_rxfrequency.on_change = [this](rf::Frequency f) { + rx_frequency = f; + if(rx_enabled) + receiver_model.set_tuning_frequency(f); + }; + field_rxfrequency.on_edit = [this, &nav]() { + // TODO: Provide separate modal method/scheme? + auto new_view = nav.push(rx_frequency); + new_view->on_changed = [this](rf::Frequency f) { + focused_ui = 1; + rx_frequency = f; + if(rx_enabled) + receiver_model.set_tuning_frequency(f); + this->field_rxfrequency.set_value(f); + set_dirty(); + }; + }; + rx_lna = receiver_model.lna(); field_rxlna.on_change = [this](int32_t v) { @@ -339,10 +379,10 @@ MicTXView::MicTXView( rx_amp = receiver_model.rf_amp(); field_rxamp.on_change = [this](int32_t v) { - rx_amp = (bool)v; + rx_amp = v; receiver_model.set_rf_amp(rx_amp); }; - field_rxamp.set_value(rx_amp ? 14 : 0); + field_rxamp.set_value(rx_amp); transmitter_model.set_sampling_rate(sampling_rate); transmitter_model.set_baseband_bandwidth(1750000); @@ -355,6 +395,7 @@ MicTXView::MicTXView( MicTXView::~MicTXView() { audio::input::stop(); + transmitter_model.set_tuning_frequency(tx_frequency); // Save Tx frequency instead of Rx. Or maybe we need some "System Wide" changes to seperate Tx and Rx frequency. transmitter_model.disable(); if (rx_enabled) //Also turn off audio rx if enabled rxaudio(false); diff --git a/firmware/application/apps/ui_mictx.hpp b/firmware/application/apps/ui_mictx.hpp index 159bfbac..0b0c6d6e 100644 --- a/firmware/application/apps/ui_mictx.hpp +++ b/firmware/application/apps/ui_mictx.hpp @@ -64,7 +64,7 @@ private: void update_vumeter(); void do_timing(); void set_tx(bool enable); - void on_tuning_frequency_changed(rf::Frequency f); +// void on_tuning_frequency_changed(rf::Frequency f); void on_tx_progress(const bool done); void configure_baseband(); @@ -91,6 +91,9 @@ private: int32_t rx_lna { 32 }; int32_t rx_vga { 32 }; bool rx_amp { false }; + rf::Frequency tx_frequency { 0 }; + rf::Frequency rx_frequency { 0 }; + int32_t focused_ui { 0 }; Labels labels { @@ -106,9 +109,10 @@ private: { { 4 * 8, ( 19 * 8 ) - 2 }, "TONE KEY:", Color::light_grey() }, { { 9 * 8, 30 * 8 }, "VOL:", Color::light_grey() }, { { 5 * 8, 32 * 8 }, "SQUELCH:", Color::light_grey() }, - { { 5 * 8, 34 * 8 }, "LNA:", Color::light_grey()}, - { {12 * 8, 34 * 8 }, "VGA:", Color::light_grey()}, - { {19 * 8, 34 * 8 }, "AMP:", Color::light_grey()} + { { 5 * 8, 34 * 8 }, "FREQUENCY:", Color::light_grey() }, + { { 5 * 8, 36 * 8 }, "LNA:", Color::light_grey()}, + { {12 * 8, 36 * 8 }, "VGA:", Color::light_grey()}, + { {19 * 8, 36 * 8 }, "AMP:", Color::light_grey()} }; VuMeter vumeter { @@ -230,8 +234,12 @@ private: ' ', }; + FrequencyField field_rxfrequency { + { 15 * 8, 34 * 8 }, + }; + NumberField field_rxlna { - { 9 * 8, 34 * 8 }, + { 9 * 8, 36 * 8 }, 2, { 0, 40 }, 8, @@ -239,7 +247,7 @@ private: }; NumberField field_rxvga { - { 16 * 8, 34 * 8 }, + { 16 * 8, 36 * 8 }, 2, { 0, 62 }, 2, @@ -247,10 +255,10 @@ private: }; NumberField field_rxamp { - { 23 * 8, 34 * 8 }, - 2, - { 0, 14 }, - 14, + { 23 * 8, 36 * 8 }, + 1, + { 0, 1 }, + 1, ' ', }; diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index 60981c70..ccd9bf7e 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -157,13 +157,14 @@ bool set_tuning_frequency(const rf::Frequency frequency) { void set_rf_amp(const bool rf_amp) { rf_path.set_rf_amp(rf_amp); - + /* if (direction == rf::Direction::Transmit) { if (rf_amp) led_tx.on(); else led_tx.off(); } + */ } void set_lna_gain(const int_fast8_t db) { From d7568b820ddd8df090ebad68c03db1547ac2a6fa Mon Sep 17 00:00:00 2001 From: dqs105 Date: Mon, 24 Aug 2020 01:53:34 +0800 Subject: [PATCH 4/7] UI tweak & new PTT button --- firmware/application/apps/ui_mictx.cpp | 36 +++++++--- firmware/application/apps/ui_mictx.hpp | 87 ++++++++++++----------- firmware/common/ui_widget.cpp | 95 ++++++++++++++++++++++++++ firmware/common/ui_widget.hpp | 28 ++++++++ 4 files changed, 191 insertions(+), 55 deletions(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index ca6d2662..d70e724f 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -45,7 +45,7 @@ void MicTXView::focus() { field_rxfrequency.focus(); break; default: - field_frequency.focus(); + field_va.focus(); break; } } @@ -126,7 +126,7 @@ void MicTXView::do_timing() { } else { // Check for PTT release const auto switches_state = get_switches_state(); - if (!switches_state[0] && transmitting) // Right button + if (!switches_state[4] && transmitting && !button_touch) // Select button set_tx(false); } } @@ -175,9 +175,7 @@ void MicTXView::on_headphone_volume_changed(int32_t v) { } void MicTXView::set_ptt_visibility(bool v) { - text_ptt_1.hidden(!v); - text_ptt_2.hidden(!v); - text_ptt_3.hidden(!v); + tx_button.hidden(!v); } MicTXView::MicTXView( @@ -210,9 +208,7 @@ MicTXView::MicTXView( &field_rxlna, &field_rxvga, &field_rxamp, - &text_ptt_1, - &text_ptt_2, - &text_ptt_3 + &tx_button }); tone_keys_populate(options_tone_key); @@ -236,10 +232,10 @@ MicTXView::MicTXView( transmitter_model.set_tuning_frequency(f); }; field_frequency.on_edit = [this, &nav]() { + focused_ui = 0; // TODO: Provide separate modal method/scheme? auto new_view = nav.push(tx_frequency); new_view->on_changed = [this](rf::Frequency f) { - focused_ui = 0; tx_frequency = f; if(!rx_enabled) transmitter_model.set_tuning_frequency(f); @@ -350,10 +346,10 @@ MicTXView::MicTXView( receiver_model.set_tuning_frequency(f); }; field_rxfrequency.on_edit = [this, &nav]() { + focused_ui = 1; // TODO: Provide separate modal method/scheme? auto new_view = nav.push(rx_frequency); new_view->on_changed = [this](rf::Frequency f) { - focused_ui = 1; rx_frequency = f; if(rx_enabled) receiver_model.set_tuning_frequency(f); @@ -384,6 +380,26 @@ MicTXView::MicTXView( }; field_rxamp.set_value(rx_amp); + tx_button.on_select = [this](TxButton&) { + if(ptt_enabled && !transmitting) { + button_touch = true; + set_tx(true); + } + }; + + tx_button.on_release = [this](TxButton&) { + if(button_touch) { + button_touch = false; + set_tx(false); + } + }; + + tx_button.on_buttonpress = [this](TxButton&) { + if(ptt_enabled && !transmitting) { + set_tx(true); + } + }; + transmitter_model.set_sampling_rate(sampling_rate); transmitter_model.set_baseband_bandwidth(1750000); diff --git a/firmware/application/apps/ui_mictx.hpp b/firmware/application/apps/ui_mictx.hpp index 0b0c6d6e..cb735503 100644 --- a/firmware/application/apps/ui_mictx.hpp +++ b/firmware/application/apps/ui_mictx.hpp @@ -47,6 +47,8 @@ public: void focus() override; // PTT: Enable through KeyEvent (only works with presses), disable by polling :( + // This is the old "RIGHT BUTTON" method. + /* bool on_key(const KeyEvent key) { if ((key == KeyEvent::Right) && (!va_enabled) && ptt_enabled) { set_tx(true); @@ -54,7 +56,8 @@ public: } else return false; }; - + */ + std::string title() const override { return "Mic TX RX"; }; private: @@ -93,26 +96,27 @@ private: bool rx_amp { false }; rf::Frequency tx_frequency { 0 }; rf::Frequency rx_frequency { 0 }; - int32_t focused_ui { 0 }; + int32_t focused_ui { 2 }; + bool button_touch { true }; Labels labels { { { 3 * 8, 1 * 8 }, "MIC. GAIN:", Color::light_grey() }, - { { 3 * 8, 3 * 8 }, "FREQUENCY:", Color::light_grey() }, - { { 3 * 8, 5 * 8 }, "BANDWIDTH: kHz", Color::light_grey() }, - { { 3 * 8, 7 * 8 }, "RFGAIN:", Color::light_grey() }, - { {13 * 8, 7 * 8 }, "Amp:", Color::light_grey() }, - { { 3 * 8, 10 * 8 }, "TX Activation:", Color::light_grey() }, - { { 7 * 8, 12 * 8 }, "LEVEL: /255", Color::light_grey() }, - { { 6 * 8, 14 * 8 }, "ATTACK: ms", Color::light_grey() }, - { { 7 * 8, 16 * 8 }, "DECAY: ms", Color::light_grey() }, - { { 4 * 8, ( 19 * 8 ) - 2 }, "TONE KEY:", Color::light_grey() }, - { { 9 * 8, 30 * 8 }, "VOL:", Color::light_grey() }, - { { 5 * 8, 32 * 8 }, "SQUELCH:", Color::light_grey() }, - { { 5 * 8, 34 * 8 }, "FREQUENCY:", Color::light_grey() }, - { { 5 * 8, 36 * 8 }, "LNA:", Color::light_grey()}, - { {12 * 8, 36 * 8 }, "VGA:", Color::light_grey()}, - { {19 * 8, 36 * 8 }, "AMP:", Color::light_grey()} + { { 3 * 8, 3 * 8 }, "F:", Color::light_grey() }, + { { 15 * 8, 3 * 8 }, "BW: kHz", Color::light_grey() }, + { { 3 * 8, 5 * 8 }, "GAIN:", Color::light_grey() }, + { {11 * 8, 5 * 8 }, "Amp:", Color::light_grey() }, + { { 3 * 8, 8 * 8 }, "TX Activation:", Color::light_grey() }, + { { 4 * 8, 10 * 8 }, "LVL:", Color::light_grey() }, + { {12 * 8, 10 * 8 }, "ATT:", Color::light_grey() }, + { {20 * 8, 10 * 8 }, "DEC:", Color::light_grey() }, + { { 4 * 8, ( 13 * 8 ) - 2 }, "TONE KEY:", Color::light_grey() }, + { { 9 * 8, 23 * 8 }, "VOL:", Color::light_grey() }, + { {17 * 8, 25 * 8 }, "SQ:", Color::light_grey() }, + { { 5 * 8, 25 * 8 }, "F:", Color::light_grey() }, + { { 5 * 8, 27 * 8 }, "LNA:", Color::light_grey()}, + { {12 * 8, 27 * 8 }, "VGA:", Color::light_grey()}, + { {19 * 8, 27 * 8 }, "AMP:", Color::light_grey()} }; VuMeter vumeter { @@ -120,6 +124,7 @@ private: 12, true }; + OptionsField options_gain { { 13 * 8, 1 * 8 }, @@ -133,10 +138,10 @@ private: }; FrequencyField field_frequency { - { 13 * 8, 3 * 8 }, + { 5 * 8, 3 * 8 }, }; NumberField field_bw { - { 13 * 8, 5 * 8 }, + { 18 * 8, 3 * 8 }, 3, { 0, 150 }, 1, @@ -144,14 +149,14 @@ private: }; NumberField field_rfgain { - { 10 * 8, 7 * 8 }, + { 8 * 8, 5 * 8 }, 2, { 0, 47 }, 1, ' ' }; NumberField field_rfamp { - { 17 * 8, 7 * 8 }, + { 15 * 8, 5 * 8 }, 2, { 0, 14 }, 14, @@ -167,7 +172,7 @@ private: */ OptionsField field_va { - { 17 * 8, 10 * 8 }, + { 17 * 8, 8 * 8 }, 3, { {" OFF", 0}, @@ -177,21 +182,21 @@ private: }; NumberField field_va_level { - { 13 * 8, 12 * 8 }, + { 8 * 8, 10 * 8 }, 3, { 0, 255 }, 2, ' ' }; NumberField field_va_attack { - { 13 * 8, 14 * 8 }, + { 16 * 8, 10 * 8 }, 3, { 0, 999 }, 20, ' ' }; NumberField field_va_decay { - { 13 * 8, 16 * 8 }, + { 24 * 8, 10 * 8 }, 4, { 0, 9999 }, 100, @@ -199,27 +204,27 @@ private: }; OptionsField options_tone_key { - { 10 * 8, ( 21 * 8 ) - 2 }, + { 10 * 8, ( 15 * 8 ) - 2 }, 23, { } }; Checkbox check_rogerbeep { - { 3 * 8, 23 * 8 }, + { 3 * 8, ( 16 * 8 ) + 4 }, 10, "Roger beep", false }; Checkbox check_rxactive { - { 3 * 8, (27 * 8) + 4 }, + { 3 * 8, ( 21 * 8 ) - 4 }, 8, "RX audio listening", false }; NumberField field_volume { - { 13 * 8, 30 * 8 }, + { 13 * 8, 23 * 8 }, 2, { 0, 99 }, 1, @@ -227,7 +232,7 @@ private: }; NumberField field_squelch { - { 13 * 8, 32 * 8 }, + { 20 * 8, 25 * 8 }, 2, { 0, 99 }, 1, @@ -235,11 +240,11 @@ private: }; FrequencyField field_rxfrequency { - { 15 * 8, 34 * 8 }, + { 7 * 8, 25 * 8 }, }; NumberField field_rxlna { - { 9 * 8, 36 * 8 }, + { 9 * 8, 27 * 8 }, 2, { 0, 40 }, 8, @@ -247,7 +252,7 @@ private: }; NumberField field_rxvga { - { 16 * 8, 36 * 8 }, + { 16 * 8, 27 * 8 }, 2, { 0, 62 }, 2, @@ -255,24 +260,16 @@ private: }; NumberField field_rxamp { - { 23 * 8, 36 * 8 }, + { 23 * 8, 27 * 8 }, 1, { 0, 1 }, 1, ' ', }; - Text text_ptt_1 { - { 22 * 8, 13 * 8, 7 * 8, 8 }, - "PTT: " - }; - Text text_ptt_2 { - { 22 * 8, 15 * 8, 7 * 8, 8 }, - "RIGHT " - }; - Text text_ptt_3 { - { 22 * 8, 17 * 8, 7 * 8, 8 }, - "BUTTON" + TxButton tx_button { + { 10 * 8, 30 * 8, 10 * 8, 5 * 8 }, + "TX" }; diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index a9333eae..af20b152 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -946,6 +946,101 @@ bool Button::on_touch(const TouchEvent event) { #endif } +/* TxButton ****************************************************************/ + +TxButton::TxButton( + Rect parent_rect, + std::string text +) : Widget { parent_rect }, + text_ { text } +{ + set_focusable(true); +} + +void TxButton::set_text(const std::string value) { + text_ = value; + set_dirty(); +} + +std::string TxButton::text() const { + return text_; +} + +void TxButton::paint(Painter& painter) { + Color bg, fg; + const auto r = screen_rect(); + + if (has_focus() || highlighted()) { + bg = style().foreground; + fg = Color::black(); + } else { + bg = Color::grey(); + fg = style().foreground; + } + + const Style paint_style = { style().font, bg, fg }; + + painter.draw_rectangle({r.location(), {r.size().width(), 1}}, Color::light_grey()); + painter.draw_rectangle({r.location().x(), r.location().y() + r.size().height() - 1, r.size().width(), 1}, Color::dark_grey()); + painter.draw_rectangle({r.location().x() + r.size().width() - 1, r.location().y(), 1, r.size().height()}, Color::dark_grey()); + + painter.fill_rectangle( + { r.location().x(), r.location().y() + 1, r.size().width() - 1, r.size().height() - 2 }, + paint_style.background + ); + + const auto label_r = paint_style.font.size_of(text_); + painter.draw_string( + { r.location().x() + (r.size().width() - label_r.width()) / 2, r.location().y() + (r.size().height() - label_r.height()) / 2 }, + paint_style, + text_ + ); +} + +void TxButton::on_focus() { + if( on_highlight ) + on_highlight(*this); +} + +bool TxButton::on_key(const KeyEvent key) { + if( key == KeyEvent::Select ) { + if( on_buttonpress ) { + on_buttonpress(*this); + return true; + } + } else { + if( on_dir ) { + return on_dir(*this, key); + } + } + + return false; +} + +bool TxButton::on_touch(const TouchEvent event) { + switch(event.type) { + case TouchEvent::Type::Start: + set_highlighted(true); + set_dirty(); + if( on_select ) { + on_select(*this); + } + return true; + + + case TouchEvent::Type::End: + set_highlighted(false); + set_dirty(); + if( on_release ) { + on_release(*this); + } + return true; + + default: + return false; + } +} + /* NewButton ****************************************************************/ NewButton::NewButton( diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index 51de4277..6bca547f 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -401,6 +401,34 @@ private: std::string text_; }; +class TxButton : public Widget { +public: + std::function on_select { }; // Touch only. + std::function on_release { }; // Touch only. There's no way (or complicated) for detecting a button's release :( + std::function on_buttonpress { }; + std::function on_dir { }; + std::function on_highlight { }; + + TxButton(Rect parent_rect, std::string text); + + TxButton( + ) : TxButton { { }, { } } + { + } + + void set_text(const std::string value); + std::string text() const; + + void paint(Painter& painter) override; + + void on_focus() override; + bool on_key(const KeyEvent key) override; + bool on_touch(const TouchEvent event) override; + +private: + std::string text_; +}; + class NewButton : public Widget { public: std::function on_select { }; From 911eb36210c97b280de30346a4ec61add0f05bc1 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Mon, 24 Aug 2020 11:02:42 +0800 Subject: [PATCH 5/7] Merged TxButton and Button & minor bug fix --- firmware/application/apps/ui_mictx.cpp | 20 ++--- firmware/application/apps/ui_mictx.hpp | 7 +- firmware/common/ui_widget.cpp | 112 ++++--------------------- firmware/common/ui_widget.hpp | 39 +++------ 4 files changed, 38 insertions(+), 140 deletions(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index d70e724f..fb66ae1f 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -362,42 +362,42 @@ MicTXView::MicTXView( rx_lna = receiver_model.lna(); field_rxlna.on_change = [this](int32_t v) { rx_lna = v; - receiver_model.set_lna(v); + if(rx_enabled) + receiver_model.set_lna(v); }; field_rxlna.set_value(rx_lna); rx_vga = receiver_model.vga(); field_rxvga.on_change = [this](int32_t v) { rx_vga = v; - receiver_model.set_vga(v); + if(rx_enabled) + receiver_model.set_vga(v); }; field_rxvga.set_value(rx_vga); rx_amp = receiver_model.rf_amp(); field_rxamp.on_change = [this](int32_t v) { rx_amp = v; - receiver_model.set_rf_amp(rx_amp); + if(rx_enabled) + receiver_model.set_rf_amp(rx_amp); }; field_rxamp.set_value(rx_amp); - tx_button.on_select = [this](TxButton&) { + tx_button.on_select = [this](Button&) { if(ptt_enabled && !transmitting) { - button_touch = true; set_tx(true); } }; - tx_button.on_release = [this](TxButton&) { + tx_button.on_touch_release = [this](Button&) { if(button_touch) { button_touch = false; set_tx(false); } }; - tx_button.on_buttonpress = [this](TxButton&) { - if(ptt_enabled && !transmitting) { - set_tx(true); - } + tx_button.on_touch_press = [this](Button&) { + button_touch = true; }; transmitter_model.set_sampling_rate(sampling_rate); diff --git a/firmware/application/apps/ui_mictx.hpp b/firmware/application/apps/ui_mictx.hpp index cb735503..2b7853da 100644 --- a/firmware/application/apps/ui_mictx.hpp +++ b/firmware/application/apps/ui_mictx.hpp @@ -97,7 +97,7 @@ private: rf::Frequency tx_frequency { 0 }; rf::Frequency rx_frequency { 0 }; int32_t focused_ui { 2 }; - bool button_touch { true }; + bool button_touch { false }; Labels labels { @@ -267,9 +267,10 @@ private: ' ', }; - TxButton tx_button { + Button tx_button { { 10 * 8, 30 * 8, 10 * 8, 5 * 8 }, - "TX" + "TX", + true }; diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index af20b152..90c544fe 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -827,9 +827,11 @@ bool Checkbox::on_touch(const TouchEvent event) { Button::Button( Rect parent_rect, - std::string text + std::string text, + bool instant_exec ) : Widget { parent_rect }, - text_ { text } + text_ { text }, + instant_exec_ { instant_exec } { set_focusable(true); } @@ -899,15 +901,24 @@ bool Button::on_touch(const TouchEvent event) { case TouchEvent::Type::Start: set_highlighted(true); set_dirty(); + if( on_touch_press) { + on_touch_press(*this); + } + if( on_select && instant_exec_ ) { + on_select(*this); + } return true; case TouchEvent::Type::End: set_highlighted(false); set_dirty(); - if( on_select ) { + if( on_select && !instant_exec_ ) { on_select(*this); } + if( on_touch_release) { + on_touch_release(*this); + } return true; default: @@ -946,101 +957,6 @@ bool Button::on_touch(const TouchEvent event) { #endif } -/* TxButton ****************************************************************/ - -TxButton::TxButton( - Rect parent_rect, - std::string text -) : Widget { parent_rect }, - text_ { text } -{ - set_focusable(true); -} - -void TxButton::set_text(const std::string value) { - text_ = value; - set_dirty(); -} - -std::string TxButton::text() const { - return text_; -} - -void TxButton::paint(Painter& painter) { - Color bg, fg; - const auto r = screen_rect(); - - if (has_focus() || highlighted()) { - bg = style().foreground; - fg = Color::black(); - } else { - bg = Color::grey(); - fg = style().foreground; - } - - const Style paint_style = { style().font, bg, fg }; - - painter.draw_rectangle({r.location(), {r.size().width(), 1}}, Color::light_grey()); - painter.draw_rectangle({r.location().x(), r.location().y() + r.size().height() - 1, r.size().width(), 1}, Color::dark_grey()); - painter.draw_rectangle({r.location().x() + r.size().width() - 1, r.location().y(), 1, r.size().height()}, Color::dark_grey()); - - painter.fill_rectangle( - { r.location().x(), r.location().y() + 1, r.size().width() - 1, r.size().height() - 2 }, - paint_style.background - ); - - const auto label_r = paint_style.font.size_of(text_); - painter.draw_string( - { r.location().x() + (r.size().width() - label_r.width()) / 2, r.location().y() + (r.size().height() - label_r.height()) / 2 }, - paint_style, - text_ - ); -} - -void TxButton::on_focus() { - if( on_highlight ) - on_highlight(*this); -} - -bool TxButton::on_key(const KeyEvent key) { - if( key == KeyEvent::Select ) { - if( on_buttonpress ) { - on_buttonpress(*this); - return true; - } - } else { - if( on_dir ) { - return on_dir(*this, key); - } - } - - return false; -} - -bool TxButton::on_touch(const TouchEvent event) { - switch(event.type) { - case TouchEvent::Type::Start: - set_highlighted(true); - set_dirty(); - if( on_select ) { - on_select(*this); - } - return true; - - - case TouchEvent::Type::End: - set_highlighted(false); - set_dirty(); - if( on_release ) { - on_release(*this); - } - return true; - - default: - return false; - } -} - /* NewButton ****************************************************************/ NewButton::NewButton( diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index 6bca547f..f66da710 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -378,10 +378,18 @@ private: class Button : 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 { }; - Button(Rect parent_rect, std::string text); + Button(Rect parent_rect, std::string text, bool instant_exec); // instant_exec: Execute on_select when you touching instead of releasing + Button( + Rect parent_rect, + std::string text + ) : Button { parent_rect, text, false } + { + } Button( ) : Button { { }, { } } @@ -399,34 +407,7 @@ public: private: std::string text_; -}; - -class TxButton : public Widget { -public: - std::function on_select { }; // Touch only. - std::function on_release { }; // Touch only. There's no way (or complicated) for detecting a button's release :( - std::function on_buttonpress { }; - std::function on_dir { }; - std::function on_highlight { }; - - TxButton(Rect parent_rect, std::string text); - - TxButton( - ) : TxButton { { }, { } } - { - } - - void set_text(const std::string value); - std::string text() const; - - void paint(Painter& painter) override; - - void on_focus() override; - bool on_key(const KeyEvent key) override; - bool on_touch(const TouchEvent event) override; - -private: - std::string text_; + bool instant_exec_ { false }; }; class NewButton : public Widget { From 7d6fb56c7e0b2a94b195c4e2ad142bf54d18ea08 Mon Sep 17 00:00:00 2001 From: dqs105 Date: Mon, 24 Aug 2020 11:09:10 +0800 Subject: [PATCH 6/7] Minor bug fix - Key press & touch isolation --- firmware/application/apps/ui_mictx.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index fb66ae1f..82e66408 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -397,7 +397,9 @@ MicTXView::MicTXView( }; tx_button.on_touch_press = [this](Button&) { - button_touch = true; + if(!transmitting) { + button_touch = true; + } }; transmitter_model.set_sampling_rate(sampling_rate); From 8833b2fce5dbc7a87bd2eb858cc282dc36e9b4dd Mon Sep 17 00:00:00 2001 From: dqs105 <69909636+dqs105@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:21:30 +0800 Subject: [PATCH 7/7] Restored radio.cpp --- firmware/application/radio.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index ccd9bf7e..60981c70 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -157,14 +157,13 @@ bool set_tuning_frequency(const rf::Frequency frequency) { void set_rf_amp(const bool rf_amp) { rf_path.set_rf_amp(rf_amp); - /* + if (direction == rf::Direction::Transmit) { if (rf_amp) led_tx.on(); else led_tx.off(); } - */ } void set_lna_gain(const int_fast8_t db) {