Sensor ui refactoring
This commit is contained in:
@@ -30,6 +30,7 @@ string(REPLACE ".cpp" ".h" firmwares_HDRS "${firmwares_SRCS}")
|
||||
list(APPEND firmwares_HDRS
|
||||
eepromimportexport.h
|
||||
moduledata.h
|
||||
helpersdata.h
|
||||
)
|
||||
|
||||
set(firmwares_QT
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _HELPERS_DATA_H_
|
||||
#define _HELPERS_DATA_H_
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class FieldRange
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FieldRange)
|
||||
|
||||
public:
|
||||
FieldRange():
|
||||
decimals(0),
|
||||
min(0.0),
|
||||
max(0.0),
|
||||
step(1.0),
|
||||
offset(0.0),
|
||||
prefix(""),
|
||||
unit("")
|
||||
{
|
||||
}
|
||||
|
||||
float getValue(int value) { return float(value) * step; }
|
||||
|
||||
int decimals;
|
||||
double min;
|
||||
double max;
|
||||
double step;
|
||||
double offset;
|
||||
QString prefix;
|
||||
QString unit;
|
||||
};
|
||||
|
||||
#endif // _HELPERS_DATA_H_
|
||||
@@ -57,17 +57,65 @@ bool SensorData::isEmpty() const
|
||||
return (!isAvailable() && type == 0 && id == 0 && subid == 0 && instance == 0 && rxIdx == 0 && moduleIdx == 0 && unit == 0 && ratio == 0 && prec == 0 && offset == 0 && autoOffset == 0 && filter == 0 && onlyPositive == 0 && logs == 0);
|
||||
}
|
||||
|
||||
constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 };
|
||||
constexpr int SENSOR_PRINT_GPS { 1 << 2 };
|
||||
constexpr int SENSOR_PRINT_CELLS { 1 << 3 };
|
||||
constexpr int SENSOR_PRINT_CONSUMPTION { 1 << 4 };
|
||||
constexpr int SENSOR_PRINT_RATIO { 1 << 5 };
|
||||
constexpr int SENSOR_PRINT_TOTALIZE { 1 << 6 };
|
||||
constexpr int SENSOR_PRINT_SOURCES_12 { 1 << 7 };
|
||||
constexpr int SENSOR_PRINT_SOURCES_34 { 1 << 8 };
|
||||
constexpr char FMT_LABEL[] { "<b>%1:</b> " };
|
||||
constexpr char FMT_VALUE[] { "%1 " };
|
||||
constexpr char FMT_LABEL_VALUE[] { "<b>%1:</b> %2 " };
|
||||
QString SensorData::typeToString() const
|
||||
{
|
||||
return typeToString(type);
|
||||
}
|
||||
|
||||
QString SensorData::formulaToString() const
|
||||
{
|
||||
return formulaToString(formula);
|
||||
}
|
||||
|
||||
QString SensorData::cellIndexToString() const
|
||||
{
|
||||
return cellIndexToString(index);
|
||||
}
|
||||
|
||||
QString SensorData::unitToString() const
|
||||
{
|
||||
return unitToString(unit);
|
||||
}
|
||||
|
||||
QString SensorData::precToString() const
|
||||
{
|
||||
return precToString(prec);
|
||||
}
|
||||
|
||||
int SensorData::getMask() const
|
||||
{
|
||||
int mask = 0;
|
||||
|
||||
if (type == TELEM_TYPE_CALCULATED) {
|
||||
if (formula < TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_ISCONFIGURABLE | SENSOR_HAS_POSITIVE;
|
||||
if (formula == TELEM_FORMULA_DIST)
|
||||
mask |= SENSOR_HAS_GPS;
|
||||
if (formula == TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_HAS_CELLS;
|
||||
if (formula == TELEM_FORMULA_CONSUMPTION)
|
||||
mask |= SENSOR_HAS_CONSUMPTION;
|
||||
if (formula <= TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_HAS_SOURCES_12;
|
||||
if (formula < TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_HAS_SOURCES_34;
|
||||
if (formula == TELEM_FORMULA_TOTALIZE)
|
||||
mask |= SENSOR_HAS_TOTALIZE;
|
||||
}
|
||||
else {
|
||||
if (unit < UNIT_FIRST_VIRTUAL)
|
||||
mask |= (SENSOR_ISCONFIGURABLE | SENSOR_HAS_RATIO | SENSOR_HAS_POSITIVE);
|
||||
}
|
||||
|
||||
if (mask & SENSOR_ISCONFIGURABLE && unit != UNIT_FAHRENHEIT)
|
||||
mask |= SENSOR_HAS_PRECISION;
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
constexpr char FMT_LABEL[] { "<b>%1:</b> " };
|
||||
constexpr char FMT_VALUE[] { "%1 " };
|
||||
constexpr char FMT_LABEL_VALUE[] { "<b>%1:</b> %2 " };
|
||||
|
||||
QString SensorData::paramsToString(const ModelData * model) const
|
||||
{
|
||||
@@ -75,62 +123,45 @@ QString SensorData::paramsToString(const ModelData * model) const
|
||||
return "";
|
||||
|
||||
QString str;
|
||||
int mask = 0;
|
||||
int mask = getMask();
|
||||
|
||||
if (type == TELEM_TYPE_CALCULATED) {
|
||||
if (formula < TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_ISCONFIGURABLE;
|
||||
if (formula == TELEM_FORMULA_DIST)
|
||||
mask |= SENSOR_PRINT_GPS;
|
||||
if (formula == TELEM_FORMULA_CELL)
|
||||
mask |= SENSOR_PRINT_CELLS;
|
||||
if (formula == TELEM_FORMULA_CONSUMPTION)
|
||||
mask |= SENSOR_PRINT_CONSUMPTION;
|
||||
if (formula <= TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_PRINT_SOURCES_12;
|
||||
if (formula < TELEM_FORMULA_MULTIPLY)
|
||||
mask |= SENSOR_PRINT_SOURCES_34;
|
||||
if (formula == TELEM_FORMULA_TOTALIZE)
|
||||
mask |= SENSOR_PRINT_TOTALIZE;
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Formula")).arg(formulaToString(formula)));
|
||||
}
|
||||
else {
|
||||
if (unit < UNIT_FIRST_VIRTUAL)
|
||||
mask |= (SENSOR_ISCONFIGURABLE | SENSOR_PRINT_RATIO);
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Id")).arg(QString::number(id, 16).toUpper()));
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Instance")).arg(instance));
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_CELLS) {
|
||||
if (mask & SENSOR_HAS_CELLS) {
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Sensor")).arg(sourceToString(model, source)));
|
||||
str.append(QString(FMT_VALUE).arg(cellIndexToString(index)));
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_SOURCES_12) {
|
||||
if (mask & SENSOR_HAS_SOURCES_12) {
|
||||
str.append(QString(FMT_LABEL).arg(tr("Sources")));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < 2 || mask & SENSOR_PRINT_SOURCES_34) {
|
||||
if (i < 2 || mask & SENSOR_HAS_SOURCES_34) {
|
||||
str.append(QString(FMT_VALUE).arg(sourceToString(model, sources[i])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mask & SENSOR_PRINT_CONSUMPTION || mask & SENSOR_PRINT_TOTALIZE)
|
||||
if (mask & SENSOR_HAS_CONSUMPTION || mask & SENSOR_HAS_TOTALIZE)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Sensor")).arg(sourceToString(model, amps)));
|
||||
|
||||
if (mask & SENSOR_PRINT_GPS) {
|
||||
if (mask & SENSOR_HAS_GPS) {
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("GPS")).arg(sourceToString(model, gps)));
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Alt")).arg(sourceToString(model, alt)));
|
||||
}
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Unit")).arg(unitToString(unit)));
|
||||
if (mask & SENSOR_ISCONFIGURABLE)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Unit")).arg(unitToString(unit)));
|
||||
|
||||
if (mask & SENSOR_ISCONFIGURABLE && unit != UNIT_FAHRENHEIT)
|
||||
if (mask & SENSOR_HAS_PRECISION)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Precision")).arg(precToString(prec)));
|
||||
|
||||
if (mask & SENSOR_PRINT_RATIO) {
|
||||
if (mask & SENSOR_HAS_RATIO) {
|
||||
if (unit != UNIT_RPMS) {
|
||||
int precsn = prec == 0 ? 1 : pow(10, prec);
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Ratio")).arg((float)ratio / 10));
|
||||
@@ -149,12 +180,78 @@ QString SensorData::paramsToString(const ModelData * model) const
|
||||
if (type == TELEM_TYPE_CALCULATED)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Persist")).arg(boolToString(persistent)));
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Positive")).arg(boolToString(onlyPositive)));
|
||||
if (mask & SENSOR_HAS_POSITIVE)
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Positive")).arg(boolToString(onlyPositive)));
|
||||
|
||||
str.append(QString(FMT_LABEL_VALUE).arg(tr("Log")).arg(boolToString(logs)));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
FieldRange SensorData::getRatioRange() const
|
||||
{
|
||||
FieldRange result;
|
||||
|
||||
if (unit == SensorData::UNIT_RPMS) {
|
||||
result.decimals = 0;
|
||||
result.max = 30000;
|
||||
result.min = 1;
|
||||
result.step = 1;
|
||||
}
|
||||
else {
|
||||
result.decimals = 1;
|
||||
result.max = 30000;
|
||||
result.min = 0;
|
||||
result.step = 0.1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FieldRange SensorData::getOffsetRange() const
|
||||
{
|
||||
FieldRange result;
|
||||
|
||||
if (unit == SensorData::UNIT_RPMS) {
|
||||
result.decimals = 0;
|
||||
result.max = 30000;
|
||||
result.min = 1;
|
||||
result.step = 1;
|
||||
}
|
||||
else {
|
||||
result.decimals = prec;
|
||||
result.max = 30000.0f / powf(10.0f, prec);
|
||||
result.min = -result.max;
|
||||
result.step = pow(0.1, prec);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SensorData::formulaChanged()
|
||||
{
|
||||
switch (formula) {
|
||||
case TELEM_FORMULA_CELL:
|
||||
prec = 2;
|
||||
unit = UNIT_VOLTS;
|
||||
break;
|
||||
case TELEM_FORMULA_CONSUMPTION:
|
||||
prec = 0;
|
||||
unit = UNIT_MAH;
|
||||
break;
|
||||
case TELEM_FORMULA_DIST:
|
||||
prec = 0;
|
||||
unit = UNIT_METERS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SensorData::unitChanged()
|
||||
{
|
||||
if (unit == UNIT_FAHRENHEIT)
|
||||
prec = 0;
|
||||
}
|
||||
|
||||
// static
|
||||
QString SensorData::typeToString(const int value)
|
||||
{
|
||||
|
||||
@@ -21,16 +21,30 @@
|
||||
#ifndef SENSORDATA_H
|
||||
#define SENSORDATA_H
|
||||
|
||||
#include "helpersdata.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
constexpr int CPN_MAX_SENSORS = 60;
|
||||
constexpr int SENSOR_LABEL_LEN = 4;
|
||||
constexpr int CPN_MAX_SENSORS { 60 };
|
||||
constexpr int SENSOR_LABEL_LEN { 4 };
|
||||
|
||||
constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 };
|
||||
constexpr int SENSOR_HAS_GPS { 1 << 2 };
|
||||
constexpr int SENSOR_HAS_CELLS { 1 << 3 };
|
||||
constexpr int SENSOR_HAS_CONSUMPTION { 1 << 4 };
|
||||
constexpr int SENSOR_HAS_RATIO { 1 << 5 };
|
||||
constexpr int SENSOR_HAS_TOTALIZE { 1 << 6 };
|
||||
constexpr int SENSOR_HAS_SOURCES_12 { 1 << 7 };
|
||||
constexpr int SENSOR_HAS_SOURCES_34 { 1 << 8 };
|
||||
constexpr int SENSOR_HAS_POSITIVE { 1 << 9 };
|
||||
constexpr int SENSOR_HAS_PRECISION { 1 << 10 };
|
||||
|
||||
class ModelData;
|
||||
class AbstractStaticItemModel;
|
||||
class PrecisionItemModel;
|
||||
|
||||
class SensorData {
|
||||
|
||||
Q_DECLARE_TR_FUNCTIONS(SensorData)
|
||||
|
||||
public:
|
||||
@@ -171,7 +185,17 @@ class SensorData {
|
||||
QString getOrigin(const ModelData* model) const;
|
||||
void clear() { memset(this, 0, sizeof(SensorData)); }
|
||||
bool isEmpty() const;
|
||||
QString typeToString() const;
|
||||
QString formulaToString() const;
|
||||
QString cellIndexToString() const;
|
||||
QString unitToString() const;
|
||||
QString precToString() const;
|
||||
int getMask() const;
|
||||
QString paramsToString(const ModelData * model) const;
|
||||
FieldRange getRatioRange() const;
|
||||
FieldRange getOffsetRange() const;
|
||||
void formulaChanged();
|
||||
void unitChanged();
|
||||
|
||||
static QString sourceToString(const ModelData * model, const int index, const bool sign = false);
|
||||
static bool isSourceAvailable(const ModelData * model, const int index);
|
||||
|
||||
Reference in New Issue
Block a user