117 lines
2.6 KiB
C++
117 lines
2.6 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);
|
|
}
|
|
|
|
void BCValue::setFromDouble( double value )
|
|
{
|
|
if( _optMin.has_value() && _optMax.has_value() )
|
|
{
|
|
|
|
double min = _optMin.value();
|
|
double max = _optMax.value();
|
|
|
|
value = qBound( min,value,max);
|
|
}
|
|
|
|
_rawValue = value / _factor;
|
|
|
|
|
|
}
|
|
|
|
double BCValue::calcMinMaxRatio() const
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
/// ----
|