More improvements to the rssi tone. Added saving of the tuned frequency

to the radio model persistent store.
This commit is contained in:
teixeluis 2021-06-13 23:35:33 +01:00
parent 43e123bafe
commit a80d91fb1e
4 changed files with 31 additions and 11 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -77,8 +77,21 @@ void SondeProcessor::on_message(const Message* const msg) {
switch(msg->id) {
case Message::ID::RequestSignal:
if ((*reinterpret_cast<const RequestSignalMessage*>(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);
}

View File

@ -97,6 +97,13 @@
#include <cstddef>
#include <bitset>
#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 };