Cosmetics and some commenting.

This commit is contained in:
2025-12-29 13:05:35 +01:00
parent 1a450e30ff
commit 527f66759f
9 changed files with 171 additions and 133 deletions

154
bc.h
View File

@@ -607,121 +607,121 @@ public:
Motor_Assist_Lowspeed_Ramp_Flag = 0x40, // Enables A Lower Speed Ramp. 0: Ramp Disabled, 1: Ramp Enabled
Motor_Assist_Direction = 0x42, // -
Motor_Sn_Stator_Type = 0x43, // -
Motor_Geometry_Circ_Hi = 0x44,
Motor_Geometry_Circ_Lo = 0x45,
Motor_Sn_Stator_Type = 0x43, // -
Motor_Geometry_Circ_Hi = 0x44,
Motor_Geometry_Circ_Lo = 0x45,
Motor_Torque_Gauge_Polarity = 0x46, // -
Motor_Torque_Gauge_Polarity = 0x46, // -
Motor_Status_Main = 0x47, // Indicates The Current Main Status Of The Motor. 0-Running, 1-Nocommand, 2-Startup, 3-I2cshutoff, 4-Antibackwardshort, 5-Alarmregen, 6-Alarmshort, 7-Overspeedi, 8-Overspeedv, 9-V12uvp, 10-V12ovp, 11-Vpwruvp, 12-Vpwrovp, 13-Ocprotect, 14-Badstatorpn, 15-Hallerror
Motor_Status_Main = 0x47, // Indicates The Current Main Status Of The Motor. 0-Running, 1-Nocommand, 2-Startup, 3-I2cshutoff, 4-Antibackwardshort, 5-Alarmregen, 6-Alarmshort, 7-Overspeedi, 8-Overspeedv, 9-V12uvp, 10-V12ovp, 11-Vpwruvp, 12-Vpwrovp, 13-Ocprotect, 14-Badstatorpn, 15-Hallerror
Motor_Sn_Item_Hi = 0x60, // Serial Number
Motor_Sn_Item_Lo = 0x61,
Motor_Sn_Pn_Hi = 0x62, // Partnumber
Motor_Sn_Pn_Lo = 0x63,
Motor_Sn_Year = 0x64, // Mfd. Year
Motor_Sn_Month = 0x65, // Mfd. Month
Motor_Sn_Day = 0x66, // Mfd. Day
Motor_Sn_Item_Hi = 0x60, // Serial Number
Motor_Sn_Item_Lo = 0x61,
Motor_Sn_Pn_Hi = 0x62, // Partnumber
Motor_Sn_Pn_Lo = 0x63,
Motor_Sn_Year = 0x64, // Mfd. Year
Motor_Sn_Month = 0x65, // Mfd. Month
Motor_Sn_Day = 0x66, // Mfd. Day
Motor_Sn_Oem_Hi = 0x67, // Oem
Motor_Sn_Oem_Lo = 0x68,
Motor_Sn_Product_Hi = 0x69, // Product
Motor_Sn_Product_Lo = 0x6a,
Motor_Sn_Location = 0x6b, // Location
Motor_Sn_Oem_Hi = 0x67, // Oem
Motor_Sn_Oem_Lo = 0x68,
Motor_Sn_Product_Hi = 0x69, // Product
Motor_Sn_Product_Lo = 0x6a,
Motor_Sn_Location = 0x6b, // Location
Motor_Torque_Gauge_Type = 0x6c, // -
Motor_Torque_Gauge_Type = 0x6c, // -
Motor_Assist_Stator_Pn_Hi = 0x6d, // -
Motor_Assist_Stator_Pn_Lo = 0x6e, //
Motor_Assist_Stator_Pn_Hi = 0x6d, // -
Motor_Assist_Stator_Pn_Lo = 0x6e, //
Motor_Status_Power_Voltage_Hi = 0x70, // - [Unit:V, Factor:0.001]
Motor_Status_Power_Voltage_Lo = 0x71,
Motor_Status_Power_Voltage_Hi = 0x70, // - [Unit:V, Factor:0.001]
Motor_Status_Power_Voltage_Lo = 0x71,
Motor_Status_12v_Voltage_Hi = 0x72, // - [Unit:V, Factor:0.001]
Motor_Status_12v_Voltage_Lo = 0x73,
Motor_Status_12v_Voltage_Hi = 0x72, // - [Unit:V, Factor:0.001]
Motor_Status_12v_Voltage_Lo = 0x73,
Motor_Status_5v_Voltage_Hi = 0x74, // - [Unit:V, Factor:0.001]
Motor_Status_5v_Voltage_Lo = 0x75,
Motor_Status_5v_Voltage_Hi = 0x74, // - [Unit:V, Factor:0.001]
Motor_Status_5v_Voltage_Lo = 0x75,
Motor_Stat_Max_Power_Voltage_Hi = 0x80, // - [Unit:V, Factor:0.001]
Motor_Stat_Max_Power_Voltage_Lo = 0x81,
Motor_Stat_Max_Power_Voltage_Hi = 0x80, // - [Unit:V, Factor:0.001]
Motor_Stat_Max_Power_Voltage_Lo = 0x81,
Motor_Stat_Max_Temperature_Hi = 0x82, // -
Motor_Stat_Max_Temperature_Lo = 0x83,
Motor_Stat_Max_Temperature_Hi = 0x82, // -
Motor_Stat_Max_Temperature_Lo = 0x83,
Motor_Stat_Odo_Hi = 0x84, // - [Unit:Km]
Motor_Stat_Odo_Lo = 0x85,
Motor_Stat_Odo_Hi = 0x84, // - [Unit:Km]
Motor_Stat_Odo_Lo = 0x85,
Motor_Stat_Chrono_Hours_Hi = 0x86, // - [Unit:H]
Motor_Stat_Chrono_Hours_Lo = 0x87,
Motor_Stat_Chrono_Hours_Hi = 0x86, // - [Unit:H]
Motor_Stat_Chrono_Hours_Lo = 0x87,
Motor_Stat_Chrono_Seconds_Hi = 0x88, // - [Unit:S]
Motor_Stat_Chrono_Seconds_Lo = 0x89,
Motor_Stat_Chrono_Seconds_Hi = 0x88, // - [Unit:S]
Motor_Stat_Chrono_Seconds_Lo = 0x89,
Motor_Preference_Region = 0x8a, // -
Motor_Preference_Region = 0x8a, // -
Motor_Assist_Maxspeed = 0x8b, // - [Unit:Km/H]
Motor_Assist_Dynamic_Flag = 0x8c, // - [Range:0..1]
Motor_Assist_Maxspeed = 0x8b, // - [Unit:Km/H]
Motor_Assist_Dynamic_Flag = 0x8c, // - [Range:0..1]
Motor_Config_Pwm_Limit_Enable = 0x8d, // -
Motor_Config_Pwm_Limit_Enable = 0x8d, // -
Motor_Status_Codes = 0x92, // Indicates Conditions Currently Detected By Motor. Bit 0-Sensor Saturation
Motor_Status_Codes_Latch = 0x93, // Indicates Conditions Detected By Motor Since Its Last Power Up. See Bit Description Of Status.Codes
Motor_Status_Codes = 0x92, // Indicates Conditions Currently Detected By Motor. Bit 0-Sensor Saturation
Motor_Status_Codes_Latch = 0x93, // Indicates Conditions Detected By Motor Since Its Last Power Up. See Bit Description Of Status.Codes
Motor_Protect_Unlock = 0xa5, // Unlock Register, Write Unlock_Key Here Before Setting Protected Registers
Motor_Protect_Unlock_Key = 0xaa,
Motor_Protect_Lock_Key = 0x00,
Motor_Protect_Unlock = 0xa5, // Unlock Register, Write Unlock_Key Here Before Setting Protected Registers
Motor_Protect_Unlock_Key = 0xaa,
Motor_Protect_Lock_Key = 0x00,
Motor_Stat_Hall_Dchs_Hi = 0xb0, // -
Motor_Stat_Hall_Dchs_Lo = 0xb1,
Motor_Stat_Hall_Dchs_Hi = 0xb0, // -
Motor_Stat_Hall_Dchs_Lo = 0xb1,
Motor_Stat_Hall_Trans_Hi = 0xb2, // -
Motor_Stat_Hall_Trans_Lo = 0xb3,
Motor_Stat_Hall_Trans_Hi = 0xb2, // -
Motor_Stat_Hall_Trans_Lo = 0xb3,
Motor_Stat_Hall_Ring_Hi = 0xb4, // -
Motor_Stat_Hall_Ring_Lo = 0xb5,
Motor_Stat_Hall_Ring_Hi = 0xb4, // -
Motor_Stat_Hall_Ring_Lo = 0xb5,
Motor_Stat_Hall_Lost_Hi = 0xb6, // -
Motor_Stat_Hall_Lost_Lo = 0xb7,
Motor_Stat_Hall_Lost_Hi = 0xb6, // -
Motor_Stat_Hall_Lost_Lo = 0xb7,
Motor_Torque_Gauge_Noise_Hi = 0xc4, // - [Unit:%, Range:0..100, Factor:0.0015259]
Motor_Torque_Gauge_Noise_Lo = 0xc5,
Motor_Torque_Gauge_Noise_Hi = 0xc4, // - [Unit:%, Range:0..100, Factor:0.0015259]
Motor_Torque_Gauge_Noise_Lo = 0xc5,
Motor_Torque_Gauge_Delay_Hi = 0xc6, // - [Unit:S, Range:0..?, Factor:0.001]
Motor_Torque_Gauge_Delay_Lo = 0xc7,
Motor_Torque_Gauge_Delay_Hi = 0xc6, // - [Unit:S, Range:0..?, Factor:0.001]
Motor_Torque_Gauge_Delay_Lo = 0xc7,
Motor_Torque_Gauge_Speed = 0xc8, // - [Unit:Rpm, Range:0..?, Factor:9.091]
Motor_Torque_Gauge_Speed = 0xc8, // - [Unit:Rpm, Range:0..?, Factor:9.091]
Motor_Torque_Gauge_Voltage_Hi = 0xc9, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
Motor_Torque_Gauge_Voltage_Lo = 0xca,
Motor_Torque_Gauge_Voltage_Hi = 0xc9, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
Motor_Torque_Gauge_Voltage_Lo = 0xca,
Motor_Torque_Gauge_Reference_Hi = 0xcb, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
Motor_Torque_Gauge_Reference_Lo = 0xcc,
Motor_Torque_Gauge_Reference_Hi = 0xcb, // - [Unit:V, Range:0..5, Factor:0.000076295, Offset:5]
Motor_Torque_Gauge_Reference_Lo = 0xcc,
Motor_Config_Communication_Mode_Hi = 0xcd, // Sets The Communication Mode. 0 For Can And 0xca01 For I2c
Motor_Config_Communication_Mode_Hi = 0xcd, // Sets The Communication Mode. 0 For Can And 0xca01 For I2c
Motor_Torque_Gauge_Gain = 0xce, // - [Unit:%, Range:0..398, Factor:1.5625]
Motor_Torque_Gauge_Gain = 0xce, // - [Unit:%, Range:0..398, Factor:1.5625]
Motor_Torque_Gauge_Max_Voltage = 0xe0, // Maximum Voltage Allowed For The Sensor. When The Sensor Detect A Voltage Over This Value For Motor.Torque.Gaugemaxvoltagedelay, It Assumes An Electrical Failure And Cuts Assistance [Unit:V, Range:0..5, Factor:0.019608]
Motor_Torque_Gauge_Max_Voltage_Delay = 0xe1, // Time After Which A Voltage Over Motor.Torque.Gaugemaxvoltage Is Assumed To Be An Electrical Failure, Cutting Assistance [Unit:S, Range:0..25.5, Factor:0.1]
Motor_Torque_Gauge_Max_Voltage = 0xe0, // Maximum Voltage Allowed For The Sensor. When The Sensor Detect A Voltage Over This Value For Motor.Torque.Gaugemaxvoltagedelay, It Assumes An Electrical Failure And Cuts Assistance [Unit:V, Range:0..5, Factor:0.019608]
Motor_Torque_Gauge_Max_Voltage_Delay = 0xe1, // Time After Which A Voltage Over Motor.Torque.Gaugemaxvoltage Is Assumed To Be An Electrical Failure, Cutting Assistance [Unit:S, Range:0..25.5, Factor:0.1]
Motor_Assist_Level_Offslope_Hi = 0xd0, // Speed At Which The Assist Level Set In The Motor Decreases When The Console Stops Sending Requests (When It Is Removed For Example) [Unit:%/S, Factor:3.05]
Motor_Assist_Level_Offslope_Lo = 0xd1,
Motor_Assist_Level_Offslope_Hi = 0xd0, // Speed At Which The Assist Level Set In The Motor Decreases When The Console Stops Sending Requests (When It Is Removed For Example) [Unit:%/S, Factor:3.05]
Motor_Assist_Level_Offslope_Lo = 0xd1,
Motor_Assist_Regen_Inflex = 0xd2, // Speed From Which Regen Is Not Attenuated [Unit:Rpm, Range:5..?, Factor:9.091]
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]
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,
ID_Sensor = 0x68,
Reg_Sensor_Config_Gauge_Gain_Hi = 0x10,
Reg_Sensor_Config_Gauge_Gain_Lo = 0x11,
Reg_Sensor_Config_Ramp_Up_Steps_Hi = 0x12,
Reg_Sensor_Config_Ramp_Up_Steps_Lo = 0x13,
Reg_Sensor_Config_Ramp_Up_Steps_Hi = 0x12,
Reg_Sensor_Config_Ramp_Up_Steps_Lo = 0x13,
Reg_Sensor_Config_Decay_Delay_Hi = 0x14,
Reg_Sensor_Config_Decay_Delay_Lo = 0x15,
@@ -802,6 +802,10 @@ namespace BCTags
inline constexpr auto Min = "Min"_L1;
inline constexpr auto Max = "Max"_L1;
inline constexpr auto Factor = "Factor"_L1;
inline constexpr auto ValueTag = "Wert"_L1;
inline constexpr auto LabelTag = "Bezeichnung"_L1;
}
#endif // BC_H

