diff --git a/bc.h b/bc.h index ad3fff0..a31259b 100644 --- a/bc.h +++ b/bc.h @@ -712,10 +712,7 @@ public: Motor_Assist_Regen_Inflex = 0xd2, // Speed From Which Regen Is Not Attenuated [Unit:Rpm, Range:5..?, Factor:9.091] Motor_Assist_Maxspeed_Derate_Delta = 0xd3, // Speed Before Maxspeed To Start Derating [Unit:Rpm, Factor:9.091] - //{%Endregion} - - - //{%Region Sensor} + ID_Sensor = 0x68, Reg_Sensor_Config_Gauge_Gain_Hi = 0x10, Reg_Sensor_Config_Gauge_Gain_Lo = 0x11, diff --git a/bcdatamanager.cpp b/bcdatamanager.cpp index 08a62d8..a01f4ba 100644 --- a/bcdatamanager.cpp +++ b/bcdatamanager.cpp @@ -107,7 +107,7 @@ void BCDataManager::loadXmlBikeData( const QString& fileName ) printAttrs (_xml); // Wir wollen die Device-ID aus dem XML Tag ermitteln const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData(); - auto optDeviceID = _bcDeviceEnum.keyToValue64(deviceKey); + auto optDeviceID = _bcDeviceEnum.keysToValue64(deviceKey); //_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) ); if( optDeviceID.has_value()) { @@ -204,41 +204,6 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, cons static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; - static BCValueTypeMap s_bcDataTypes - { - { "Byte", new BCValueTypeWord( "", 1.5625F) }, - { "Word", new BCValueTypeWord( "", 1.5625F) }, - - { "Float", new BCValueTypeWord( "", 1.5625F) }, - { "Percent",new BCValueTypeWord( "%", 1.5625 ) }, - { "KWh", new BCValueTypeWord( "kwh", 1.5625 ) }, - { "Watt", new BCValueTypeWord( "w", 1.5625 ) }, - { "Km", new BCValueTypeWord( "km", 1.5625 ) }, - { "Kmh", new BCValueTypeWord( "km/h", 0.1 ) }, - { "Mm", new BCValueTypeWord( "mm", 1.5625 ) }, - { "Sec", new BCValueTypeWord( "s", 1.5625 ) }, - { "SoC", new BCValueTypeWord( "%", 1.5625 ) }, - { "Odo", new BCValueTypeWord( "km", 1.5625 ) }, - { "Assist", new BCValueTypeWord( "", 0 ,4 ) }, - { "Assist", new BCValueTypeWord( "%" ) }, - }; - - - /* - _dataTypes.insert( "Float", new Fitz{{ "", 1.5625F}} ); - _dataTypes.insert( "Percent",new Fatz{{ "%", 1.5625 }} ); - _dataTypes.insert( "KWh", new Fatz{{ "kwh", 1.5625 }} ); - _dataTypes.insert( "Watt", new Long{{ "w", 1.5625 }} ); - _dataTypes.insert( "Km", new BCValueTypeWord{{ "km", 1.5625 }} ); - _dataTypes.insert( "Kmh", new BCValueTypeWord{{ "km/h", 0.1 }} ); - _dataTypes.insert( "Mm", new BCValueTypeWord{{ "mm", 1.5625 }} ); - _dataTypes.insert( "Sec", new BCValueTypeWord{{ "s", 1.5625 }} ); - _dataTypes.insert( "SoC", new Long{{ "%", 1.5625 }} ); - _dataTypes.insert( "Odo", new Fitz{{ "km", 1.5625 }} ); - _dataTypes.insert( "Assist", new Fatz{{ "", 0 ,4 }} ); - _dataTypes.insert( "Assist", new Fatz{{ "%" }} ); - //_dataTypes.insert( "Date", { BCValueType::TypeID::Date } ); - */ /* Wir brauchen: @@ -249,16 +214,14 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, cons std::optional newValue; - std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); + std::optional IDVal = s_bcValueEnum.keysToValue64( params.ID.toLatin1().constData() ); qDebug() << " --- should create: " << params.Label << ": " << params.UnitType; if( IDVal.has_value() ) { - - if( s_bcDataTypes.contains( params.UnitType ) ) + auto valueType = BCValueType::fetchValueType(params.UnitType); + if( valueType.has_value() ) { - - const BCValueType* valueType = s_bcDataTypes[params.UnitType]; - newValue = BCValue( valueType, deviceID, static_cast(IDVal.value()) ); + newValue = BCValue( *valueType, deviceID, static_cast(IDVal.value()) ); /* setIfExists( params.Factor, newValue.factor ); @@ -269,7 +232,6 @@ std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, cons newValue->defaultValue = params.Default; qDebug() << " --- created: " << params.Label; - } } diff --git a/bcdatamanager.h b/bcdatamanager.h index b029c18..c06ecde 100644 --- a/bcdatamanager.h +++ b/bcdatamanager.h @@ -79,8 +79,6 @@ protected: std::optional makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); - using BCValueTypeMap = QHash; - QXmlStreamReader _xml; QMetaEnum _bcDeviceEnum{QMetaEnum::fromType()}; diff --git a/bcvaluetype.cpp b/bcvaluetype.cpp index 2494acc..759b739 100644 --- a/bcvaluetype.cpp +++ b/bcvaluetype.cpp @@ -53,6 +53,51 @@ QString BCValueType::formatValue( uint32_t value ) const double result = value * factor; return QString::number(result, 'f', 2); } + +/* + _dataTypes.insert( "Float", new Fitz{{ "", 1.5625F}} ); + _dataTypes.insert( "Percent",new Fatz{{ "%", 1.5625 }} ); + _dataTypes.insert( "KWh", new Fatz{{ "kwh", 1.5625 }} ); + _dataTypes.insert( "Watt", new Long{{ "w", 1.5625 }} ); + _dataTypes.insert( "Km", new BCValueTypeWord{{ "km", 1.5625 }} ); + _dataTypes.insert( "Kmh", new BCValueTypeWord{{ "km/h", 0.1 }} ); + _dataTypes.insert( "Mm", new BCValueTypeWord{{ "mm", 1.5625 }} ); + _dataTypes.insert( "Sec", new BCValueTypeWord{{ "s", 1.5625 }} ); + _dataTypes.insert( "SoC", new Long{{ "%", 1.5625 }} ); + _dataTypes.insert( "Odo", new Fitz{{ "km", 1.5625 }} ); + _dataTypes.insert( "Assist", new Fatz{{ "", 0 ,4 }} ); + _dataTypes.insert( "Assist", new Fatz{{ "%" }} ); + //_dataTypes.insert( "Date", { BCValueType::TypeID::Date } ); + */ +std::optional BCValueType::fetchValueType( const QString& unitTypeKey ) +{ + static QHash s_bcDataTypes + { + { "Byte", new BCValueTypeWord( "", 1.5625F) }, + { "Word", new BCValueTypeWord( "", 1.5625F) }, + + { "Float", new BCValueTypeWord( "", 1.5625F) }, + { "Percent",new BCValueTypeWord( "%", 1.5625 ) }, + { "KWh", new BCValueTypeWord( "kwh", 1.5625 ) }, + { "Watt", new BCValueTypeWord( "w", 1.5625 ) }, + { "Km", new BCValueTypeWord( "km", 1.5625 ) }, + { "Kmh", new BCValueTypeWord( "km/h", 0.1 ) }, + { "Mm", new BCValueTypeWord( "mm", 1.5625 ) }, + { "Sec", new BCValueTypeWord( "s", 1.5625 ) }, + { "Degree", new BCValueTypeByte( "°C", 1.0 ) }, + { "SoC", new BCValueTypeWord( "%", 1.5625 ) }, + { "Odo", new BCValueTypeWord( "km", 1.5625 ) }, + { "Assist", new BCValueTypeWord( "", 0 ,4 ) }, + { "Assist", new BCValueTypeWord( "%" ) }, + }; + + if( !s_bcDataTypes.contains( unitTypeKey ) ) + return std::nullopt; + + return s_bcDataTypes[unitTypeKey]; + +} + /// ---- BCValueTypeByte::BCValueTypeByte( QString unitLabel_, double factor_, optDouble min_, optDouble max_ ) diff --git a/bcvaluetype.h b/bcvaluetype.h index ca65a12..b7ba5d3 100644 --- a/bcvaluetype.h +++ b/bcvaluetype.h @@ -65,6 +65,7 @@ public: virtual QString formatValue( uint32_t value ) const; + static std::optional fetchValueType( const QString& unitTypeKey ); }; diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index 202cade..e43fdac 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -29,12 +29,24 @@ + + + + + + + + + + + + + + + - - - - +