mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-14 04:04:34 +00:00
Fix RSSI meter scaling, clean up limits code.
This commit is contained in:
parent
87a6f931c9
commit
c761d3aaa8
@ -41,18 +41,19 @@ void RSSI::on_hide() {
|
||||
|
||||
void RSSI::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
/*
|
||||
constexpr int32_t rssi_min = 0.# * 256 / 3.3;
|
||||
constexpr int32_t rssi_max = 2.5 * 256 / 3.3;
|
||||
// (23 - 194) / 2
|
||||
*/
|
||||
/* TODO: Clip maximum */
|
||||
constexpr int32_t raw_min = 23;
|
||||
|
||||
constexpr int32_t rssi_sample_range = 256;
|
||||
constexpr float rssi_voltage_min = 0.4;
|
||||
constexpr float rssi_voltage_max = 2.2;
|
||||
constexpr float adc_voltage_max = 3.3;
|
||||
constexpr int32_t raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
|
||||
constexpr int32_t raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
|
||||
constexpr int32_t raw_delta = raw_max - raw_min;
|
||||
const int32_t x_0 = 0;
|
||||
const int32_t x_min = std::max(x_0, (min_ - raw_min) / 2);
|
||||
const int32_t x_avg = std::max(x_min, (avg_ - raw_min) / 2);
|
||||
const int32_t x_max = std::max(x_avg + 1, (max_ - raw_min) / 2);
|
||||
const int32_t x_lim = r.width();
|
||||
const int32_t x_min = std::max(x_0, (min_ - raw_min) * x_lim / raw_delta);
|
||||
const int32_t x_avg = std::max(x_min, (avg_ - raw_min) * x_lim / raw_delta);
|
||||
const int32_t x_max = std::max(x_avg + 1, (max_ - raw_min) * x_lim / raw_delta);
|
||||
|
||||
const Rect r0 {
|
||||
static_cast<ui::Coord>(r.left() + x_0), r.top(),
|
||||
|
Loading…
Reference in New Issue
Block a user