From ba0a6c79d37582e599d29d26e3aa7f913eaf0314 Mon Sep 17 00:00:00 2001 From: Frankie Arzu <32604366+frankiearzu@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:42:00 -0500 Subject: [PATCH 1/2] #4021 Fix proper scaling using "ratio" 1. Remove code that seems that was not needed and creating problems --- radio/src/telemetry/telemetry_sensors.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/radio/src/telemetry/telemetry_sensors.cpp b/radio/src/telemetry/telemetry_sensors.cpp index 9ffd4667290..a2e567ea4b3 100644 --- a/radio/src/telemetry/telemetry_sensors.cpp +++ b/radio/src/telemetry/telemetry_sensors.cpp @@ -707,6 +707,7 @@ int32_t convertTelemetryValue(int32_t value, uint8_t unit, uint8_t prec, uint8_t int32_t TelemetrySensor::getValue(int32_t value, uint8_t unit, uint8_t prec) const { if (type == TELEM_TYPE_CUSTOM && custom.ratio) { + /* farzu: Not needed, scaling work properly for the 3 types of prec without it if (this->prec == 2) { value *= 10; prec = 2; @@ -714,7 +715,9 @@ int32_t TelemetrySensor::getValue(int32_t value, uint8_t unit, uint8_t prec) con else { prec = 1; } - value = (custom.ratio * value + 122) / 255; + */ + + value = (custom.ratio * value + 122) / 255; // 122/255 (0.48) is to aproximate up (ceiling) } value = convertTelemetryValue(value, unit, prec, this->unit, this->prec); From 94051db0d1ec1565afb9deb906981143052a5634 Mon Sep 17 00:00:00 2001 From: Frankie Arzu <32604366+frankiearzu@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:58:12 -0600 Subject: [PATCH 2/2] Fix Tel Sensor UI to display "Ratio" with 1 Decimal This makes it consistent with B&W UI and Companion.. Also is backward compatible, internally the value is stored as integer, only converted to PREC1 for display. --- radio/src/gui/colorlcd/model_telemetry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/model_telemetry.cpp b/radio/src/gui/colorlcd/model_telemetry.cpp index a415202ccb2..28aec32c8c3 100644 --- a/radio/src/gui/colorlcd/model_telemetry.cpp +++ b/radio/src/gui/colorlcd/model_telemetry.cpp @@ -671,7 +671,8 @@ class SensorEditWindow : public Page { paramLines[P_RATIO] = form->newLine(&grid); new StaticText(paramLines[P_RATIO], rect_t{}, STR_RATIO, 0, COLOR_THEME_PRIMARY1); - auto edit = new NumberEdit(paramLines[P_RATIO], rect_t{}, 0, 30000, GET_SET_DEFAULT(sensor->custom.ratio)); + auto edit = new NumberEdit(paramLines[P_RATIO], rect_t{}, 0, 30000, GET_SET_DEFAULT(sensor->custom.ratio), + 0, PREC1); edit->setZeroText("-"); paramLines[P_CELLINDEX] = form->newLine(&grid);