From a80d91fb1eb72d829eb781a0077a82f0bf52b632 Mon Sep 17 00:00:00 2001 From: teixeluis Date: Sun, 13 Jun 2021 23:35:33 +0100 Subject: [PATCH] More improvements to the rssi tone. Added saving of the tuned frequency to the radio model persistent store. --- firmware/application/apps/ui_sonde.cpp | 7 ++++++- firmware/application/apps/ui_sonde.hpp | 8 -------- firmware/baseband/proc_sonde.cpp | 18 ++++++++++++++++-- firmware/baseband/proc_sonde.hpp | 9 +++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/firmware/application/apps/ui_sonde.cpp b/firmware/application/apps/ui_sonde.cpp index 28796cd76..419ad579d 100644 --- a/firmware/application/apps/ui_sonde.cpp +++ b/firmware/application/apps/ui_sonde.cpp @@ -66,6 +66,9 @@ SondeView::SondeView(NavigationView& nav) { &button_see_map }); + // start from the frequency currently stored in the receiver_model: + target_frequency_ = receiver_model.tuning_frequency(); + field_frequency.set_value(target_frequency_); field_frequency.set_step(500); //euquiq: was 10000, but we are using this for fine-tunning field_frequency.on_change = [this](rf::Frequency f) { @@ -206,7 +209,9 @@ void SondeView::on_headphone_volume_changed(int32_t v) { void SondeView::set_target_frequency(const uint32_t new_value) { target_frequency_ = new_value; - radio::set_tuning_frequency(tuning_frequency()); + //radio::set_tuning_frequency(tuning_frequency()); + // we better remember the tuned frequency, by using this function instead: + receiver_model.set_tuning_frequency(tuning_frequency()); } uint32_t SondeView::tuning_frequency() const { diff --git a/firmware/application/apps/ui_sonde.hpp b/firmware/application/apps/ui_sonde.hpp index 73591eb3c..afc2bbecf 100644 --- a/firmware/application/apps/ui_sonde.hpp +++ b/firmware/application/apps/ui_sonde.hpp @@ -55,14 +55,6 @@ class SondeView : public View { public: static constexpr uint32_t sampling_rate = 2457600; static constexpr uint32_t baseband_bandwidth = 1750000; - static constexpr int rssi_sample_range = 256; - static constexpr float rssi_voltage_min = 0.4; - static constexpr float rssi_voltage_max = 2.2; - static constexpr float adc_voltage_max = 3.3; - - static constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max; - static constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max; - static constexpr int raw_delta = raw_max - raw_min; SondeView(NavigationView& nav); ~SondeView(); diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index b7397a314..d956372f0 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -77,8 +77,21 @@ void SondeProcessor::on_message(const Message* const msg) { switch(msg->id) { case Message::ID::RequestSignal: if ((*reinterpret_cast(msg)).signal == RequestSignalMessage::Signal::BeepRequest) { + float rssi_ratio = (float) last_rssi / (float) RSSI_CEILING; + int beep_duration = 0; + + if(rssi_ratio <= PROPORTIONAL_BEEP_THRES) { + beep_duration = BEEP_MIN_DURATION; + } + else if(rssi_ratio < 1) { + beep_duration = (int) rssi_ratio * BEEP_DURATION_RANGE + BEEP_MIN_DURATION; + } + else { + beep_duration = BEEP_DURATION_RANGE + BEEP_MIN_DURATION; + } + play_beep(); - chThdSleepMilliseconds(150); + chThdSleepMilliseconds(beep_duration); stop_beep(); } break; @@ -122,7 +135,8 @@ void SondeProcessor::generate_silence() { void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) { pitch_rssi_enabled = message.enabled; - uint32_t tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); + uint32_t tone_delta = (int) ((float) message.rssi * (float) RSSI_PITCH_WEIGHT + (float) 1000) * ((float) (1ULL << 32) / (float) 24000); + last_rssi = message.rssi; tone_gen.configure(tone_delta, 1.0, ToneGen::tone_type::square); } diff --git a/firmware/baseband/proc_sonde.hpp b/firmware/baseband/proc_sonde.hpp index 108c40661..fcf4d20b3 100644 --- a/firmware/baseband/proc_sonde.hpp +++ b/firmware/baseband/proc_sonde.hpp @@ -97,6 +97,13 @@ #include #include + +#define BEEP_MIN_DURATION 80 +#define BEEP_DURATION_RANGE 150 +#define RSSI_CEILING 1000 +#define PROPORTIONAL_BEEP_THRES 0.8 +#define RSSI_PITCH_WEIGHT 0.7 + class SondeProcessor : public BasebandProcessor { public: SondeProcessor(); @@ -120,6 +127,8 @@ private: bool silence_play { false }; bool pitch_rssi_enabled { false }; + uint32_t last_rssi { 0 }; + ToneGen tone_gen { }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };