diff --git a/lib/charts/BarChart.cpp b/lib/charts/BarChart.cpp index 305cdbd..b73f731 100644 --- a/lib/charts/BarChart.cpp +++ b/lib/charts/BarChart.cpp @@ -18,6 +18,16 @@ void BarChart::reset(uint16_t x, uint16_t y, uint16_t w, uint16_t h) Chart::reset(x, y, w, h); } +void BarChart::clear() +{ + for (int i = 0; i < width; i++) + { + ys[i] = min_y; + } + + redraw_all = true; +} + int BarChart::updatePoint(float x, float y) { if (x < min_x || x >= max_x) diff --git a/lib/charts/charts.h b/lib/charts/charts.h index d159cc0..516e5e8 100644 --- a/lib/charts/charts.h +++ b/lib/charts/charts.h @@ -81,6 +81,7 @@ struct BarChart : ProgressChart, Listener }; void reset(uint16_t x, uint16_t y, uint16_t w, uint16_t h) override; + void clear(); int updatePoint(float x, float y) override; void drawOne(int x) override; void draw() override; diff --git a/src/main.cpp b/src/main.cpp index 49190a5..034d3fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -924,6 +924,12 @@ void configureDetection() range = RANGE; configurePages(); + + if (bar != NULL) + { + bar->bar.min_x = CONF_FREQ_BEGIN; + bar->bar.max_x = CONF_FREQ_END; + } } void readConfigFile() @@ -1450,6 +1456,8 @@ void loraSendMessage(Message &m); Result checkRadio(RadioComms &c); +void display_scan_result(ScanTaskResult &dump); + /* * If m.to is LOOP, the message is directed at this module; enact the message. * If m.to is not LOOP, send the message via the respective interface. @@ -2199,3 +2207,49 @@ void reportScan() loraSendMessage(m); } + +void display_scan_result(ScanTaskResult &dump) +{ + if (bar == NULL) + return; + // assuming this module and the peer are in sync w.r.t. scan ranges + if (config.detection_strategy.equalsIgnoreCase("RSSI")) + { + for (int i = 0; i < dump.sz; i++) + bar->bar.updatePoint(dump.freqs_khz[i] / 1000, dump.rssis[i]); + + bar->draw(); + display.display(); + + return; + } + + if (config.detection_strategy.equalsIgnoreCase("RSSI_MAX")) + { + float step = (bar->bar.max_x - bar->bar.min_x) / bar->bar.width; + + bar->bar.clear(); + + for (int i = 0; i < config.scan_ranges_sz; i++) + { + int j; + for (j = 0; j < dump.sz; j++) + { + if (config.scan_ranges[i].start_khz <= dump.freqs_khz[j] && + config.scan_ranges[i].end_khz >= dump.freqs_khz[j]) + break; + } + + int16_t rssi = j < dump.sz ? dump.rssis[j] : bar->bar.min_y; + + for (float f = config.scan_ranges[i].start_khz / 1000; + f <= config.scan_ranges[i].end_khz / 1000; f += step) + bar->bar.updatePoint(f, rssi); + } + + bar->draw(); + display.display(); + + return; + } +}