Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly scale PREC2 sensor values using "ratio" #4083

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion radio/src/gui/colorlcd/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion radio/src/telemetry/telemetry_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,17 @@ 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;
}
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);
Expand Down