Added BCValueType

This commit is contained in:
2025-12-17 17:50:24 +01:00
parent 09ff2f00bb
commit 35112ba334
5 changed files with 123 additions and 67 deletions

View File

@@ -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;
}