Added BCValueType
This commit is contained in:
5
bc.h
5
bc.h
@@ -716,9 +716,6 @@ public:
|
||||
Reg_Sensor_Rev_Sub = 0x83 // Software Subversion
|
||||
|
||||
};
|
||||
//const
|
||||
// SECONDS_PER_DAY = SecsPerDay; //60 * 60 * 24;
|
||||
|
||||
Q_ENUM(ID)
|
||||
|
||||
}; // struct BionxID
|
||||
@@ -739,7 +736,7 @@ public:
|
||||
BIB = uint8_t( BC::ID::ID_Bib ),
|
||||
Sensor = uint8_t( BC::ID::ID_Sensor )
|
||||
};
|
||||
Q_ENUM(ID)
|
||||
Q_ENUM(ID)
|
||||
};
|
||||
|
||||
using namespace Qt::Literals::StringLiterals; // Für _L1
|
||||
|
||||
38
bcvalue.cpp
38
bcvalue.cpp
@@ -47,41 +47,3 @@ uint8_t BCValue::getLongValue()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BCValue BCValue::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
|
||||
{
|
||||
|
||||
auto setIfExists = [&]( QStringView source, optDouble& target )
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
bool ok;
|
||||
double testVal = source.toDouble(&ok);
|
||||
if (ok)
|
||||
target = testVal;
|
||||
}
|
||||
};
|
||||
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
|
||||
/*
|
||||
Wir brauchen:
|
||||
- eine gültige ID
|
||||
|
||||
*/
|
||||
BCValue newValue{};
|
||||
|
||||
auto IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||
if( IDVal.has_value() )
|
||||
{
|
||||
newValue = BCValue( deviceID, BC::ID( IDVal.value() ) );
|
||||
setIfExists( params.Factor, newValue.factor );
|
||||
setIfExists( params.Min, newValue.min );
|
||||
setIfExists( params.Max, newValue.max );
|
||||
newValue.defaultValue.setValue( params.Label );
|
||||
newValue.value.setValue( params.Current );
|
||||
newValue.label = params.Label;
|
||||
}
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
101
bcvalue.h
101
bcvalue.h
@@ -28,39 +28,81 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef BCRawValue_H
|
||||
#define BCRawValue_H
|
||||
|
||||
#ifndef BCVALUE_H
|
||||
#define BCVALUE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
|
||||
#include <bc.h>
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Das ist natürlich annalog zu den ItemTypes:
|
||||
- ein Value hat einen ValueType, der bestimmt folgendes:
|
||||
- long or short
|
||||
- unit (mm, km/h, odo ... )
|
||||
-
|
||||
|
||||
|
||||
*/
|
||||
using optDouble = std::optional<double>;
|
||||
|
||||
struct BCValueParams
|
||||
struct BCValueType
|
||||
{
|
||||
QString ID;
|
||||
QString Label;
|
||||
QString Default;
|
||||
QString Current;
|
||||
QString Enabled;
|
||||
QString UnitType;
|
||||
QString Min;
|
||||
QString Max;
|
||||
QString Factor;
|
||||
};
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
|
||||
struct BCUnit
|
||||
{
|
||||
enum class ID
|
||||
enum class TypeID : uint8_t
|
||||
{
|
||||
|
||||
Invalid = 0x0,
|
||||
};
|
||||
Q_ENUM(TypeID)
|
||||
|
||||
enum class UnitID : uint8_t
|
||||
{
|
||||
Invalid = 0x0,
|
||||
Text,
|
||||
Number,
|
||||
Float,
|
||||
Percent,
|
||||
KWh,
|
||||
Km,
|
||||
Mm,
|
||||
Sec,
|
||||
SOC,
|
||||
Date
|
||||
};
|
||||
Q_ENUM(UnitID)
|
||||
|
||||
|
||||
static QString getUnitName( UnitID unitID)
|
||||
{
|
||||
static QMap<UnitID,QString> s_unitNames
|
||||
{
|
||||
{UnitID::Invalid, "" },
|
||||
{UnitID::Text, ""},
|
||||
{UnitID::Number, ""},
|
||||
{UnitID::Float, "" },
|
||||
{UnitID::Percent, "%"},
|
||||
{UnitID::KWh, "kWh" },
|
||||
{UnitID::Km, "km"},
|
||||
{UnitID::Mm, "mm"},
|
||||
{UnitID::Sec, "s"},
|
||||
{UnitID::SOC, "%"},
|
||||
{UnitID::Date, ""}
|
||||
};
|
||||
return s_unitNames[unitID];
|
||||
}
|
||||
|
||||
UnitID ID;
|
||||
optDouble min;
|
||||
optDouble max;
|
||||
optDouble factor;
|
||||
};
|
||||
|
||||
class BCValue
|
||||
@@ -79,19 +121,30 @@ public:
|
||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||
BC::ID targetID{BC::ID::Invalid};
|
||||
|
||||
optDouble min;
|
||||
optDouble max;
|
||||
optDouble factor;
|
||||
//BCValueType::ID typeID{BCValueType::ID::Invalid};
|
||||
BCValueType::TypeID firz;
|
||||
|
||||
QVariant defaultValue;
|
||||
QVariant value;
|
||||
|
||||
static BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params );
|
||||
|
||||
};
|
||||
// Damit QVariant dieses Struct transportieren kann:
|
||||
Q_DECLARE_METATYPE(BCValue)
|
||||
|
||||
|
||||
struct BCValueParams
|
||||
{
|
||||
QString ID;
|
||||
QString Label;
|
||||
QString Default;
|
||||
QString Current;
|
||||
QString Enabled;
|
||||
QString UnitType;
|
||||
QString Min;
|
||||
QString Max;
|
||||
QString Factor;
|
||||
};
|
||||
|
||||
// abbreviations:
|
||||
// SOC = State Of Charge
|
||||
// LMD = Last Measured Discharge
|
||||
@@ -111,4 +164,4 @@ constexpr auto to_u(E e) noexcept {
|
||||
using BCValueList = QVector<BCValue>;
|
||||
|
||||
|
||||
#endif // BCRawValue_H
|
||||
#endif // BCVALUE_H
|
||||
|
||||
@@ -181,7 +181,7 @@ void BCValueManager::readDevice( BCValueList& parsedValues )
|
||||
//BCValue newValue = BCValue::makeValue( _currentDeviceID, params );
|
||||
//if(newValue)
|
||||
// parsedValues.push_back( newValue );
|
||||
parsedValues.push_back( BCValue::makeValue( _currentDeviceID, params ) );
|
||||
parsedValues.push_back( makeValue( _currentDeviceID, params ) );
|
||||
}
|
||||
|
||||
//printAttrs (_xml);
|
||||
@@ -229,3 +229,45 @@ void BCValueManager::saveXml()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
BCValue BCValueManager::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
|
||||
{
|
||||
|
||||
auto setIfExists = [&]( QStringView source, optDouble& target )
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
bool ok;
|
||||
double testVal = source.toDouble(&ok);
|
||||
if (ok)
|
||||
target = testVal;
|
||||
}
|
||||
};
|
||||
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
|
||||
/*
|
||||
Wir brauchen:
|
||||
- eine gültige ID
|
||||
|
||||
*/
|
||||
BCValue newValue{};
|
||||
|
||||
auto IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||
if( IDVal.has_value() )
|
||||
{
|
||||
newValue = BCValue( deviceID, BC::ID( IDVal.value() ) );
|
||||
/*
|
||||
setIfExists( params.Factor, newValue.factor );
|
||||
setIfExists( params.Min, newValue.min );
|
||||
setIfExists( params.Max, newValue.max );
|
||||
*/
|
||||
newValue.defaultValue.setValue( params.Label );
|
||||
newValue.value.setValue( params.Current );
|
||||
newValue.label = params.Label;
|
||||
}
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
|
||||
std::optional<BCValueModel*> getModel(const QString& key );
|
||||
|
||||
BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params );
|
||||
|
||||
protected:
|
||||
|
||||
void readDevice( BCValueList& parsedValues );
|
||||
|
||||
Reference in New Issue
Block a user