From 28e92d964a60852fe6892ee738661563244381bf Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Sat, 9 May 2015 21:49:27 +0400 Subject: [PATCH] Fix lots of broken stuff in companion telemetry sensor handling, sync displayed items/units/formulas with firmware (should fix #2285) --- companion/src/eeprominterface.cpp | 4 +- companion/src/eeprominterface.h | 41 ++++++++++++++----- .../src/firmwares/opentx/opentxeeprom.cpp | 20 ++++----- companion/src/modeledit/telemetry.cpp | 37 +++++++++-------- companion/src/modeledit/telemetry_sensor.ui | 31 ++++++++------ .../src/gui/Taranis/menu_model_telemetry.cpp | 2 +- 6 files changed, 81 insertions(+), 54 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index a69b12851..b8270f629 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -95,8 +95,8 @@ QString getGVarString(int16_t val, bool sign) void SensorData::updateUnit() { - if (type == TYPE_CALCULATED) { - if (formula == FORMULA_CONSUMPTION) + if (type == TELEM_TYPE_CALCULATED) { + if (formula == TELEM_FORMULA_CONSUMPTION) unit = UNIT_MAH; } } diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 289b148b3..ce9d13c67 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -855,29 +855,45 @@ class SensorData { enum { - TYPE_CUSTOM, - TYPE_CALCULATED + TELEM_TYPE_CUSTOM, + TELEM_TYPE_CALCULATED }; enum { - FORMULA_ADD, - FORMULA_AVERAGE, - FORMULA_MIN, - FORMULA_MAX, - FORMULA_MULTIPLY, - FORMULA_CELL, - FORMULA_CONSUMPTION, - FORMULA_DIST + TELEM_FORMULA_ADD, + TELEM_FORMULA_AVERAGE, + TELEM_FORMULA_MIN, + TELEM_FORMULA_MAX, + TELEM_FORMULA_MULTIPLY, + TELEM_FORMULA_TOTALIZE, + TELEM_FORMULA_CELL, + TELEM_FORMULA_CONSUMPTION, + TELEM_FORMULA_DIST, + TELEM_FORMULA_LAST = TELEM_FORMULA_DIST }; enum { + TELEM_CELL_INDEX_LOWEST, + TELEM_CELL_INDEX_1, + TELEM_CELL_INDEX_2, + TELEM_CELL_INDEX_3, + TELEM_CELL_INDEX_4, + TELEM_CELL_INDEX_5, + TELEM_CELL_INDEX_6, + TELEM_CELL_INDEX_HIGHEST, + TELEM_CELL_INDEX_DELTA, + }; + + enum + { UNIT_RAW, UNIT_VOLTS, UNIT_AMPS, UNIT_MILLIAMPS, UNIT_KTS, UNIT_METERS_PER_SECOND, + UNIT_FEET_PER_SECOND, UNIT_KMH, UNIT_MPH, UNIT_METERS, @@ -891,11 +907,14 @@ class SensorData { UNIT_RPMS, UNIT_G, UNIT_DEGREE, + UNIT_MILLILITERS, + UNIT_FLOZ, UNIT_HOURS, UNIT_MINUTES, UNIT_SECONDS, // FrSky format used for these fields, could be another format in the future - UNIT_CELLS, + UNIT_FIRST_VIRTUAL, + UNIT_CELLS = UNIT_FIRST_VIRTUAL, UNIT_DATETIME, UNIT_GPS, UNIT_GPS_LONGITUDE, diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index c4523d94c..5d9cc8bd3 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -2706,7 +2706,7 @@ class SensorField: public TransformedField { virtual void beforeExport() { - if (sensor.type == SensorData::TYPE_CUSTOM) { + if (sensor.type == SensorData::TELEM_TYPE_CUSTOM) { _id = sensor.id; _instance = sensor.instance; _param = (sensor.ratio) + (sensor.offset << 16); @@ -2714,20 +2714,20 @@ class SensorField: public TransformedField { else { _id = sensor.persistentValue; _instance = sensor.formula; - if (sensor.formula == SensorData::FORMULA_CELL) + if (sensor.formula == SensorData::TELEM_FORMULA_CELL) _param = (sensor.source) + (sensor.index << 8); - else if (sensor.formula == SensorData::FORMULA_ADD || sensor.formula == SensorData::FORMULA_MULTIPLY || sensor.formula == SensorData::FORMULA_MIN || sensor.formula == SensorData::FORMULA_MAX) + else if (sensor.formula == SensorData::TELEM_FORMULA_ADD || sensor.formula == SensorData::TELEM_FORMULA_MULTIPLY || sensor.formula == SensorData::TELEM_FORMULA_MIN || sensor.formula == SensorData::TELEM_FORMULA_MAX) _param = ((uint8_t)sensor.sources[0]) + ((uint8_t)sensor.sources[1] << 8) + ((uint8_t)sensor.sources[2] << 16) + ((uint8_t)sensor.sources[3] << 24); - else if (sensor.formula == SensorData::FORMULA_DIST) + else if (sensor.formula == SensorData::TELEM_FORMULA_DIST) _param = (sensor.gps) + (sensor.alt << 8); - else if (sensor.formula == SensorData::FORMULA_CONSUMPTION) + else if (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION) _param = (sensor.amps); } } virtual void afterImport() { - if (sensor.type == SensorData::TYPE_CUSTOM) { + if (sensor.type == SensorData::TELEM_TYPE_CUSTOM) { sensor.id = _id; sensor.instance = _instance; sensor.ratio = _param & 0xFF; @@ -2736,14 +2736,14 @@ class SensorField: public TransformedField { else { sensor.persistentValue = _id; sensor.formula = _instance; - if (sensor.formula == SensorData::FORMULA_CELL) + if (sensor.formula == SensorData::TELEM_FORMULA_CELL) (sensor.source = _sources[0], sensor.index = _sources[1]); - else if (sensor.formula == SensorData::FORMULA_ADD || sensor.formula == SensorData::FORMULA_MULTIPLY || sensor.formula == SensorData::FORMULA_MIN || sensor.formula == SensorData::FORMULA_MAX) + else if (sensor.formula == SensorData::TELEM_FORMULA_ADD || sensor.formula == SensorData::TELEM_FORMULA_MULTIPLY || sensor.formula == SensorData::TELEM_FORMULA_MIN || sensor.formula == SensorData::TELEM_FORMULA_MAX) for (int i=0; i<4; ++i) sensor.sources[i] = _sources[i]; - else if (sensor.formula == SensorData::FORMULA_DIST) + else if (sensor.formula == SensorData::TELEM_FORMULA_DIST) (sensor.gps = _sources[0], sensor.alt = _sources[1]); - else if (sensor.formula == SensorData::FORMULA_CONSUMPTION) + else if (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION) sensor.amps = _sources[0]; } } diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index d90196f5e..ab66467f1 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -494,11 +494,11 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ui->altSensor->setField(sensor.alt); ui->ampsSensor->setField(sensor.amps); ui->cellsSensor->setField(sensor.source); - ui->cellsIndex->addItem(tr("Lowest"), 0); - for (int i=1; i<=6; ++i) + ui->cellsIndex->addItem(tr("Lowest"), SensorData::TELEM_CELL_INDEX_LOWEST); + for (int i=1; i<=6; i++) ui->cellsIndex->addItem(tr("Cell %1").arg(i), i); - ui->cellsIndex->addItem(tr("Highest"), 0); - ui->cellsIndex->addItem(tr("Delta"), 0); + ui->cellsIndex->addItem(tr("Highest"), SensorData::TELEM_CELL_INDEX_HIGHEST); + ui->cellsIndex->addItem(tr("Delta"), SensorData::TELEM_CELL_INDEX_DELTA); ui->cellsIndex->setField(sensor.index); ui->source1->setField(sensor.sources[0]); ui->source2->setField(sensor.sources[1]); @@ -514,7 +514,7 @@ TelemetrySensorPanel::~TelemetrySensorPanel() void TelemetrySensorPanel::update() { - bool precDisplayed = false; + bool isConfigurable = false; bool gpsFieldsDisplayed = false; bool cellsFieldsDisplayed = false; bool consFieldsDisplayed = false; @@ -528,7 +528,7 @@ void TelemetrySensorPanel::update() ui->unit->setCurrentIndex(sensor.unit); ui->prec->setValue(sensor.prec); - if (sensor.type == SensorData::TYPE_CALCULATED) { + if (sensor.type == SensorData::TELEM_TYPE_CALCULATED) { sensor.updateUnit(); ui->idLabel->hide(); ui->id->hide(); @@ -536,12 +536,12 @@ void TelemetrySensorPanel::update() ui->instance->hide(); ui->formula->show(); ui->formula->setCurrentIndex(sensor.formula); - precDisplayed = (sensor.formula < SensorData::FORMULA_CELL); - gpsFieldsDisplayed = (sensor.formula == SensorData::FORMULA_DIST); - cellsFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CELL); - consFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CONSUMPTION); - sources12FieldsDisplayed = (sensor.formula <= SensorData::FORMULA_MULTIPLY); - sources34FieldsDisplayed = (sensor.formula < SensorData::FORMULA_MULTIPLY); + isConfigurable = (sensor.formula < SensorData::TELEM_FORMULA_CELL); + gpsFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_DIST); + cellsFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_CELL); + consFieldsDisplayed = (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION); + sources12FieldsDisplayed = (sensor.formula <= SensorData::TELEM_FORMULA_MULTIPLY); + sources34FieldsDisplayed = (sensor.formula < SensorData::TELEM_FORMULA_MULTIPLY); updateSourcesComboBox(ui->source1, true); updateSourcesComboBox(ui->source2, true); updateSourcesComboBox(ui->source3, true); @@ -557,8 +557,8 @@ void TelemetrySensorPanel::update() ui->instanceLabel->show(); ui->instance->show(); ui->formula->hide(); - ratioFieldsDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME); - precDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME); + isConfigurable = sensor.unit < SensorData::UNIT_FIRST_VIRTUAL; + ratioFieldsDisplayed = (sensor.unit < SensorData::UNIT_FIRST_VIRTUAL); ui->offset->setMaximum((sensor.prec > 0 ? sensor.prec == 2 ? 30000 : 3000 : 300)); ui->offset->setMinimum((sensor.prec > 0 ? sensor.prec == 2 ? -30000 : -3000 : -300)); @@ -581,9 +581,9 @@ void TelemetrySensorPanel::update() ui->offsetLabel->setVisible(ratioFieldsDisplayed && sensor.unit != SensorData::UNIT_RPMS); ui->multiplierLabel->setVisible(sensor.unit == SensorData::UNIT_RPMS); ui->offset->setVisible(ratioFieldsDisplayed); - ui->precLabel->setVisible(precDisplayed); - ui->prec->setVisible(precDisplayed); - ui->unit->setVisible(precDisplayed); + ui->precLabel->setVisible(isConfigurable); + ui->prec->setVisible(isConfigurable && sensor.unit != SensorData::UNIT_FAHRENHEIT); + ui->unit->setVisible((sensor.type == SensorData::TELEM_TYPE_CALCULATED && (sensor.formula == SensorData::TELEM_FORMULA_DIST)) || isConfigurable); ui->gpsSensorLabel->setVisible(gpsFieldsDisplayed); ui->gpsSensor->setVisible(gpsFieldsDisplayed); ui->altSensorLabel->setVisible(gpsFieldsDisplayed); @@ -597,6 +597,9 @@ void TelemetrySensorPanel::update() ui->source2->setVisible(sources12FieldsDisplayed); ui->source3->setVisible(sources34FieldsDisplayed); ui->source4->setVisible(sources34FieldsDisplayed); + ui->autoOffset->setVisible(sensor.unit != SensorData::UNIT_RPMS && isConfigurable); + ui->filter->setVisible(isConfigurable); + ui->persistent->setVisible((sensor.type == SensorData::TELEM_TYPE_CALCULATED && sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION) || isConfigurable); lock = false; } diff --git a/companion/src/modeledit/telemetry_sensor.ui b/companion/src/modeledit/telemetry_sensor.ui index 09db2719e..46fcf2fba 100644 --- a/companion/src/modeledit/telemetry_sensor.ui +++ b/companion/src/modeledit/telemetry_sensor.ui @@ -13,7 +13,7 @@ Form - + 0 @@ -48,7 +48,7 @@ - Formula + Calculated @@ -147,6 +147,11 @@ Multiply + + + Totalize + + Cell @@ -406,7 +411,7 @@ - Feet (f) + Feet (ft) @@ -602,16 +607,6 @@ - - - - Qt::LeftToRight - - - Logs - - - @@ -622,6 +617,16 @@ + + + + Qt::LeftToRight + + + Logs + + + diff --git a/radio/src/gui/Taranis/menu_model_telemetry.cpp b/radio/src/gui/Taranis/menu_model_telemetry.cpp index e5bf80d4a..8829ca4da 100644 --- a/radio/src/gui/Taranis/menu_model_telemetry.cpp +++ b/radio/src/gui/Taranis/menu_model_telemetry.cpp @@ -202,7 +202,7 @@ bool isSensorAvailable(int sensor) #define SENSOR_2ND_COLUMN (12*FW) #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_UNIT_ROWS ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_PREC_ROWS (sensor->isConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (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)