1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00
* negative altitude on top bar was displayed wrong (same bug affected vertical speed)
* add ability to select an altitude sensor with ft unit for top bar
* display actual sensor unit for top bar altitude
This commit is contained in:
Damjan Adamic 2015-11-10 17:24:49 +01:00
parent a1d44d4d9f
commit f854442c79
4 changed files with 12 additions and 12 deletions

View file

@ -164,12 +164,8 @@ enum SensorFields {
bool isSensorUnit(int sensor, uint8_t unit) bool isSensorUnit(int sensor, uint8_t unit)
{ {
if (sensor == 0) if (sensor <= 0 || sensor > MAX_SENSORS ) return true;
return true; return g_model.telemetrySensors[--sensor].unit == unit;
sensor -= 1;
return g_model.telemetrySensors[sensor].unit == unit;
} }
bool isCellsSensor(int sensor) bool isCellsSensor(int sensor)
@ -184,7 +180,7 @@ bool isGPSSensor(int sensor)
bool isAltSensor(int sensor) bool isAltSensor(int sensor)
{ {
return isSensorUnit(sensor, UNIT_DIST); return isSensorUnit(sensor, UNIT_DIST) || isSensorUnit(sensor, UNIT_FEET);
} }
bool isVoltsSensor(int sensor) bool isVoltsSensor(int sensor)

View file

@ -254,7 +254,7 @@ void displayTopBar()
if (altitudeItem.isAvailable()) { if (altitudeItem.isAvailable()) {
LCD_ICON(altitude_icon_x, BAR_Y, ICON_ALTITUDE); LCD_ICON(altitude_icon_x, BAR_Y, ICON_ALTITUDE);
int32_t value = altitudeItem.value / g_model.telemetrySensors[item].getPrecDivisor(); int32_t value = altitudeItem.value / g_model.telemetrySensors[item].getPrecDivisor();
putsValueWithUnit(altitude_icon_x+2*FW-1, BAR_Y+1, value, UNIT_METERS, LEFT); putsValueWithUnit(altitude_icon_x+2*FW-1, BAR_Y+1, value, g_model.telemetrySensors[item].unit, LEFT);
} }
} }
} }

View file

@ -1317,8 +1317,8 @@ PACK(typedef struct {
int32_t getValue(int32_t value, uint8_t unit, uint8_t prec) const; int32_t getValue(int32_t value, uint8_t unit, uint8_t prec) const;
bool isConfigurable() const; bool isConfigurable() const;
bool isPrecConfigurable() const; bool isPrecConfigurable() const;
uint32_t getPrecMultiplier() const; int32_t getPrecMultiplier() const;
uint32_t getPrecDivisor() const; int32_t getPrecDivisor() const;
}) TelemetrySensor; }) TelemetrySensor;
#endif #endif

View file

@ -647,14 +647,18 @@ bool TelemetrySensor::isPrecConfigurable() const
} }
} }
uint32_t TelemetrySensor::getPrecMultiplier() const int32_t TelemetrySensor::getPrecMultiplier() const
{ {
/*
Important: the return type must be signed, otherwise
mathematic operations with a negative telemetry value won't work
*/
if (prec == 2) return 1; if (prec == 2) return 1;
if (prec == 1) return 10; if (prec == 1) return 10;
return 100; return 100;
} }
uint32_t TelemetrySensor::getPrecDivisor() const int32_t TelemetrySensor::getPrecDivisor() const
{ {
if (prec == 2) return 100; if (prec == 2) return 100;
if (prec == 1) return 10; if (prec == 1) return 10;