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:
gullradriel 2023-11-06 11:12:36 +01:00 committed by GitHub
parent 645f02e2f3
commit 2b7962fa7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 20 deletions

View file

@ -30,6 +30,10 @@
#define max(a, b) ((a) > (b) ? (a) : (b))
#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 {
RSSI::RSSI(
@ -209,17 +213,48 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
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) {
const auto r = screen_rect();
RSSIGraph_entry& prev_entry = graph_list[0];
int xpos = 0, prev_xpos = r.width();
if (graph_list.size() == 0)
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++) {
xpos = (r.width() * (graph_list.size() - n)) / graph_list.size();
int size = abs(xpos - prev_xpos);
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
const Rect r0{r.right() - prev_xpos, r.top(), size, r.height()};
painter.fill_rectangle(
@ -293,6 +328,10 @@ void RSSIGraph::paint(Painter& painter) {
prev_entry = entry;
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) {