Praline rssi (#3127)

This commit is contained in:
Pezsma
2026-04-07 19:42:21 +02:00
committed by GitHub
parent d5f94398ce
commit 5deeaed5f0
7 changed files with 69 additions and 252 deletions
+27 -22
View File
@@ -46,17 +46,17 @@ RSSI::RSSI(
void RSSI::paint(Painter& painter) {
const auto r = screen_rect();
/* RSSI scaling based on transceiver output voltage range.
* MAX2837 (HackRF One): 0.4V to 2.2V
* MAX2831 (HackRF Pro): 0.5V to 2.0V (similar enough to use same scaling)
*/
constexpr int rssi_sample_range = 256;
// constexpr float rssi_voltage_min = 0.4;
constexpr float rssi_voltage_min = 0.4;
#ifdef PRALINE
constexpr float rssi_voltage_max = 2.4;
#else
constexpr float rssi_voltage_max = 2.2;
// constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int raw_min = 0;
#endif
constexpr float adc_voltage_max = 3.3;
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
constexpr int raw_min = (rssi_sample_range * rssi_voltage_min) / adc_voltage_max;
constexpr int raw_max = (int)(((rssi_sample_range * rssi_voltage_max) / adc_voltage_max) + 0.5f);
constexpr int raw_delta = raw_max - raw_min;
if (!vertical_rssi_enabled) {
@@ -117,7 +117,6 @@ void RSSI::paint(Painter& painter) {
const Rect r_db{r.left() + x_db, r.top(), 1, r.height()};
if (db_) painter.fill_rectangle(r_db, Color::green());
} else {
// vertical bottom to top level meters
const range_t<int> y_avg_range{0, r.height() - 1};
@@ -226,7 +225,6 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
min_ = statistics.min;
avg_ = statistics.accumulator / statistics.count;
max_ = statistics.max;
if (peak_enabled) {
peak_duration_ = peak_duration_ + 100;
if (max_ > peak_) {
@@ -434,25 +432,38 @@ void RSSIGraph::paint(Painter& painter) {
void RSSIGraph::add_values(int16_t rssi_min, int16_t rssi_avg, int16_t rssi_max, int16_t db) {
const auto r = screen_rect();
/* RSSI scaling based on transceiver output voltage range.
* MAX2837 (HackRF One): 0.4V to 2.2V
* MAX2831 (HackRF Pro): 0.4V to 2.4V
*/
constexpr int rssi_sample_range = 256;
// constexpr float rssi_voltage_min = 0.4;
constexpr float rssi_voltage_min = 0.4;
#ifdef PRALINE
constexpr float rssi_voltage_max = 2.4;
#else
constexpr float rssi_voltage_max = 2.2;
// constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int raw_min = 0;
#endif
constexpr float adc_voltage_max = 3.3;
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
constexpr int raw_min = (rssi_sample_range * rssi_voltage_min) / adc_voltage_max;
constexpr int raw_max = (int)(((rssi_sample_range * rssi_voltage_max) / adc_voltage_max) + 0.5f);
constexpr int raw_delta = raw_max - raw_min;
// vertical bottom to top level meters
// y_avg
const range_t<int> y_avg_range{0, r.height() - 1};
const int16_t y_avg = y_avg_range.clip((rssi_avg - raw_min) * r.height() / raw_delta);
// y_min
const range_t<int> y_min_range{0, y_avg};
const int16_t y_min = y_min_range.clip((rssi_min - raw_min) * r.height() / raw_delta);
const range_t<int> y_max_range{y_avg + 1, r.height() - 1};
// y_max
const range_t<int> y_max_range{y_avg, r.height() - 1};
const int16_t y_max = y_max_range.clip((rssi_max - raw_min) * r.height() / raw_delta);
// range
const range_t<int> db_range{-80, 10};
int16_t db_ = db_range.clip(db);
db_ = db_ - 10;
db_ -= 10;
db_ = db_ * r.height() / 90;
db_ = r.height() + db_;
@@ -529,12 +540,6 @@ bool RSSI::on_touch(const TouchEvent event) {
}
void RSSI::set_db(int16_t db) {
#ifdef PRALINE
/* Add a +30dB global boost to align 40MHz/1.2V VCM data
with the UI's existing display scale. */
db_ = db + 30;
#else
db_ = db;
#endif
}
} /* namespace ui */