From f8c6b20a35345706b801dbc13fdff5e96e553e88 Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 2 Jan 2017 11:32:54 +0100 Subject: [PATCH] Add missing units (#4181) * Add missing units * Add import shift --- companion/src/eeprominterface.cpp | 14 ++++--- companion/src/eeprominterface.h | 40 ++++++++++--------- .../src/firmwares/opentx/opentxeeprom.cpp | 10 +++++ companion/src/modeledit/telemetry_sensor.ui | 10 +++++ 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 7165baa57..c308dafff 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -193,6 +193,8 @@ QString SensorData::unitString() const return QObject::tr("mAh"); case UNIT_WATTS: return QObject::tr("W"); + case UNIT_MILLIWATTS: + return QObject::tr("mW"); case UNIT_DB: return QObject::tr("dB"); case UNIT_RPMS: @@ -201,6 +203,8 @@ QString SensorData::unitString() const return QObject::tr("g"); case UNIT_DEGREE: return QObject::trUtf8("°"); + case UNIT_RADIANS: + return QObject::trUtf8("Rad"); case UNIT_HOURS: return QObject::tr("hours"); case UNIT_MINUTES: @@ -1061,11 +1065,11 @@ GeneralSettings::GeneralSettings() calibSpanNeg[i] = 0x180; calibSpanPos[i] = 0x180; } - + for (int i=0; igetCapability(Switches); i++) { switchConfig[i] = GetCurrentFirmware()->getSwitch(i).type; } - + BoardEnum board = GetEepromInterface()->getBoard(); if (board == BOARD_HORUS) { potConfig[0] = POT_WITH_DETENT; @@ -1194,7 +1198,7 @@ GeneralSettings::GeneralSettings() } } } - + strcpy(themeName, "default"); ThemeOptionData option1 = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0 }; memcpy(&themeOptionValue[0], option1, sizeof(ThemeOptionData)); @@ -1719,7 +1723,7 @@ QString getBoardName(BoardEnum board) case BOARD_TARANIS_X9DP: return "Taranis X9D+"; case BOARD_TARANIS_X9E: - return "Taranis X9E"; + return "Taranis X9E"; case BOARD_SKY9X: return "Sky9x"; case BOARD_9XRPRO: @@ -1727,7 +1731,7 @@ QString getBoardName(BoardEnum board) case BOARD_AR9X: return "AR9X"; case BOARD_HORUS: - return "Horus"; + return "Horus"; default: return "Unknown"; } diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index b9ea0cb2e..3e9088a2f 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -971,10 +971,12 @@ class SensorData { UNIT_PERCENT, UNIT_MAH, UNIT_WATTS, + UNIT_MILLIWATTS, UNIT_DB, UNIT_RPMS, UNIT_G, UNIT_DEGREE, + UNIT_RADIANS, UNIT_MILLILITERS, UNIT_FLOZ, UNIT_HOURS, @@ -1041,7 +1043,7 @@ class SensorData { #if 0 class CustomScreenOptionData { public: - + }; class CustomScreenZoneData { @@ -1053,7 +1055,7 @@ class CustomScreenZoneData { class CustomScreenData { public: CustomScreenData(); - + char layoutName[10+1]; CustomScreenZoneData zones[]; CustomScreenOptionData options[]; @@ -1131,11 +1133,11 @@ class ModelData { SensorData sensorData[CPN_MAX_SENSORS]; unsigned int toplcdTimer; - + CustomScreenData customScreenData[5]; - + TopbarData topbarData; - + void clear(); bool isEmpty() const; void setDefaultInputs(const GeneralSettings & settings); @@ -1303,7 +1305,7 @@ class GeneralSettings { char themeName[8+1]; typedef uint8_t ThemeOptionData[8+1]; ThemeOptionData themeOptionValue[5]; - + struct SwitchInfo { SwitchInfo(unsigned int index, unsigned int position): index(index), @@ -1325,13 +1327,13 @@ class RadioData { public: GeneralSettings generalSettings; ModelData models[CPN_MAX_MODELS]; - + void setCurrentModel(unsigned int index) { generalSettings.currModelIndex = index; strcpy(generalSettings.currModelFilename, models[index].filename); } - + QString getNextModelFilename() { char filename[sizeof(ModelData::filename)]; @@ -1479,7 +1481,7 @@ class EEPROMInterface virtual unsigned long load(RadioData &radioData, const uint8_t * eeprom, int size) = 0; virtual unsigned long loadBackup(RadioData & radioData, const uint8_t * eeprom, int esize, int index) = 0; - + virtual unsigned long loadxml(RadioData & radioData, QDomDocument &doc) = 0; virtual int save(uint8_t * eeprom, RadioData & radioData, uint8_t version=0, uint32_t variant=0) = 0; @@ -1491,11 +1493,11 @@ class EEPROMInterface virtual const int getEEpromSize() = 0; virtual const int getMaxModels() = 0; - + virtual int loadFile(RadioData & radioData, const QString & filename) = 0; - + virtual int saveFile(const RadioData & radioData, const QString & filename) = 0; - + protected: BoardEnum board; @@ -1638,7 +1640,7 @@ struct Option { }; class Firmware { - + public: Firmware(const QString & id, const QString & name, const BoardEnum board, EEPROMInterface * eepromInterface): id(id), @@ -1720,29 +1722,29 @@ class Firmware { } virtual int getCapability(Capability) = 0; - + enum SwitchType { SWITCH_NONE, SWITCH_TOGGLE, SWITCH_2POS, SWITCH_3POS }; - + struct Switch { SwitchType type; const char * name; }; - + virtual Switch getSwitch(unsigned int index) = 0; - + virtual QString getAnalogInputName(unsigned int index) = 0; - + virtual QTime getMaxTimerStart() = 0; virtual bool isTelemetrySourceAvailable(int source) = 0; virtual int isAvailable(PulsesProtocol proto, int port=0) = 0; - + const int getFlashSize(); public: diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 4d05121c1..095b86f75 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -2935,6 +2935,7 @@ class SensorField: public TransformedField { TransformedField(internalField), internalField("Sensor"), sensor(sensor), + version(version), _param(0) { internalField.Append(new UnsignedField<16>(_id, "id/persistentValue")); @@ -2997,12 +2998,21 @@ class SensorField: public TransformedField { else if (sensor.formula == SensorData::TELEM_FORMULA_CONSUMPTION || sensor.formula == SensorData::TELEM_FORMULA_TOTALIZE) sensor.amps = _sources[0]; } + + if (version < 218) { + if (sensor.unit > SensorData::UNIT_WATTS) + sensor.unit++; + if (sensor.unit > SensorData::UNIT_DEGREE) + sensor.unit++; + } + eepromImportDebug() << QString("imported %1").arg(internalField.getName()); } protected: StructField internalField; SensorData & sensor; + unsigned int version; unsigned int _id; unsigned int _subid; unsigned int _instance; diff --git a/companion/src/modeledit/telemetry_sensor.ui b/companion/src/modeledit/telemetry_sensor.ui index 046aeb3eb..9966bc8ee 100644 --- a/companion/src/modeledit/telemetry_sensor.ui +++ b/companion/src/modeledit/telemetry_sensor.ui @@ -439,6 +439,11 @@ W + + + mW + + dBm @@ -459,6 +464,11 @@ ° + + + Rad + + mL