Files
BionxControl/bcvalue.cpp
Christoph Holzheuer f19a33cc5f Debug updates.
2026-01-08 14:55:47 +01:00

103 lines
2.4 KiB
C++

/***************************************************************************
BionxControl
© 2025 -2026 christoph holzheuer
christoph.holzheuer@gmail.com
Using:
mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
Based on Bionx data type descriptions from:
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
#include <QMetaEnum>
#include <bcvalue.h>
///-------------------------------
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
: deviceID{deviceID_}, registerID{registerID_}
{
}
QString BCValue::formatValue() const
{
if( factor == 1 )
return QString::number( rawValue );
double result = rawValue * factor;
return QString::number(result, 'f', 2);
}
bool BCValue::isWord() const
{
return valueFlags.testFlag(BCValue::Flag::IsWord);
}
bool BCValue::isReadOnly() const
{
return valueFlags.testFlag(BCValue::Flag::ReadOnly);
}
double BCValue::calcRatio() const
{
return 0.33;
double ratio = 0;
if( optMin.has_value() && optMax.has_value() )
{
double min = optMin.value();
double max = optMax.value();
double range = max - min;
// Safety: Division durch Null verhindern (wenn min == max)
if (std::abs(range) < 1e-9)
return ratio;
// Die eigentliche Formel
ratio = ((rawValue - min) / range);
//ratio = (int) qBound( min,ratio, max);
}
return ratio;
}
void BCValue::dumpValue() const
{
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
qDebug();
}
/// ----