diff --git a/radio/src/gui/128x64/model_telemetry_sensor.cpp b/radio/src/gui/128x64/model_telemetry_sensor.cpp index 1ce8173f4..7e56c7f7c 100644 --- a/radio/src/gui/128x64/model_telemetry_sensor.cpp +++ b/radio/src/gui/128x64/model_telemetry_sensor.cpp @@ -56,7 +56,7 @@ void menuModelSensor(event_t event) sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, // ID / Formula // sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : READONLY_ROW, // Receiver name ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW), // Unit - (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (uint8_t)0 : HIDDEN_ROW), // Precision + (sensor->isPrecConfigurable()? (uint8_t)0 : HIDDEN_ROW), // Precision (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0), // Param1 (sensor->unit == UNIT_GPS || sensor->unit == UNIT_DATETIME || sensor->unit == UNIT_CELLS || (sensor->type==TELEM_TYPE_CALCULATED && (sensor->formula==TELEM_FORMULA_CONSUMPTION || sensor->formula==TELEM_FORMULA_TOTALIZE)) ? HIDDEN_ROW : (uint8_t)0), // Param2 (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW, // Param3 diff --git a/radio/src/gui/212x64/model_telemetry_sensor.cpp b/radio/src/gui/212x64/model_telemetry_sensor.cpp index 5135deb92..a2f5ab32c 100644 --- a/radio/src/gui/212x64/model_telemetry_sensor.cpp +++ b/radio/src/gui/212x64/model_telemetry_sensor.cpp @@ -45,7 +45,7 @@ enum SensorFields { #define SENSOR_3RD_COLUMN (18*FW) #define SENSOR_UNIT_ROWS ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) -#define SENSOR_PREC_ROWS (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (uint8_t)0 : HIDDEN_ROW) +#define SENSOR_PREC_ROWS (sensor->isPrecConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_PARAM1_ROWS (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0) #define SENSOR_PARAM2_ROWS (sensor->unit == UNIT_GPS || sensor->unit == UNIT_DATETIME || sensor->unit == UNIT_CELLS || (sensor->type==TELEM_TYPE_CALCULATED && (sensor->formula==TELEM_FORMULA_CONSUMPTION || sensor->formula==TELEM_FORMULA_TOTALIZE)) ? HIDDEN_ROW : (uint8_t)0) #define SENSOR_PARAM3_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW diff --git a/radio/src/gui/colorlcd/model_telemetry.cpp b/radio/src/gui/colorlcd/model_telemetry.cpp index 28aec32c8..4a44cbdc1 100644 --- a/radio/src/gui/colorlcd/model_telemetry.cpp +++ b/radio/src/gui/colorlcd/model_telemetry.cpp @@ -465,7 +465,7 @@ class SensorEditWindow : public Page { } // Precision - if (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT) { + if (sensor->isPrecConfigurable()) { lv_obj_clear_flag(paramLines[P_PREC]->getLvObj(), LV_OBJ_FLAG_HIDDEN); } diff --git a/radio/src/telemetry/telemetry_sensors.cpp b/radio/src/telemetry/telemetry_sensors.cpp index a2e567ea4..783a83db2 100644 --- a/radio/src/telemetry/telemetry_sensors.cpp +++ b/radio/src/telemetry/telemetry_sensors.cpp @@ -672,19 +672,30 @@ const UnitConversionRule unitConversionTable[] = { { 0, 0, 0, 0} // termination }; +// The MAX precision used in sensors is 3..support up to Prec4. +const int16_t power10[] = { 1, 10, 100, 1000, 10000 }; + int32_t convertTelemetryValue(int32_t value, uint8_t unit, uint8_t prec, uint8_t destUnit, uint8_t destPrec) { - for (int i=prec; i Prec2.. need to * 10 the value. + // Ex: Converting from Prec0 -> Prec2.. need to * 100 the value. + if (prec < destPrec) { + value *= power10[destPrec-prec]; + temp_prec = destPrec; + } + if (unit == UNIT_CELSIUS) { if (destUnit == UNIT_FAHRENHEIT) { // T(°F) = T(°C)×1,8 + 32 - value = 32 + (value*18) / 10; + value = (32*power10[temp_prec]) + (value*18) / 10; } } else if (unit == UNIT_FAHRENHEIT) { if (destUnit == UNIT_CELSIUS) { - value = (value - 32) * 10/18; + value = (value - (32*power10[temp_prec])) * 10/18; } } else { @@ -698,8 +709,11 @@ int32_t convertTelemetryValue(int32_t value, uint8_t unit, uint8_t prec, uint8_t } } - for (int i=destPrec; i Prec1.. need to / 10 the value. + // Ex: Converting from Prec2 -> Prec0.. need to / 100 the value. + if (destPrec < prec) { + value = value / power10[prec - destPrec]; + } return value; } @@ -720,7 +734,10 @@ int32_t TelemetrySensor::getValue(int32_t value, uint8_t unit, uint8_t prec) con value = (custom.ratio * value + 122) / 255; // 122/255 (0.48) is to aproximate up (ceiling) } - value = convertTelemetryValue(value, unit, prec, this->unit, this->prec); + // Does it needs any conversion ? + if ((unit != this->unit) || (prec != this->prec)) { + value = convertTelemetryValue(value, unit, prec, this->unit, this->prec); + } if (type == TELEM_TYPE_CUSTOM) { value += custom.offset; @@ -749,7 +766,10 @@ bool TelemetrySensor::isConfigurable() const bool TelemetrySensor::isPrecConfigurable() const { - if (isConfigurable()) { + if (unit == UNIT_FAHRENHEIT) { // use Prec0 + return false; + } + else if (isConfigurable()) { return true; } else if (unit == UNIT_CELLS) {