View File

@@ -74,13 +74,13 @@ void BCCanDriver::onStartDriver()
if( _driverState == DriverState::NotPresent)
_driverState = loadDriver();
emit stateChanged( (int) _driverState );
emit stateChanged( _driverState );
// DLL geladen, Verbindungsversuch
_driverState = initDriver();
// Wir haben was erreicht
emit stateChanged( (int) _driverState );
emit stateChanged( _driverState );
}
catch( std::exception& except )
{

View File

@@ -114,10 +114,11 @@ public:
signals:
// __fix wird das gebraucht?
void errorOccured( const QString& errMsg );
void statusHint( const QString& msg ) const;
void stateChanged( int state );
void stateChanged( DriverState state );
public slots:

View File

@@ -169,7 +169,12 @@ void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
// nur gültige Werte sind vorhanden und können gespeichert werden
std::optional<BCValue> newValue = makeDataValue( deviceID, params );
if(newValue)
{
// wir merken uns gleich den index in der Werteliste
(*newValue).indexRow = currentValues.size();
currentValues.push_back( *newValue );
}
}
// weiter zum nächsten Element
_xml.skipCurrentElement();

View File

@@ -33,7 +33,7 @@
#ifndef BCDATAMANAGER_H
#define BCDATAMANAGER_H
#include <QMap>
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QMetaEnum>
@@ -79,7 +79,7 @@ protected:
std::optional<BCValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
using BCValueTypeMap = QMap<QString,BCValueType*>;
using BCValueTypeMap = QHash<QString,BCValueType*>;
QXmlStreamReader _xml;
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};

View File

@@ -89,14 +89,14 @@ private:
QString formatDisplayString(const QModelIndex& index) const;
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
int _highlightedRow{-1};
qreal _opacity{1.0};
QTableView* _view{};
QPropertyAnimation *_animation{};
int _highlightedRow{-1};
qreal _opacity{1.0};
QTableView* _view{};
QPropertyAnimation* _animation{};
private:
QHash<int, qreal> m_rowOpacities;
QHash<int, qreal> m_rowOpacities;
QHash<int, QVariantAnimation*> m_rowAnimations;
};

View File

@@ -78,7 +78,7 @@ protected:
// Wir brauchen eine Verbindung zwischen den Views
// und dem Device, das sie darstellen.
using BCDevicePanels = QMap<BCDevice::ID, BCDevicePanel*>;
using BCDevicePanels = QHash<BCDevice::ID, BCDevicePanel*>;
BCDevicePanels _devicePanels;
BCDevicePanel* _currentPanel{};

View File

@@ -32,6 +32,10 @@
#include <bcvaluemodel.h>
/**
* @brief Konstruktor, ohne Besonderheiten
* @param parent Das Elternobject
*/
BCValueModel::BCValueModel(QObject *parent)
: QAbstractTableModel(parent)
@@ -40,6 +44,11 @@ BCValueModel::BCValueModel(QObject *parent)
}
/**
* @brief Einen Einzelwert hinzufügen
* @param val der neue Wert
*/
void BCValueModel::addValue(const BCValue& val)
{
int row = _valueList.size();
@@ -49,12 +58,22 @@ void BCValueModel::addValue(const BCValue& val)
}
/**
* @brief Gibt die interne Werteliste als const ref zurück
* @return Die WerteListe
*/
const BCValueList& BCValueModel::getValueList() const
{
return _valueList;
}
/**
* @brief Nimmt eine Werteliste in Besitz.
* @param newValueList Die Wertelist. Nach dem Aufruf leer.
*/
void BCValueModel::takeValueList(BCValueList& newValueList)
{
beginResetModel();
@@ -63,34 +82,40 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
endResetModel();
}
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newValue )
/**
* @brief SLOT, der aufgerufen wird, wenn sich ein Wert und/oder der Zustand eines Wertes geändert hat.
* Emitted 'dataChanged' um die zuständige View upzudaten.
*
* @param row Der Index des geänderten Wertes in der Liste
* @param state Der neue state des Wertes
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall
*/
void BCValueModel::onValueUpdated( int row, BC::State state, const QString& newVisisbleValue )
{
qDebug() << " Panel update: " << newValue;
const BCValueList& valueList = getValueList();
if( row > -1 && row < valueList.size() )
qDebug() << " Panel update: " << newVisisbleValue;
if( row > -1 && row < _valueList.size() )
{
bool valueChanged = false;
const BCValue& value = valueList[row];
if( value.state != state )
const BCValue& value = _valueList[row];
QModelIndex idx = index(row,1);
value.state = state;
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
{
valueChanged = true;
value.state = state;
}
if( !newValue.isEmpty() && newValue != value.visibleValue )
{
valueChanged = true;
value.visibleValue = newValue;
}
if( valueChanged )
{
QModelIndex idx = index(row,1);
emit dataChanged(idx, idx, {Qt::DisplayRole});
value.visibleValue = newVisisbleValue;
}
// wir schicken auf jeden fall einen update request
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole});
}
}
/**
* @brief Gibt die Zeilenanzahl zurück
* @param parent Der Elternindex
* @return die Zeilenanzahl
*/
int BCValueModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
@@ -98,12 +123,29 @@ int BCValueModel::rowCount(const QModelIndex& parent) const
return _valueList.size();
}
int BCValueModel::columnCount(const QModelIndex &parent) const
/**
* @brief Gibt die Spaltenanzahl zurück
* @param parent Der Elternindex
* @return die Spaltenanzahl
*/
int BCValueModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid()) return 0;
if (parent.isValid())
return 0;
return 2;
}
/**
* @brief Gibt die Header-Einträge zurück
* @param section
* @param orientation
* @param role
* @return
*/
QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
@@ -112,9 +154,9 @@ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int
switch (section)
{
case 0:
return QString("Bezeichnung");
return BCTags::LabelTag;
case 1:
return QString("Wert");
return BCTags::ValueTag;
default:
return QVariant();
}
@@ -122,24 +164,7 @@ QVariant BCValueModel::headerData(int section, Qt::Orientation orientation, int
QVariant BCValueModel::data(const QModelIndex& index, int role) const
{
/*
if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
return QVariant();
const auto& item = m_items.at(index.row());
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0: return item.id;
case 1: return item.name;
case 2: {
// Hier nutzen wir QLocale für das Komma!
return QLocale(QLocale::German).toString(item.value, 'f', 2);
}
}
}
/*
// Bonus: Rechtsbündig für Zahlen
if (role == Qt::TextAlignmentRole && (index.column() == 0 || index.column() == 2)) {
return Qt::AlignRight | Qt::AlignVCenter;
@@ -152,8 +177,8 @@ if (!index.isValid() || index.row() >= static_cast<int>(m_items.size()))
if (!index.isValid() || row >= _valueList.size())
return QVariant();
BCValue& entry = const_cast<BCValue&>(_valueList.at( row ));
entry.indexRow = row;
const BCValue& entry = _valueList.at( row );
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
@@ -178,6 +203,9 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// __fix!
if (index.isValid() && role == Qt::EditRole)
{
BCValue& item = _valueList[index.row()];

View File

@@ -70,7 +70,7 @@ public:
public slots:
void onValueUpdated( int index, BC::State state, const QString& newValue="" );
void onValueUpdated(int index, BC::State state, const QString& newVisisbleValue="" );
protected: