Skip to content

Commit

Permalink
More improvements to the rssi tone. Added saving of the tuned frequency
Browse files Browse the repository at this point in the history
to the radio model persistent store.
  • Loading branch information
teixeluis committed Jun 13, 2021
1 parent 43e123b commit a80d91f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
7 changes: 6 additions & 1 deletion firmware/application/apps/ui_sonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions firmware/application/apps/ui_sonde.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions firmware/baseband/proc_sonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions firmware/baseband/proc_sonde.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -120,6 +127,8 @@ class SondeProcessor : public BasebandProcessor {
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 };
Expand Down

0 comments on commit a80d91f

Please sign in to comment.