mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Level RSSIGraph tuning (#1556)
* Added whole graph RSSI min/avg/max/delta to RSSIGraph * fix for min=0 values when modulation is changed * literal number as a #define flag
This commit is contained in:
parent
645f02e2f3
commit
2b7962fa7c
@ -142,31 +142,24 @@ LevelView::LevelView(NavigationView& nav)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
|
void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
|
||||||
static int last_max_db = -1000;
|
static int16_t last_max_db = -1000;
|
||||||
static int last_min_rssi = -1000;
|
static int16_t last_min_rssi = -1000;
|
||||||
static int last_avg_rssi = -1000;
|
static int16_t last_avg_rssi = -1000;
|
||||||
static int last_max_rssi = -1000;
|
static int16_t last_max_rssi = -1000;
|
||||||
|
|
||||||
rssi_graph.add_values(rssi.get_min(), rssi.get_avg(), rssi.get_max(), statistics.max_db);
|
rssi_graph.add_values(rssi.get_min(), rssi.get_avg(), rssi.get_max(), statistics.max_db);
|
||||||
|
|
||||||
bool refresh_db = false;
|
// refresh db
|
||||||
bool refresh_rssi = false;
|
|
||||||
|
|
||||||
if (last_max_db != statistics.max_db) {
|
if (last_max_db != statistics.max_db) {
|
||||||
refresh_db = true;
|
|
||||||
}
|
|
||||||
if (last_min_rssi != rssi.get_min() || last_avg_rssi != rssi.get_avg() || last_max_rssi != rssi.get_max()) {
|
|
||||||
refresh_rssi = true;
|
|
||||||
}
|
|
||||||
if (refresh_db) {
|
|
||||||
last_max_db = statistics.max_db;
|
last_max_db = statistics.max_db;
|
||||||
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
|
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
|
||||||
}
|
}
|
||||||
if (refresh_rssi) {
|
// refresh rssi
|
||||||
last_min_rssi = rssi.get_min();
|
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_avg_rssi = rssi.get_avg();
|
last_min_rssi = rssi_graph.get_graph_min();
|
||||||
last_max_rssi = rssi.get_max();
|
last_avg_rssi = rssi_graph.get_graph_avg();
|
||||||
freq_stats_rssi.set("RSSI: " + to_string_dec_int(rssi.get_min()) + "/" + to_string_dec_int(rssi.get_avg()) + "/" + to_string_dec_int(rssi.get_max()) + ",dt: " + to_string_dec_int(rssi.get_delta()));
|
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()));
|
||||||
}
|
}
|
||||||
} /* on_statistic_updates */
|
} /* on_statistic_updates */
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define abs(x) ((x) > 0 ? (x) : -(x))
|
#define abs(x) ((x) > 0 ? (x) : -(x))
|
||||||
|
|
||||||
|
// flag value for graph min
|
||||||
|
// If it does not change, then all graph min values are is zero
|
||||||
|
#define GRAPH_MIN_ALL_ZERO_FLAG 666
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
RSSI::RSSI(
|
RSSI::RSSI(
|
||||||
@ -209,17 +213,48 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
|
|||||||
set_dirty();
|
set_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t RSSIGraph::get_graph_min() {
|
||||||
|
return graph_min_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t RSSIGraph::get_graph_avg() {
|
||||||
|
return graph_avg_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t RSSIGraph::get_graph_max() {
|
||||||
|
return graph_max_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t RSSIGraph::get_graph_delta() {
|
||||||
|
return graph_max_ - graph_min_;
|
||||||
|
}
|
||||||
|
|
||||||
void RSSIGraph::paint(Painter& painter) {
|
void RSSIGraph::paint(Painter& painter) {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
|
|
||||||
RSSIGraph_entry& prev_entry = graph_list[0];
|
if (graph_list.size() == 0)
|
||||||
int xpos = 0, prev_xpos = r.width();
|
return;
|
||||||
|
|
||||||
|
int xpos = 0, prev_xpos = r.width();
|
||||||
|
RSSIGraph_entry& prev_entry = graph_list[0];
|
||||||
|
|
||||||
|
graph_min_ = GRAPH_MIN_ALL_ZERO_FLAG; // if it stays at that value the whole graphlist min are zero
|
||||||
|
graph_max_ = 0;
|
||||||
|
int avg_sum = 0;
|
||||||
for (int n = 1; (unsigned)n <= graph_list.size(); n++) {
|
for (int n = 1; (unsigned)n <= graph_list.size(); n++) {
|
||||||
xpos = (r.width() * (graph_list.size() - n)) / graph_list.size();
|
xpos = (r.width() * (graph_list.size() - n)) / graph_list.size();
|
||||||
int size = abs(xpos - prev_xpos);
|
int size = abs(xpos - prev_xpos);
|
||||||
RSSIGraph_entry& entry = graph_list[n - 1];
|
RSSIGraph_entry& entry = graph_list[n - 1];
|
||||||
|
|
||||||
|
// stats
|
||||||
|
if (entry.rssi_min != 0 && entry.rssi_min < graph_min_) {
|
||||||
|
graph_min_ = entry.rssi_min;
|
||||||
|
}
|
||||||
|
if (entry.rssi_max > graph_max_) {
|
||||||
|
graph_max_ = entry.rssi_max;
|
||||||
|
}
|
||||||
|
avg_sum += entry.rssi_avg;
|
||||||
|
|
||||||
// black
|
// black
|
||||||
const Rect r0{r.right() - prev_xpos, r.top(), size, r.height()};
|
const Rect r0{r.right() - prev_xpos, r.top(), size, r.height()};
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
@ -293,6 +328,10 @@ void RSSIGraph::paint(Painter& painter) {
|
|||||||
prev_entry = entry;
|
prev_entry = entry;
|
||||||
prev_xpos = xpos;
|
prev_xpos = xpos;
|
||||||
}
|
}
|
||||||
|
graph_avg_ = (avg_sum / graph_list.size());
|
||||||
|
// hack to only set to 0 if all graphlist min values are 0
|
||||||
|
if (graph_min_ == GRAPH_MIN_ALL_ZERO_FLAG)
|
||||||
|
graph_min_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void RSSIGraph::paintOld(Painter& painter) {
|
/*void RSSIGraph::paintOld(Painter& painter) {
|
||||||
|
@ -49,6 +49,7 @@ class RSSI : public Widget {
|
|||||||
: RSSI{{}, {}} {
|
: RSSI{{}, {}} {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last used/received min/avg/max/delta
|
||||||
int16_t get_min();
|
int16_t get_min();
|
||||||
int16_t get_avg();
|
int16_t get_avg();
|
||||||
int16_t get_max();
|
int16_t get_max();
|
||||||
@ -113,8 +114,16 @@ class RSSIGraph : public Widget {
|
|||||||
|
|
||||||
void on_hide() override;
|
void on_hide() override;
|
||||||
void on_show() 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();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int16_t graph_min_ = 0;
|
||||||
|
int16_t graph_avg_ = 0;
|
||||||
|
int16_t graph_max_ = 0;
|
||||||
uint16_t nb_columns_before_hide = 16;
|
uint16_t nb_columns_before_hide = 16;
|
||||||
uint16_t nb_columns = 16;
|
uint16_t nb_columns = 16;
|
||||||
RSSIGraphList graph_list{};
|
RSSIGraphList graph_list{};
|
||||||
|
Loading…
Reference in New Issue
Block a user