Skip to content

Commit

Permalink
Rxsat in Level app (#1959)
Browse files Browse the repository at this point in the history
* added Rx Saturation

* testing reducing values to uint8_t

* clang format

* refactorisation

* cleanings

* cleanings

* set back request_m4_performance_counter to zero on app exit

---------

Co-authored-by: GullCode <gullradriel@hotmail.com>
  • Loading branch information
gullradriel and GullCode committed Mar 9, 2024
1 parent 1fbfdbc commit b5e6638
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 36 deletions.
24 changes: 19 additions & 5 deletions firmware/application/apps/ui_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void LevelView::focus() {
}

LevelView::~LevelView() {
// reset performance counters request to default
shared_memory.request_m4_performance_counter = 0;
receiver_model.disable();
baseband::shutdown();
}
Expand All @@ -58,12 +60,16 @@ LevelView::LevelView(NavigationView& nav)
&text_ctcss,
&freq_stats_rssi,
&freq_stats_db,
&freq_stats_rx,
&audio_mode,
&peak_mode,
&rssi,
&rssi_graph});

// activate vertical bar mode
rssi.set_vertical_rssi(true);
// activate counters for RxSat
shared_memory.request_m4_performance_counter = 2;

change_mode(NFM_MODULATION); // Start on AM
field_mode.set_by_value(NFM_MODULATION); // Reflect the mode into the manual selector
Expand Down Expand Up @@ -139,13 +145,15 @@ LevelView::LevelView(NavigationView& nav)
freqman_set_step_option_short(step_mode);
freq_stats_rssi.set_style(&Styles::white);
freq_stats_db.set_style(&Styles::white);
freq_stats_rx.set_style(&Styles::white);
}

void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
static int16_t last_max_db = -1000;
static int16_t last_min_rssi = -1000;
static int16_t last_avg_rssi = -1000;
static int16_t last_max_rssi = -1000;
static int16_t last_max_db = 0;
static uint8_t last_min_rssi = 0;
static uint8_t last_avg_rssi = 0;
static uint8_t last_max_rssi = 0;
static uint8_t last_rx_sat = 0;

rssi_graph.add_values(rssi.get_min(), rssi.get_avg(), rssi.get_max(), statistics.max_db);

Expand All @@ -154,12 +162,18 @@ void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
last_max_db = statistics.max_db;
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
}
// refresh sat
uint8_t rx_sat = ((uint32_t)shared_memory.m4_performance_counter) * 100 / 127;
if (last_rx_sat != rx_sat) {
last_rx_sat = rx_sat;
freq_stats_rx.set("RxSat: " + to_string_dec_uint(rx_sat) + "%");
}
// refresh rssi
if (last_min_rssi != rssi_graph.get_graph_min() || last_avg_rssi != rssi_graph.get_graph_avg() || last_max_rssi != rssi_graph.get_graph_max()) {
last_min_rssi = rssi_graph.get_graph_min();
last_avg_rssi = rssi_graph.get_graph_avg();
last_max_rssi = rssi_graph.get_graph_max();
freq_stats_rssi.set("RSSI: " + to_string_dec_int(last_min_rssi) + "/" + to_string_dec_int(last_avg_rssi) + "/" + to_string_dec_int(last_max_rssi) + ",dt: " + to_string_dec_int(rssi_graph.get_graph_delta()));
freq_stats_rssi.set("RSSI: " + to_string_dec_uint(last_min_rssi) + "/" + to_string_dec_uint(last_avg_rssi) + "/" + to_string_dec_uint(last_max_rssi) + ", dt: " + to_string_dec_uint(rssi_graph.get_graph_delta()));
}
} /* on_statistic_updates */

