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

Add multiplier to RPM sensor (Fix #1688), fix offset/ratio DSBs

This commit is contained in:
Andre Bernet 2015-03-31 17:49:43 +04:00
parent 4110de0e64
commit 8b29aa1e9b
5 changed files with 51 additions and 12 deletions

View file

@ -558,13 +558,28 @@ void TelemetrySensorPanel::update()
ui->instance->show(); ui->instance->show();
ui->formula->hide(); ui->formula->hide();
ratioFieldsDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME); ratioFieldsDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME);
ui->offset->setDecimals(sensor.prec);
precDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME); precDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME);
ui->offset->setMaximum((sensor.prec > 0 ? sensor.prec == 2 ? 30000 : 3000 : 300));
ui->offset->setMinimum((sensor.prec > 0 ? sensor.prec == 2 ? -30000 : -3000 : -300));
if (sensor.unit == SensorData::UNIT_RPMS) {
ui->offset->setDecimals(0);
ui->ratio->setDecimals(0);
ui->autoOffset->hide();
ui->ratio->setMinimum(1);
ui->offset->setMinimum(1);
}
else {
ui->offset->setDecimals(sensor.prec);
ui->ratio->setDecimals(1);
}
} }
ui->ratioLabel->setVisible(ratioFieldsDisplayed); ui->ratioLabel->setVisible(ratioFieldsDisplayed && sensor.unit != SensorData::UNIT_RPMS);
ui->bladesLabel->setVisible(sensor.unit == SensorData::UNIT_RPMS);
ui->ratio->setVisible(ratioFieldsDisplayed); ui->ratio->setVisible(ratioFieldsDisplayed);
ui->offsetLabel->setVisible(ratioFieldsDisplayed); ui->offsetLabel->setVisible(ratioFieldsDisplayed && sensor.unit != SensorData::UNIT_RPMS);
ui->multiplierLabel->setVisible(sensor.unit == SensorData::UNIT_RPMS);
ui->offset->setVisible(ratioFieldsDisplayed); ui->offset->setVisible(ratioFieldsDisplayed);
ui->precLabel->setVisible(precDisplayed); ui->precLabel->setVisible(precDisplayed);
ui->prec->setVisible(precDisplayed); ui->prec->setVisible(precDisplayed);

View file

@ -13,7 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -506,6 +506,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="bladesLabel">
<property name="text">
<string>Blades</string>
</property>
</widget>
</item>
<item> <item>
<widget class="AutoDoubleSpinBox" name="ratio"> <widget class="AutoDoubleSpinBox" name="ratio">
<property name="enabled"> <property name="enabled">
@ -518,7 +525,10 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="decimals"> <property name="decimals">
<number>1</number> <number>0</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property> </property>
<property name="maximum"> <property name="maximum">
<double>3000.000000000000000</double> <double>3000.000000000000000</double>
@ -538,6 +548,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="multiplierLabel">
<property name="text">
<string>Multiplier</string>
</property>
</widget>
</item>
<item> <item>
<widget class="AutoDoubleSpinBox" name="offset"> <widget class="AutoDoubleSpinBox" name="offset">
<property name="sizePolicy"> <property name="sizePolicy">
@ -547,16 +564,16 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="decimals"> <property name="decimals">
<number>2</number> <number>0</number>
</property> </property>
<property name="minimum"> <property name="minimum">
<double>-12.800000000000001</double> <double>-30000.000000000000000</double>
</property> </property>
<property name="maximum"> <property name="maximum">
<double>12.699999999999999</double> <double>30000.000000000000000</double>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<double>0.100000000000000</double> <double>1.000000000000000</double>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -205,10 +205,10 @@ bool isSensorAvailable(int sensor)
#define SENSOR_UNIT_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_UNIT_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
#define SENSOR_PREC_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_PREC_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
#define SENSOR_PARAM1_ROWS (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0) #define SENSOR_PARAM1_ROWS (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0)
#define SENSOR_PARAM2_ROWS (sensor->unit == UNIT_RPMS || 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) #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)
#define SENSOR_PARAM3_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW #define SENSOR_PARAM3_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
#define SENSOR_PARAM4_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW #define SENSOR_PARAM4_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
#define SENSOR_AUTOOFFSET_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_AUTOOFFSET_ROWS (sensor->unit != UNIT_RPMS && sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
#define SENSOR_FILTER_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_FILTER_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
#define SENSOR_PERSISTENT_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW) #define SENSOR_PERSISTENT_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
@ -377,6 +377,12 @@ void menuModelSensor(uint8_t event)
break; break;
} }
} }
else if (sensor->unit == UNIT_RPMS) {
lcd_putsLeft(y, STR_MULTIPLIER);
if (attr) CHECK_INCDEC_MODELVAR(event, sensor->custom.offset, 1, 30000);
lcd_outdezAtt(SENSOR_2ND_COLUMN, y, sensor->custom.offset, LEFT|attr);
break;
}
else { else {
lcd_putsLeft(y, NO_INDENT(STR_OFFSET)); lcd_putsLeft(y, NO_INDENT(STR_OFFSET));
if (attr) CHECK_INCDEC_MODELVAR(event, sensor->custom.offset, -30000, +30000); if (attr) CHECK_INCDEC_MODELVAR(event, sensor->custom.offset, -30000, +30000);

View file

@ -259,6 +259,7 @@ void frskySportSetDefault(int index, uint16_t id, uint8_t instance)
} }
if (unit == UNIT_RPMS) { if (unit == UNIT_RPMS) {
telemetrySensor.custom.ratio = 1; telemetrySensor.custom.ratio = 1;
telemetrySensor.custom.offset = 1;
} }
} }
else { else {

View file

@ -172,7 +172,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32
newVal = 0; newVal = 0;
} }
else if (unit == UNIT_RPMS) { else if (unit == UNIT_RPMS) {
newVal = newVal / sensor.custom.ratio; newVal = (newVal * sensor.custom.offset) / sensor.custom.ratio;
} }
else { else {
newVal = sensor.getValue(newVal, unit, prec); newVal = sensor.getValue(newVal, unit, prec);