Fix RSSI meter scaling, clean up limits code.

This commit is contained in:
Jared Boone 2016-01-27 11:48:22 -08:00
parent 87a6f931c9
commit c761d3aaa8

View File

@ -41,18 +41,19 @@ void RSSI::on_hide() {
void RSSI::paint(Painter& painter) { void RSSI::paint(Painter& painter) {
const auto r = screen_rect(); const auto r = screen_rect();
/*
constexpr int32_t rssi_min = 0.# * 256 / 3.3; constexpr int32_t rssi_sample_range = 256;
constexpr int32_t rssi_max = 2.5 * 256 / 3.3; constexpr float rssi_voltage_min = 0.4;
// (23 - 194) / 2 constexpr float rssi_voltage_max = 2.2;
*/ constexpr float adc_voltage_max = 3.3;
/* TODO: Clip maximum */ constexpr int32_t raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int32_t raw_min = 23; 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_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_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 { const Rect r0 {
static_cast<ui::Coord>(r.left() + x_0), r.top(), static_cast<ui::Coord>(r.left() + x_0), r.top(),