Expand Down
10 changes: 7 additions & 3 deletions firmware/application/apps/ui_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class LevelView : public View {
void on_statistics_update(const ChannelStatistics& statistics);
void set_display_freq(int64_t freq);

// TODO: needed?
int32_t db{0};
rf::Frequency freq_ = {0};

Labels labels{
Expand Down Expand Up @@ -138,6 +136,7 @@ class LevelView : public View {
{"peak:5s", 5000},
{"peak:10s", 10000},
}};

OptionsField rssi_resolution{
{44 + 20 * 8, 4 * 16 + 4},
4,
Expand All @@ -149,9 +148,14 @@ class LevelView : public View {
{"240x", 240},
}};

// RxSat: XX%
Text freq_stats_rx{
{0 * 8, 5 * 16 + 4, 10 * 8, 14},
};

RSSIGraph rssi_graph{
// 240x320 =>
{0, 5 * 16 + 4, 240 - 5 * 8, 320 - (5 * 16 + 4)},
{0, 6 * 16 + 4, 240 - 5 * 8, 320 - (6 * 16 + 4)},
};

RSSI rssi{
Expand Down
16 changes: 8 additions & 8 deletions firmware/application/ui/ui_rssi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@ void RSSI::paint(Painter& painter) {
}
}

int16_t RSSI::get_min() {
uint8_t RSSI::get_min() {
return min_;
}

int16_t RSSI::get_avg() {
uint8_t RSSI::get_avg() {
return avg_;
}

int16_t RSSI::get_max() {
uint8_t RSSI::get_max() {
return max_;
}

int16_t RSSI::get_delta() {
uint8_t RSSI::get_delta() {
return max_ - min_;
}

Expand Down Expand Up @@ -213,19 +213,19 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
set_dirty();
}

int16_t RSSIGraph::get_graph_min() {
uint8_t RSSIGraph::get_graph_min() {
return graph_min_;
}

int16_t RSSIGraph::get_graph_avg() {
uint8_t RSSIGraph::get_graph_avg() {
return graph_avg_;
}

int16_t RSSIGraph::get_graph_max() {
uint8_t RSSIGraph::get_graph_max() {
return graph_max_;
}

int16_t RSSIGraph::get_graph_delta() {
uint8_t RSSIGraph::get_graph_delta() {
return graph_max_ - graph_min_;
}

Expand Down
24 changes: 12 additions & 12 deletions firmware/application/ui/ui_rssi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class RSSI : public Widget {
}

// get last used/received min/avg/max/delta
int16_t get_min();
int16_t get_avg();
int16_t get_max();
int16_t get_delta();
uint8_t get_min();
uint8_t get_avg();
uint8_t get_max();
uint8_t get_delta();
void set_vertical_rssi(bool enabled);
void set_peak(bool enabled, size_t duration);

Expand All @@ -63,10 +63,10 @@ class RSSI : public Widget {
bool on_touch(const TouchEvent event) override;

private:
int16_t min_ = 0;
int16_t avg_ = 0;
int16_t max_ = 0;
int16_t peak_ = 0;
int8_t min_ = 0;
int8_t avg_ = 0;
int8_t max_ = 0;
int8_t peak_ = 0;
size_t peak_duration_ = 0;
bool instant_exec_{false};

Expand Down Expand Up @@ -115,10 +115,10 @@ class RSSIGraph : public Widget {
void on_hide() override;
void on_show() override;
// get whole graph_list min/avg/max/delta
int16_t get_graph_min();
int16_t get_graph_avg();
int16_t get_graph_max();
int16_t get_graph_delta();
uint8_t get_graph_min();
uint8_t get_graph_avg();
uint8_t get_graph_max();
uint8_t get_graph_delta();

private:
int16_t graph_min_ = 0;
Expand Down
3 changes: 2 additions & 1 deletion firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ NavigationView* SystemView::get_navigation_view() {
}

void SystemView::toggle_overlay() {
static uint8_t last_perf_counter_status = shared_memory.request_m4_performance_counter;
switch (++overlay_active) {
case 1:
this->add_child(&this->overlay);
Expand All @@ -879,7 +880,7 @@ void SystemView::toggle_overlay() {
case 3:
this->remove_child(&this->overlay2);
this->set_dirty();
shared_memory.request_m4_performance_counter = 0;
shared_memory.request_m4_performance_counter = last_perf_counter_status;
overlay_active = 0;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions firmware/baseband/rssi_stats_collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#ifndef __RSSI_STATS_COLLECTOR_H__
#define __RSSI_STATS_COLLECTOR_H__

#include "rssi.hpp"
#include "message.hpp"

#include <cstdint>
#include <cstddef>

#include "rssi.hpp"
#include "message.hpp"

class RSSIStatisticsCollector {
public:
template <typename Callback>
Expand Down
8 changes: 4 additions & 4 deletions firmware/common/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ class Message {
};

struct RSSIStatistics {
uint32_t accumulator{0};
uint32_t min{0};
uint32_t max{0};
uint32_t count{0};
uint16_t accumulator{0};
uint8_t min{0};
uint8_t max{0};
uint16_t count{0};
};

class RSSIStatisticsMessage : public Message {
Expand Down

0 comments on commit b5e6638

Please sign in to comment.