1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

Merge remote-tracking branch 'origin/next' into Horus

# Conflicts:
#	companion/src/CMakeLists.txt
#	companion/src/firmwares/opentx/opentxinterface.cpp
#	companion/src/firmwares/opentx/simulator/CMakeLists.txt
#	companion/src/firmwares/opentx/stamp-opentx.h.in
#	radio/src/Makefile
#	radio/src/cli.cpp
#	radio/src/gui/Taranis/helpers.cpp
#	radio/src/gui/Taranis/lcd.cpp
#	radio/src/gui/Taranis/menu_model_setup.cpp
#	radio/src/gui/Taranis/view_main.cpp
#	radio/src/lua_api.cpp
#	radio/src/main_avr.cpp
#	radio/src/myeeprom.h
#	radio/src/opentx.cpp
#	radio/src/pulses/pxx_arm.cpp
#	radio/src/storage/eeprom_conversions.cpp
#	radio/src/targets/Horus/adc_driver.cpp
#	radio/src/targets/Horus/board_horus.cpp
#	radio/src/targets/Horus/board_horus.h
#	radio/src/targets/Horus/diskio.cpp
#	radio/src/targets/Horus/hal.h
#	radio/src/targets/Horus/haptic_driver.cpp
#	radio/src/targets/Horus/i2c_driver.cpp
#	radio/src/targets/Horus/keys_driver.cpp
#	radio/src/targets/Horus/lcd_driver.cpp
#	radio/src/targets/Horus/led_driver.cpp
#	radio/src/targets/Horus/pulses_driver.cpp
#	radio/src/targets/Horus/pwr_driver.c
#	radio/src/targets/Horus/sdio_sd.c
#	radio/src/targets/Horus/sdio_sd.h
#	radio/src/targets/Horus/serial2_driver.cpp
#	radio/src/targets/Horus/telemetry_driver.cpp
#	radio/src/targets/Horus/usb_conf.h
#	radio/src/targets/Horus/usbd_desc.c
#	radio/src/targets/Horus/usbd_storage_msd.cpp
This commit is contained in:
Bertrand Songis 2015-11-15 22:01:24 +01:00
commit de733579d5
85 changed files with 7038 additions and 3664 deletions

View file

@ -366,10 +366,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
result += dist*dist;
if (altItem) {
dist = abs(altItem->value);
uint8_t prec = g_model.telemetrySensors[sensor.dist.alt-1].prec;
if (prec > 0)
dist /= (prec==2 ? 100 : 10);
dist = abs(altItem->value) / g_model.telemetrySensors[sensor.dist.alt-1].getPrecDivisor();
result += dist*dist;
}
@ -545,49 +542,56 @@ void TelemetrySensor::init(uint16_t id)
init(label);
}
bool TelemetrySensor::isAvailable()
bool TelemetrySensor::isAvailable() const
{
return ZLEN(label) > 0;
}
PACK(typedef struct {
uint8_t unitFrom;
uint8_t unitTo;
int16_t multiplier;
int16_t divisor;
}) UnitConversionRule;
const UnitConversionRule unitConversionTable[] = {
/* unitFrom unitTo multiplier divisor */
{ UNIT_METERS, UNIT_FEET, 105, 32},
{ UNIT_METERS_PER_SECOND, UNIT_FEET_PER_SECOND, 105, 32},
{ UNIT_KTS, UNIT_KMH, 1852, 1000}, // 1 knot = 1.85200 kilometers per hour
{ UNIT_KTS, UNIT_MPH, 1151, 1000}, // 1 knot = 1.15077945 miles per hour
{ UNIT_KTS, UNIT_METERS_PER_SECOND, 1000, 1944}, // 1 knot = 0.514444444 meters / second (divide with 1.94384449)
{ UNIT_KTS, UNIT_FEET_PER_SECOND, 1688, 1000}, // 1 knot = 1.68780986 feet per second
{ UNIT_KMH, UNIT_KTS, 1000, 1852}, // 1 km/h = 0.539956803 knots (divide with 1.85200)
{ UNIT_KMH, UNIT_MPH, 1000, 1609}, // 1 km/h = 0.621371192 miles per hour (divide with 1.60934400)
{ UNIT_KMH, UNIT_METERS_PER_SECOND, 10, 36}, // 1 km/h = 0.277777778 meters / second (divide with 3.6)
{ UNIT_KMH, UNIT_FEET_PER_SECOND, 911, 1000}, // 1 km/h = 0.911344415 feet per second
{ UNIT_MILLILITERS, UNIT_FLOZ, 100, 2957},
{ 0, 0, 0, 0} // termination
};
int32_t convertTelemetryValue(int32_t value, uint8_t unit, uint8_t prec, uint8_t destUnit, uint8_t destPrec)
{
for (int i=prec; i<destPrec; i++)
value *= 10;
if (unit == UNIT_METERS || unit == UNIT_METERS_PER_SECOND) {
if (destUnit == UNIT_FEET || destUnit == UNIT_FEET_PER_SECOND) {
// m to ft *105/32
value = (value * 105) / 32;
}
}
else if (unit == UNIT_KTS) {
if (destUnit == UNIT_KMH) {
// kts to km/h (1 knot = 1.85200 kilometers per hour)
value = (value * 1852) / 1000;
}
else if (destUnit == UNIT_MPH) {
// kts to mph (1 knot = 1.15077945 miles per hour)
value = (value * 1151) / 1000;
}
else if (destUnit == UNIT_METERS_PER_SECOND) {
// kts to m/s (1 knot = 0.514444444 meters / second)
value = (value * 514) / 1000;
}
else if (destUnit == UNIT_FEET_PER_SECOND) {
// kts to f/s (1 knot = 1.68780986 feet per second)
value = (value * 1688) / 1000;
}
}
else if (unit == UNIT_CELSIUS) {
if (unit == UNIT_CELSIUS) {
if (destUnit == UNIT_FAHRENHEIT) {
// T(°F) = T(°C)×1,8 + 32
value = 32 + (value*18)/10;
value = 32 + (value*18) / 10;
}
}
else if (unit == UNIT_MILLILITERS) {
if (destUnit == UNIT_FLOZ) {
value = (value * 100) / 2957;
else {
const UnitConversionRule * p = unitConversionTable;
while (p->divisor) {
if (p->unitFrom == unit && p->unitTo == destUnit) {
value = (value * (int32_t)p->multiplier) / (int32_t)p->divisor;
break;
}
++p;
}
}
@ -622,7 +626,7 @@ int32_t TelemetrySensor::getValue(int32_t value, uint8_t unit, uint8_t prec) con
return value;
}
bool TelemetrySensor::isConfigurable()
bool TelemetrySensor::isConfigurable() const
{
if (type == TELEM_TYPE_CALCULATED) {
if (formula >= TELEM_FORMULA_CELL) {
@ -637,7 +641,7 @@ bool TelemetrySensor::isConfigurable()
return true;
}
bool TelemetrySensor::isPrecConfigurable()
bool TelemetrySensor::isPrecConfigurable() const
{
if (isConfigurable()) {
return true;
@ -649,3 +653,21 @@ bool TelemetrySensor::isPrecConfigurable()
return false;
}
}
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 == 1) return 10;
return 100;
}
int32_t TelemetrySensor::getPrecDivisor() const
{
if (prec == 2) return 100;
if (prec == 1) return 10;
return 1;
}