mirror of
https://github.com/opentx/opentx.git
synced 2025-07-13 11:29:51 +03:00
gvars in telemetry: Interpret gvars as decimal
The value of GVars is now interpreted as a decimal constant, with the decimal place determined by the precision of the calculated telemetry source. Examples: Precision 0.0 (aka precision=1) GVar has value 20 => calculation uses value 2.0 Precision 0.00 (aka 2) GVar has value 3 => calculation uses value 0.03
This commit is contained in:
parent
bfb670376a
commit
0da49fd2cc
1 changed files with 9 additions and 6 deletions
|
@ -409,14 +409,18 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
|||
int8_t source = sensor.calc.sources[i];
|
||||
#if defined(GVARS)
|
||||
if (GV_IS_GV_VALUE(source, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS)) {
|
||||
int32_t gvarvalue = GET_GVAR(source, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS, mixerCurrentFlightMode);
|
||||
int32_t gvarvalue;
|
||||
{
|
||||
int8_t min = -MAX_TELEMETRY_SENSORS;
|
||||
gvarvalue = getGVarValue(GV_INDEX_CALCULATION(source, MAX_TELEMETRY_SENSORS), mixerCurrentFlightMode);
|
||||
}
|
||||
|
||||
if (sensor.formula == TELEM_FORMULA_MULTIPLY) {
|
||||
if (source>0) {
|
||||
//divide, actually
|
||||
int32_t divisor = convertTelemetryValue(-gvarvalue, sensor.unit, 0, sensor.unit, 0);
|
||||
if (divisor!=0) {
|
||||
value /= divisor;
|
||||
value = convertTelemetryValue(value, sensor.unit, mulprec, sensor.unit, mulprec+sensor.prec)/divisor;
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
|
@ -426,13 +430,12 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
|||
}
|
||||
}
|
||||
else {
|
||||
int32_t sensorValue = convertTelemetryValue(gvarvalue, sensor.unit, 1, sensor.unit, sensor.prec);
|
||||
if (sensor.formula == TELEM_FORMULA_MIN)
|
||||
value = (count==1 ? sensorValue : min<int32_t>(value, sensorValue));
|
||||
value = (count==1 ? gvarvalue : min<int32_t>(value, gvarvalue));
|
||||
else if (sensor.formula == TELEM_FORMULA_MAX)
|
||||
value = (count==1 ? sensorValue : max<int32_t>(value, sensorValue));
|
||||
value = (count==1 ? gvarvalue : max<int32_t>(value, gvarvalue));
|
||||
else
|
||||
value += sensorValue;
|
||||
value += gvarvalue;
|
||||
}
|
||||
count += 1;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue