mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
Fixes #1844
This commit is contained in:
parent
b79c4ea79e
commit
a3f712b3dc
9 changed files with 104 additions and 46 deletions
|
@ -956,7 +956,7 @@ class SensorData {
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
|
|
||||||
// for calculations
|
// for calculations
|
||||||
unsigned int sources[4];
|
int sources[4];
|
||||||
|
|
||||||
// for GPS dist
|
// for GPS dist
|
||||||
unsigned int gps;
|
unsigned int gps;
|
||||||
|
|
|
@ -2671,7 +2671,7 @@ class SensorField: public TransformedField {
|
||||||
if (sensor.formula == SensorData::FORMULA_CELL)
|
if (sensor.formula == SensorData::FORMULA_CELL)
|
||||||
_param = (sensor.source) + (sensor.index << 8);
|
_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::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)
|
else if (sensor.formula == SensorData::FORMULA_DIST)
|
||||||
_param = (sensor.gps) + (sensor.alt << 8);
|
_param = (sensor.gps) + (sensor.alt << 8);
|
||||||
else if (sensor.formula == SensorData::FORMULA_CONSUMPTION)
|
else if (sensor.formula == SensorData::FORMULA_CONSUMPTION)
|
||||||
|
|
|
@ -488,6 +488,12 @@ TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor,
|
||||||
ui->altSensor->setField(sensor.alt);
|
ui->altSensor->setField(sensor.alt);
|
||||||
ui->ampsSensor->setField(sensor.amps);
|
ui->ampsSensor->setField(sensor.amps);
|
||||||
ui->cellsSensor->setField(sensor.source);
|
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->source1->setField(sensor.sources[0]);
|
||||||
ui->source2->setField(sensor.sources[1]);
|
ui->source2->setField(sensor.sources[1]);
|
||||||
ui->source3->setField(sensor.sources[2]);
|
ui->source3->setField(sensor.sources[2]);
|
||||||
|
@ -530,13 +536,14 @@ void TelemetrySensorPanel::update()
|
||||||
consFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CONSUMPTION);
|
consFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CONSUMPTION);
|
||||||
sources12FieldsDisplayed = (sensor.formula <= SensorData::FORMULA_MULTIPLY);
|
sources12FieldsDisplayed = (sensor.formula <= SensorData::FORMULA_MULTIPLY);
|
||||||
sources34FieldsDisplayed = (sensor.formula < SensorData::FORMULA_MULTIPLY);
|
sources34FieldsDisplayed = (sensor.formula < SensorData::FORMULA_MULTIPLY);
|
||||||
updateSourcesComboBox(ui->source1);
|
updateSourcesComboBox(ui->source1, true);
|
||||||
updateSourcesComboBox(ui->source2);
|
updateSourcesComboBox(ui->source2, true);
|
||||||
updateSourcesComboBox(ui->source3);
|
updateSourcesComboBox(ui->source3, true);
|
||||||
updateSourcesComboBox(ui->source4);
|
updateSourcesComboBox(ui->source4, true);
|
||||||
updateSourcesComboBox(ui->gpsSensor);
|
updateSourcesComboBox(ui->gpsSensor, false);
|
||||||
updateSourcesComboBox(ui->altSensor);
|
updateSourcesComboBox(ui->altSensor, false);
|
||||||
updateSourcesComboBox(ui->ampsSensor);
|
updateSourcesComboBox(ui->ampsSensor, false);
|
||||||
|
updateSourcesComboBox(ui->cellsSensor, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui->idLabel->show();
|
ui->idLabel->show();
|
||||||
|
@ -573,19 +580,25 @@ void TelemetrySensorPanel::update()
|
||||||
lock = false;
|
lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model)
|
void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model, bool negative)
|
||||||
{
|
{
|
||||||
cb->clear();
|
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);
|
cb->addItem("---", 0);
|
||||||
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
|
for (int i=1; i<=C9X_MAX_SENSORS; ++i) {
|
||||||
if (model->sensorData[i].isAvailable())
|
if (model->sensorData[i-1].isAvailable())
|
||||||
cb->addItem(model->sensorData[i].label, i+1);
|
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()
|
void TelemetrySensorPanel::on_name_editingFinished()
|
||||||
|
@ -712,8 +725,8 @@ void TelemetryPanel::update()
|
||||||
ui->telemetryProtocol->setCurrentIndex(0);
|
ui->telemetryProtocol->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
populateTelemetrySourcesComboBox(ui->voltsSource, model);
|
populateTelemetrySourcesComboBox(ui->voltsSource, model, false);
|
||||||
populateTelemetrySourcesComboBox(ui->altitudeSource, model);
|
populateTelemetrySourcesComboBox(ui->altitudeSource, model, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ARM(firmware->getBoard())) {
|
if (IS_ARM(firmware->getBoard())) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ class TelemetrySensorPanel: public ModelPanel
|
||||||
void on_prec_editingFinished();
|
void on_prec_editingFinished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateSourcesComboBox(AutoComboBox * cb);
|
void updateSourcesComboBox(AutoComboBox * cb, bool negative);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TelemetrySensor * ui;
|
Ui::TelemetrySensor * ui;
|
||||||
|
|
|
@ -25,7 +25,7 @@ class AutoComboBox: public QComboBox
|
||||||
lock = false;
|
lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addItem(const QString & item, unsigned int value)
|
void addItem(const QString & item, int value)
|
||||||
{
|
{
|
||||||
lock = true;
|
lock = true;
|
||||||
QComboBox::addItem(item, value);
|
QComboBox::addItem(item, value);
|
||||||
|
@ -36,6 +36,17 @@ class AutoComboBox: public QComboBox
|
||||||
}
|
}
|
||||||
|
|
||||||
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
||||||
|
{
|
||||||
|
this->field = (int *)&field;
|
||||||
|
this->panel = panel;
|
||||||
|
for (int i=0; i<count(); ++i) {
|
||||||
|
setItemData(i, i);
|
||||||
|
if ((int)field == i)
|
||||||
|
setCurrentIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setField(int & field, ModelPanel * panel=NULL)
|
||||||
{
|
{
|
||||||
this->field = &field;
|
this->field = &field;
|
||||||
this->panel = panel;
|
this->panel = panel;
|
||||||
|
@ -58,7 +69,7 @@ class AutoComboBox: public QComboBox
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int * field;
|
int * field;
|
||||||
ModelPanel * panel;
|
ModelPanel * panel;
|
||||||
bool lock;
|
bool lock;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5886,10 +5886,8 @@ bool isSensorAvailable(int sensor)
|
||||||
{
|
{
|
||||||
if (sensor == 0)
|
if (sensor == 0)
|
||||||
return true;
|
return true;
|
||||||
|
else
|
||||||
sensor -= 1;
|
return isTelemetryFieldAvailable(abs(sensor) - 1);
|
||||||
|
|
||||||
return isTelemetryFieldAvailable(sensor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SENSOR_2ND_COLUMN (12*FW)
|
#define SENSOR_2ND_COLUMN (12*FW)
|
||||||
|
@ -6038,7 +6036,7 @@ void menuModelSensor(uint8_t event)
|
||||||
case SENSOR_FIELD_PARAM2:
|
case SENSOR_FIELD_PARAM2:
|
||||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||||
|
@ -6065,10 +6063,16 @@ void menuModelSensor(uint8_t event)
|
||||||
case SENSOR_FIELD_PARAM4:
|
case SENSOR_FIELD_PARAM4:
|
||||||
{
|
{
|
||||||
putsStrIdx(0, y, "Source", k-SENSOR_FIELD_PARAM1+1);
|
putsStrIdx(0, y, "Source", k-SENSOR_FIELD_PARAM1+1);
|
||||||
uint8_t & source = sensor->calc.sources[k-SENSOR_FIELD_PARAM1];
|
int8_t & source = sensor->calc.sources[k-SENSOR_FIELD_PARAM1];
|
||||||
putsMixerSource(SENSOR_2ND_COLUMN, y, source ? MIXSRC_FIRST_TELEM+3*(source-1) : 0, attr);
|
|
||||||
if (attr) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1181,7 +1181,7 @@ PACK(typedef struct {
|
||||||
uint16_t spare;
|
uint16_t spare;
|
||||||
}) cell;
|
}) cell;
|
||||||
PACK(struct {
|
PACK(struct {
|
||||||
uint8_t sources[4];
|
int8_t sources[4];
|
||||||
}) calc;
|
}) calc;
|
||||||
PACK(struct {
|
PACK(struct {
|
||||||
uint8_t source;
|
uint8_t source;
|
||||||
|
|
|
@ -242,28 +242,42 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
||||||
lastReceived = TELEMETRY_VALUE_OLD;
|
lastReceived = TELEMETRY_VALUE_OLD;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint8_t index = sensor.cell.index;
|
unsigned int index = sensor.cell.index;
|
||||||
if (index == 0 || index == 7) {
|
if (index == TELEM_CELL_INDEX_LOWEST || index == TELEM_CELL_INDEX_HIGHEST || index == TELEM_CELL_INDEX_DELTA) {
|
||||||
bool lowest = (index == 0);
|
unsigned int lowest=0, highest=0;
|
||||||
index = 0;
|
|
||||||
for (int i=0; i<cellsItem.cells.count; i++) {
|
for (int i=0; i<cellsItem.cells.count; i++) {
|
||||||
if (cellsItem.cells.values[i].state) {
|
if (cellsItem.cells.values[i].state) {
|
||||||
if (index == 0 || (lowest && cellsItem.cells.values[i].value < cellsItem.cells.values[index-1].value) || (!lowest && cellsItem.cells.values[i].value > cellsItem.cells.values[index-1].value)) {
|
if (!lowest || cellsItem.cells.values[i].value < cellsItem.cells.values[lowest-1].value)
|
||||||
index = i+1;
|
lowest = i+1;
|
||||||
}
|
if (!highest || cellsItem.cells.values[i].value > cellsItem.cells.values[highest-1].value)
|
||||||
|
highest = i+1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
index = 0;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
if (index < cellsItem.cells.count && cellsItem.cells.values[index].state) {
|
if (index < cellsItem.cells.count && cellsItem.cells.values[index].state) {
|
||||||
setValue(sensor, cellsItem.cells.values[index].value, UNIT_VOLTS, 2);
|
setValue(sensor, cellsItem.cells.values[index].value, UNIT_VOLTS, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TELEM_FORMULA_DIST:
|
case TELEM_FORMULA_DIST:
|
||||||
|
@ -322,10 +336,11 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
for (int i=0; i<maxitems; i++) {
|
for (int i=0; i<maxitems; i++) {
|
||||||
uint8_t source = sensor.calc.sources[i];
|
int8_t source = sensor.calc.sources[i];
|
||||||
if (source) {
|
if (source) {
|
||||||
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[source-1];
|
unsigned int index = abs(source)-1;
|
||||||
TelemetryItem & telemetryItem = telemetryItems[source-1];
|
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[index];
|
||||||
|
TelemetryItem & telemetryItem = telemetryItems[index];
|
||||||
if (sensor.formula == TELEM_FORMULA_AVERAGE) {
|
if (sensor.formula == TELEM_FORMULA_AVERAGE) {
|
||||||
if (telemetryItem.isAvailable())
|
if (telemetryItem.isAvailable())
|
||||||
available = 1;
|
available = 1;
|
||||||
|
@ -343,13 +358,16 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int32_t sensorValue = telemetryItem.value;
|
||||||
|
if (source < 0)
|
||||||
|
sensorValue = -sensorValue;
|
||||||
count += 1;
|
count += 1;
|
||||||
if (sensor.formula == TELEM_FORMULA_MULTIPLY) {
|
if (sensor.formula == TELEM_FORMULA_MULTIPLY) {
|
||||||
mulprec += telemetrySensor.prec;
|
mulprec += telemetrySensor.prec;
|
||||||
value *= convertTelemetryValue(telemetryItem.value, telemetrySensor.unit, 0, sensor.unit, 0);
|
value *= convertTelemetryValue(sensorValue, telemetrySensor.unit, 0, sensor.unit, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int32_t sensorValue = convertTelemetryValue(telemetryItem.value, telemetrySensor.unit, telemetrySensor.prec, sensor.unit, sensor.prec);
|
sensorValue = convertTelemetryValue(sensorValue, telemetrySensor.unit, telemetrySensor.prec, sensor.unit, sensor.prec);
|
||||||
if (sensor.formula == TELEM_FORMULA_MIN)
|
if (sensor.formula == TELEM_FORMULA_MIN)
|
||||||
value = (count==1 ? sensorValue : min<int32_t>(value, sensorValue));
|
value = (count==1 ? sensorValue : min<int32_t>(value, sensorValue));
|
||||||
else if (sensor.formula == TELEM_FORMULA_MAX)
|
else if (sensor.formula == TELEM_FORMULA_MAX)
|
||||||
|
|
|
@ -50,6 +50,18 @@ enum TelemetryProtocol
|
||||||
|
|
||||||
#define TELEMETRY_AVERAGE_COUNT 3
|
#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
|
PACK(struct CellValue
|
||||||
{
|
{
|
||||||
uint16_t value:15;
|
uint16_t value:15;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue