diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 4cde2ced6..13554eb9a 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -956,7 +956,7 @@ class SensorData { unsigned int index; // for calculations - unsigned int sources[4]; + int sources[4]; // for GPS dist unsigned int gps; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index e10ce2173..84f3555c3 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -2671,7 +2671,7 @@ class SensorField: public TransformedField { if (sensor.formula == SensorData::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) - _param = (sensor.sources[0]) + (sensor.sources[1] << 8) + (sensor.sources[2] << 16) + (sensor.sources[3] << 24); + _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) _param = (sensor.gps) + (sensor.alt << 8); else if (sensor.formula == SensorData::FORMULA_CONSUMPTION) diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index 78f0fb858..daa655d5a 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -488,6 +488,12 @@ 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("Cell %1").arg(i), i); + ui->cellsIndex->addItem(tr("Highest"), 0); + ui->cellsIndex->addItem(tr("Delta"), 0); + ui->cellsIndex->setField(sensor.index); ui->source1->setField(sensor.sources[0]); ui->source2->setField(sensor.sources[1]); ui->source3->setField(sensor.sources[2]); @@ -530,13 +536,14 @@ void TelemetrySensorPanel::update() consFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CONSUMPTION); sources12FieldsDisplayed = (sensor.formula <= SensorData::FORMULA_MULTIPLY); sources34FieldsDisplayed = (sensor.formula < SensorData::FORMULA_MULTIPLY); - updateSourcesComboBox(ui->source1); - updateSourcesComboBox(ui->source2); - updateSourcesComboBox(ui->source3); - updateSourcesComboBox(ui->source4); - updateSourcesComboBox(ui->gpsSensor); - updateSourcesComboBox(ui->altSensor); - updateSourcesComboBox(ui->ampsSensor); + updateSourcesComboBox(ui->source1, true); + updateSourcesComboBox(ui->source2, true); + updateSourcesComboBox(ui->source3, true); + updateSourcesComboBox(ui->source4, true); + updateSourcesComboBox(ui->gpsSensor, false); + updateSourcesComboBox(ui->altSensor, false); + updateSourcesComboBox(ui->ampsSensor, false); + updateSourcesComboBox(ui->cellsSensor, false); } else { ui->idLabel->show(); @@ -573,19 +580,25 @@ void TelemetrySensorPanel::update() lock = false; } -void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model) +void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model, bool negative) { cb->clear(); + if (negative) { + for (int i=-C9X_MAX_SENSORS; i<0; ++i) { + if (model->sensorData[-i-1].isAvailable()) + cb->addItem(QObject::tr("-%1").arg(model->sensorData[-i-1].label), i); + } + } cb->addItem("---", 0); - for (int i=0; isensorData[i].isAvailable()) - cb->addItem(model->sensorData[i].label, i+1); + for (int i=1; i<=C9X_MAX_SENSORS; ++i) { + if (model->sensorData[i-1].isAvailable()) + cb->addItem(model->sensorData[i-1].label, i); } } -void TelemetrySensorPanel::updateSourcesComboBox(AutoComboBox * cb) +void TelemetrySensorPanel::updateSourcesComboBox(AutoComboBox * cb, bool negative) { - populateTelemetrySourcesComboBox(cb, model); + populateTelemetrySourcesComboBox(cb, model, negative); } void TelemetrySensorPanel::on_name_editingFinished() @@ -712,8 +725,8 @@ void TelemetryPanel::update() ui->telemetryProtocol->setCurrentIndex(0); } - populateTelemetrySourcesComboBox(ui->voltsSource, model); - populateTelemetrySourcesComboBox(ui->altitudeSource, model); + populateTelemetrySourcesComboBox(ui->voltsSource, model, false); + populateTelemetrySourcesComboBox(ui->altitudeSource, model, false); } if (IS_ARM(firmware->getBoard())) { diff --git a/companion/src/modeledit/telemetry.h b/companion/src/modeledit/telemetry.h index c9ef61591..cd5797872 100644 --- a/companion/src/modeledit/telemetry.h +++ b/companion/src/modeledit/telemetry.h @@ -95,7 +95,7 @@ class TelemetrySensorPanel: public ModelPanel void on_prec_editingFinished(); protected: - void updateSourcesComboBox(AutoComboBox * cb); + void updateSourcesComboBox(AutoComboBox * cb, bool negative); private: Ui::TelemetrySensor * ui; diff --git a/companion/src/shared/autocombobox.h b/companion/src/shared/autocombobox.h index f5c9db044..ad370d83b 100755 --- a/companion/src/shared/autocombobox.h +++ b/companion/src/shared/autocombobox.h @@ -25,7 +25,7 @@ class AutoComboBox: public QComboBox lock = false; } - void addItem(const QString & item, unsigned int value) + void addItem(const QString & item, int value) { lock = true; QComboBox::addItem(item, value); @@ -36,6 +36,17 @@ class AutoComboBox: public QComboBox } void setField(unsigned int & field, ModelPanel * panel=NULL) + { + this->field = (int *)&field; + this->panel = panel; + for (int i=0; ifield = &field; this->panel = panel; @@ -58,7 +69,7 @@ class AutoComboBox: public QComboBox } protected: - unsigned int * field; + int * field; ModelPanel * panel; bool lock; }; diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 74615303f..5288efcf7 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -5886,10 +5886,8 @@ bool isSensorAvailable(int sensor) { if (sensor == 0) return true; - - sensor -= 1; - - return isTelemetryFieldAvailable(sensor); + else + return isTelemetryFieldAvailable(abs(sensor) - 1); } #define SENSOR_2ND_COLUMN (12*FW) @@ -6038,7 +6036,7 @@ void menuModelSensor(uint8_t event) case SENSOR_FIELD_PARAM2: if (sensor->type == TELEM_TYPE_CALCULATED) { if (sensor->formula == TELEM_FORMULA_CELL) { - sensor->cell.index = selectMenuItem(SENSOR_2ND_COLUMN, y, "Cell index", "\007Lowest\0001\0 2\0 3\0 4\0 5\0 6\0 Highest", sensor->cell.index, 0, 7, attr, event); + sensor->cell.index = selectMenuItem(SENSOR_2ND_COLUMN, y, "Cell index", "\007Lowest\0001\0 2\0 3\0 4\0 5\0 6\0 HighestDelta\0", sensor->cell.index, 0, 8, attr, event); break; } else if (sensor->formula == TELEM_FORMULA_DIST) { @@ -6065,10 +6063,16 @@ void menuModelSensor(uint8_t event) case SENSOR_FIELD_PARAM4: { putsStrIdx(0, y, "Source", k-SENSOR_FIELD_PARAM1+1); - uint8_t & source = sensor->calc.sources[k-SENSOR_FIELD_PARAM1]; - putsMixerSource(SENSOR_2ND_COLUMN, y, source ? MIXSRC_FIRST_TELEM+3*(source-1) : 0, attr); + int8_t & source = sensor->calc.sources[k-SENSOR_FIELD_PARAM1]; if (attr) { - source = checkIncDec(event, source, 0, TELEM_VALUES_MAX, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable); + source = checkIncDec(event, source, -TELEM_VALUES_MAX, TELEM_VALUES_MAX, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable); + } + if (source < 0) { + lcd_putcAtt(SENSOR_2ND_COLUMN, y, '-', attr); + putsMixerSource(lcdNextPos, y, MIXSRC_FIRST_TELEM+3*(-1-source), attr); + } + else { + putsMixerSource(SENSOR_2ND_COLUMN, y, source ? MIXSRC_FIRST_TELEM+3*(source-1) : 0, attr); } break; } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index b0d177563..c24807899 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -1181,7 +1181,7 @@ PACK(typedef struct { uint16_t spare; }) cell; PACK(struct { - uint8_t sources[4]; + int8_t sources[4]; }) calc; PACK(struct { uint8_t source; diff --git a/radio/src/telemetry/telemetry.cpp b/radio/src/telemetry/telemetry.cpp index 765ece464..a9c53eb94 100755 --- a/radio/src/telemetry/telemetry.cpp +++ b/radio/src/telemetry/telemetry.cpp @@ -242,25 +242,39 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) lastReceived = TELEMETRY_VALUE_OLD; } else { - uint8_t index = sensor.cell.index; - if (index == 0 || index == 7) { - bool lowest = (index == 0); - index = 0; + unsigned int index = sensor.cell.index; + if (index == TELEM_CELL_INDEX_LOWEST || index == TELEM_CELL_INDEX_HIGHEST || index == TELEM_CELL_INDEX_DELTA) { + unsigned int lowest=0, highest=0; for (int i=0; i cellsItem.cells.values[index-1].value)) { - index = i+1; - } + if (!lowest || cellsItem.cells.values[i].value < cellsItem.cells.values[lowest-1].value) + lowest = i+1; + if (!highest || cellsItem.cells.values[i].value > cellsItem.cells.values[highest-1].value) + highest = i+1; } else { - index = 0; - break; + lowest = highest = 0; + } + } + if (lowest) { + switch (index) { + case TELEM_CELL_INDEX_LOWEST: + setValue(sensor, cellsItem.cells.values[lowest-1].value, UNIT_VOLTS, 2); + break; + case TELEM_CELL_INDEX_HIGHEST: + setValue(sensor, cellsItem.cells.values[highest-1].value, UNIT_VOLTS, 2); + break; + case TELEM_CELL_INDEX_DELTA: + setValue(sensor, cellsItem.cells.values[highest-1].value - cellsItem.cells.values[lowest-1].value, UNIT_VOLTS, 2); + break; } } } - index -= 1; - if (index < cellsItem.cells.count && cellsItem.cells.values[index].state) { - setValue(sensor, cellsItem.cells.values[index].value, UNIT_VOLTS, 2); + else { + index -= 1; + if (index < cellsItem.cells.count && cellsItem.cells.values[index].state) { + setValue(sensor, cellsItem.cells.values[index].value, UNIT_VOLTS, 2); + } } } } @@ -322,10 +336,11 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) value = 1; } for (int i=0; i(value, sensorValue)); else if (sensor.formula == TELEM_FORMULA_MAX) diff --git a/radio/src/telemetry/telemetry.h b/radio/src/telemetry/telemetry.h index a5d667d14..e328811f5 100755 --- a/radio/src/telemetry/telemetry.h +++ b/radio/src/telemetry/telemetry.h @@ -50,6 +50,18 @@ enum TelemetryProtocol #define TELEMETRY_AVERAGE_COUNT 3 +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, +}; + PACK(struct CellValue { uint16_t value:15;