Updated ValueHandling.

This commit is contained in:
Christoph Holzheuer
2026-01-07 17:13:35 +01:00
parent 7d43b0a694
commit 3bdc491830
17 changed files with 152 additions and 150 deletions

View File

@@ -37,6 +37,7 @@ li
windows windows
{ {
#LIBS += -L$$PWD/can_api -lmhstcan -lAdvapi32 #LIBS += -L$$PWD/can_api -lmhstcan -lAdvapi32
message("Konfiguration für Windows.")
} }
# You can make your code fail to compile if it uses deprecated APIs. # You can make your code fail to compile if it uses deprecated APIs.

View File

@@ -63,11 +63,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
// Hier bauen wir den String zusammen, den man sieht, // Hier bauen wir den String zusammen, den man sieht,
// wenn KEIN Editor offen ist. // wenn KEIN Editor offen ist.
// Format: "Label: Wert Einheit" // Format: "Label: Wert Einheit"
return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX"); return QString("%1: %2 %3").arg(bc.label, bc.formattedValue, "mmX");
} }
else else
{ {
qDebug() << " --- Nö!"; //qDebug() << " --- Nö!";
} }
// Fallback für normale Strings/Zahlen // Fallback für normale Strings/Zahlen
@@ -78,10 +78,11 @@ QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
/*
QVariant rawData = index.data(Qt::EditRole); QVariant rawData = index.data(Qt::EditRole);
//if (!rawData.canConvert<BCValue*>()) //if (!rawData.canConvert<BCValue*>())
return QStyledItemDelegate::createEditor(parent, option, index); return QStyledItemDelegate::createEditor(parent, option, index);
/*
const BCValue& bc = *rawData.value<BCValue*>(); const BCValue& bc = *rawData.value<BCValue*>();
// Nur bei Integern den Slider-Editor bauen // Nur bei Integern den Slider-Editor bauen
@@ -121,41 +122,50 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie
return container; return container;
} }
*/
return QStyledItemDelegate::createEditor(parent, option, index); return QStyledItemDelegate::createEditor(parent, option, index);
*/
} }
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{ {
/*
// Daten vom Model in den Editor laden // Daten vom Model in den Editor laden
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>(); const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
QSlider *slider = editor->findChild<QSlider*>("slider"); QSlider *slider = editor->findChild<QSlider*>("slider");
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit"); QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
if (slider && lblUnit) { if (slider && lblUnit)
{
bool olDriverState = slider->blockSignals(true); bool olDriverState = slider->blockSignals(true);
slider->setValue(bc.visibleValue.toInt()); slider->setValue(bc.formattedValue.toInt());
slider->blockSignals(olDriverState); slider->blockSignals(olDriverState);
lblUnit->setText(QString("%1 %2").arg(bc.formattedValue.toInt()).arg( "mm3"));
lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3")); }
} else { else
{
QStyledItemDelegate::setEditorData(editor, index); QStyledItemDelegate::setEditorData(editor, index);
} }
*/
} }
void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
{ {
/*
// Daten vom Editor zurück ins Model speichern (Beim Schließen) // Daten vom Editor zurück ins Model speichern (Beim Schließen)
QSlider *slider = editor->findChild<QSlider*>("slider"); QSlider *slider = editor->findChild<QSlider*>("slider");
if (slider) { if (slider)
{
int value = slider->value(); int value = slider->value();
model->setData(index, value, Qt::EditRole); model->setData(index, value, Qt::EditRole);
} else { }
else
{
QStyledItemDelegate::setModelData(editor, model, index); QStyledItemDelegate::setModelData(editor, model, index);
} }
*/
} }
void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
@@ -230,38 +240,42 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
{ {
/* /*
if (option.state & QStyle::State_Selected) { if (option.state & QStyle::State_Selected)
// 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS) {
QColor highlightColor = option.palette.highlight().color(); // 1. Die originale Highlight-Farbe holen (z.B. das Blau aus dem CSS)
QColor highlightColor = option.palette.highlight().color();
// 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt) // 2. Transparenz setzen (z.B. nur 30% Deckkraft für "Glass"-Effekt)
highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer) highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer)
// 3. Zeichnen (Brush setzt die Füllfarbe) // 3. Zeichnen (Brush setzt die Füllfarbe)
painter->fillRect(option.rect, highlightColor); painter->fillRect(option.rect, highlightColor);
} }
*/ */
const BCValue& valueX = *(_valueList[ index.row()].get());
int value = 50;//index.model()->data(index, Qt::DisplayRole).toInt(); const BCValue& bcValue = *(_valueList[ index.row()].get());
qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType;
// wenn Werte readOnly sind, dann brauchen keinen EditHint
if( bcValue.flags.testFlag(BCValue::Flag::ReadOnly) )
// || bcValue.valueType == BCValue::ValueType::Plain )
return;
// Hintergrund // Hintergrund
if (option.state & QStyle::State_Selected) if (option.state & QStyle::State_Selected)
{ {
painter->fillRect(option.rect, option.palette.highlight()); painter->fillRect(option.rect, option.palette.highlight());
} }
else else
{ {
QColor bcColor = option.palette.color(QPalette::Base); QColor bcColor = option.palette.color(QPalette::Base);
painter->fillRect(option.rect, bcColor); painter->fillRect(option.rect, bcColor);
} }
// Text und kleiner Slider-Indikator zeichnen // baby-Slider-Indikator zeichnen
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
//QRect textRect = option.rect.adjusted(8, 0, -120, 0);
QRect barRect = option.rect.adjusted QRect barRect = option.rect.adjusted
( (
8, 8,
@@ -275,10 +289,11 @@ if (option.state & QStyle::State_Selected) {
painter->setBrush(QColor(0xE0E0E0)); painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2); painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect; // Anteil zwischen min und max berechnen
fillRect.setWidth(barRect.width() * valueX.calcRatio() ); double ratio = bcValue.calcRatio();
barRect.setWidth(barRect.width() * ratio );
painter->setBrush(QColor(0x0078D4)); painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2); painter->drawRoundedRect(barRect, 2, 2);
painter->restore(); painter->restore();

View File

@@ -72,7 +72,7 @@ signals:
//void viewUpdateNeeded(); //void viewUpdateNeeded();
private: protected:
void updateRow(int row); void updateRow(int row);
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
@@ -83,7 +83,6 @@ private:
QPropertyAnimation* _animation{}; QPropertyAnimation* _animation{};
private:
QHash<int, qreal> m_rowOpacities; QHash<int, qreal> m_rowOpacities;
QHash<int, QVariantAnimation*> m_rowAnimations; QHash<int, QVariantAnimation*> m_rowAnimations;

View File

@@ -77,7 +77,7 @@ const BCValueList& BCDeviceView::getValueListX()
*/ */
void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueList ) void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueList )
{ {
qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size(); //qDebug() << " --- onValueListReady: " << deviceID << ": " << valueList.size();
if(_devideID == deviceID) if(_devideID == deviceID)
_valueModel.takeValueList( valueList ); _valueModel.takeValueList( valueList );
} }
@@ -87,9 +87,9 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis
* @brief SLOT, der aufgerufen wird, wenn ein Value geändert wurde. Gibt dem ItemDelegate Bescheid. * @brief SLOT, der aufgerufen wird, wenn ein Value geändert wurde. Gibt dem ItemDelegate Bescheid.
*/ */
void BCDeviceView::onValueUpdated(int index, BCValue::State state, const QString& newVisibleValue ) void BCDeviceView::updateValue(int index, BCValue::Flag state, uint32_t rawValue )
{ {
_valueModel.onValueUpdated( index, state, newVisibleValue); _valueModel.updateValue( index, state, rawValue );
_itemDelegate->onHighlightRow( index ); _itemDelegate->onHighlightRow( index );
} }

View File

@@ -53,14 +53,14 @@ public:
BCDevice::ID getDeviceID() const; BCDevice::ID getDeviceID() const;
const BCValueList& getValueListX(); const BCValueList& getValueListX();
//BCValueModel &getValueModel();
bool hasContent(); bool hasContent();
void updateValue( int index, BCValue::Flag state, uint32_t rawValue );
public slots: public slots:
void onValueListReady( BCDevice::ID deviceID, BCValueList valueList ); void onValueListReady( BCDevice::ID deviceID, BCValueList valueList );
void onValueUpdated( int index, BCValue::State state, const QString& newVisibleValue="" );
protected: protected:

View File

@@ -87,7 +87,7 @@ TransmitResult BCDriverDummy::writeRawByte( uint32_t deviceID, uint8_t registerI
{ {
Q_UNUSED(deviceID) Q_UNUSED(deviceID)
Q_UNUSED(registerID) Q_UNUSED(registerID)
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; //qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
return 0; return 0;
} }

View File

@@ -30,7 +30,7 @@
***************************************************************************/ ***************************************************************************/
#include <QDebug> #include <//qDebug>
#include <bcdrivertinycan.h> #include <bcdrivertinycan.h>
#include <can_drv.h> #include <can_drv.h>
@@ -180,22 +180,22 @@ BCDriver::DriverStateResult BCDriverTinyCan::setConsoleSlaveMode()
uint32_t console = static_cast<uint32_t>(BCDevice::ID::Console); uint32_t console = static_cast<uint32_t>(BCDevice::ID::Console);
uint8_t slaveFlag = static_cast<uint8_t> (BC::ID::Cons_Status_Slave); uint8_t slaveFlag = static_cast<uint8_t> (BC::ID::Cons_Status_Slave);
qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... "; //qDebug() << "XXX BCDriverTinyCan::Driver Init: putting Console in slave mode ... ";
TransmitResult isSlave = 0; TransmitResult isSlave = 0;
// Already slave? // Already slave?
isSlave = readRawByte( console, slaveFlag ); isSlave = readRawByte( console, slaveFlag );
if( isSlave.has_value() ) if( isSlave.has_value() )
{ {
qDebug() << "Console responded: " << isSlave.value(); //qDebug() << "Console responded: " << isSlave.value();
if( isSlave.value() == 1 ) if( isSlave.value() == 1 )
{ {
qDebug() << "Console already in slave mode. good!"; //qDebug() << "Console already in slave mode. good!";
return DriverState::DeviceReady; return DriverState::DeviceReady;
} }
} }
qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... "; //qDebug() << "BCDriverTinyCan::BCDriverTinyCan::XXX Driver Init: putting Console in slave mode ... ";
unsigned int retry = cTimeOuts; unsigned int retry = cTimeOuts;
@@ -237,7 +237,7 @@ void BCDriverTinyCan::resetDriver()
TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
{ {
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! "; //qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! ";
struct TCanMsg msg; struct TCanMsg msg;
int err, retry = 20; int err, retry = 20;
@@ -258,7 +258,7 @@ TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t register
bc::delay_millis( cTIMEOUT_MS ); bc::delay_millis( cTIMEOUT_MS );
if (timeout == -1) if (timeout == -1)
qDebug() << "error: could not send value to node "; //qDebug() << "error: could not send value to node ";
retry: retry:
@@ -268,34 +268,34 @@ retry:
if (timeout == -1) if (timeout == -1)
{ {
qDebug() << "error: no response from node"; //qDebug() << "error: no response from node";
return 0; return 0;
} }
if ((err = CanReceive(0, &msg, 1)) > 0) if ((err = CanReceive(0, &msg, 1)) > 0)
{ {
qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg; //qDebug() << " retry: " << retry << " BIB:" << BC::ID::ID_Bib << " msg.Id: " << msg.Id << " msg.MsgLen: " << msg.MsgLen << " msg.MsgData[1]: " << msg.MsgData[1] << " reg: " << reg;
if (--retry && (msg.Id != (uint32_t)BC::ID::ID_Bib|| msg.MsgLen != 4 || msg.MsgData[1] != reg)) if (--retry && (msg.Id != (uint32_t)BC::ID::ID_Bib|| msg.MsgLen != 4 || msg.MsgData[1] != reg))
goto retry; goto retry;
if (!retry) if (!retry)
{ {
qDebug() << "XXX error: no response from node: " << err; //qDebug() << "XXX error: no response from node: " << err;
return 0; return 0;
} }
qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3]; //qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3];
return (unsigned int) msg.MsgData[3]; return (unsigned int) msg.MsgData[3];
} }
else else
{ {
qDebug() << "Error:" <<err; //qDebug() << "Error:" <<err;
} }
return 0; return 0;
/* /*
//TransmitResult //TransmitResult
qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState(); //qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState();
if( _driverState <DriverState::Opened ) if( _driverState <DriverState::Opened )
return std::unexpected(QString("readRawValue error: driver not loaded." ) ); return std::unexpected(QString("readRawValue error: driver not loaded." ) );
@@ -337,15 +337,15 @@ retry:
// message empfangen // message empfangen
int err = ::CanReceive( 0, &msg, 1 ); int err = ::CanReceive( 0, &msg, 1 );
//qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts; ////qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts;
if( err < 0 ) if( err < 0 )
//throw BCException( "getValue error: could not receive value" ); //throw BCException( "getValue error: could not receive value" );
qDebug( "getValue error: could not receive value" ); //qDebug( "getValue error: could not receive value" );
//qDebug() << "HÄÄ 2" <<msg.Id; ////qDebug() << "HÄÄ 2" <<msg.Id;
//qDebug() << "HÄÄ 2" <<msg.MsgLen; ////qDebug() << "HÄÄ 2" <<msg.MsgLen;
//qDebug() << "HÄÄ 2" <<msg.MsgData[1]; ////qDebug() << "HÄÄ 2" <<msg.MsgData[1];
//if( err > 0 ) //if( err > 0 )
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) ) if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) )
@@ -354,7 +354,7 @@ retry:
if( !timeOuts ) if( !timeOuts )
return std::unexpected(QString("CAN response errror: timeout" )); return std::unexpected(QString("CAN response errror: timeout" ));
qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID; //qDebug() << " --- CAN Read Byte: " << (uint32_t) msg.MsgData[3] << " Device:: "<< deviceID << " register: " << registerID;
return (uint32_t) msg.MsgData[3]; return (uint32_t) msg.MsgData[3];
*/ */
} }
@@ -367,7 +367,7 @@ TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registe
if( _driverState <DriverState::Opened ) if( _driverState <DriverState::Opened )
return std::unexpected(QString("readRawValue error: driver not loaded." ) ); return std::unexpected(QString("readRawValue error: driver not loaded." ) );
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; //qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
::TCanMsg msg; ::TCanMsg msg;
int timeout_count = cTIMEOUT_COUNT; int timeout_count = cTIMEOUT_COUNT;

View File

@@ -134,7 +134,6 @@ void BCDriverStateWidget::onDriverStateChanged(BCDriver::DriverState state, cons
{ {
_state = state; _state = state;
qDebug() << " --- StateWidget: " << state << " - " << customMessage; qDebug() << " --- StateWidget: " << state << " - " << customMessage;
updateStyle(); updateStyle();
} }

View File

@@ -298,13 +298,13 @@ void BCMainWindow::onConnectButtonToggled(bool checked )
//_dataManager.setDriverConnectionState( checked ); //_dataManager.setDriverConnectionState( checked );
} }
void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue ) void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue )
{ {
qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)state << " on:" << newValue; qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)state << " on:" << rawValue;
if( _devicePanels.contains( deviceID ) ) if( _devicePanels.contains( deviceID ) )
{ {
BCDeviceView& panel = *_devicePanels[deviceID]; BCDeviceView& panel = *_devicePanels[deviceID];
panel.onValueUpdated( index, state, newValue ); panel.updateValue( index, state, rawValue );
} }
} }
@@ -332,7 +332,7 @@ void BCMainWindow::onSyncDeviceView()
{ {
qDebug() << " --- ### begin sync of value: " << QThread::currentThreadId() << " : " << value->label; qDebug() << " --- ### begin sync of value: " << QThread::currentThreadId() << " : " << value->label;
// wir setzen auf 'lesen' // wir setzen auf 'lesen'
value->state.setFlag( BCValue::State::ReadMe ); value->flags.setFlag( BCValue::Flag::ReadMe );
_syncButton->setEnabled( false ); _syncButton->setEnabled( false );

View File

@@ -61,7 +61,7 @@ public slots:
void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" ); void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" );
// Slots für Rückmeldungen vom Transmitter // Slots für Rückmeldungen vom Transmitter
void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" ); void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue );
void onValueQueueEmpty(); void onValueQueueEmpty();
void onSyncDeviceView(); void onSyncDeviceView();

View File

@@ -31,7 +31,7 @@
#include <QThread> #include <QThread>
#include <QDebug> #include <//qDebug>
#include <QCoreApplication> #include <QCoreApplication>
#include <bctransmitter.h> #include <bctransmitter.h>
@@ -56,7 +56,7 @@ BCTransmitter::BCTransmitter(QObject *parent)
void BCTransmitter::onToggleDriverConnection( bool connect ) void BCTransmitter::onToggleDriverConnection( bool connect )
{ {
qDebug() << " --- onToggleDriverConnection: " << connect; //qDebug() << " --- onToggleDriverConnection: " << connect;
emit driverStateChanged(BCDriver::DriverState::Initialized, "BUSY!"); emit driverStateChanged(BCDriver::DriverState::Initialized, "BUSY!");
bc::delay_millis(350); bc::delay_millis(350);
// kill all pending stuff // kill all pending stuff
@@ -103,13 +103,13 @@ void BCTransmitter::connectCanDriver()
if( hwVersion.has_value() ) if( hwVersion.has_value() )
{ {
message = " ---- HAIL to the king!"; message = " ---- HAIL to the king!";
qDebug() << message; //qDebug() << message;
// swap driver // swap driver
_canDriver = &_tinyCanDriver; _canDriver = &_tinyCanDriver;
} }
else else
{ {
qDebug() << "Console not responding"; //qDebug() << "Console not responding";
} }
} }
else else
@@ -144,7 +144,7 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr)
// der aktuelle Auftragsblock abgearbeit wurde. // der aktuelle Auftragsblock abgearbeit wurde.
_valueQueue.enqueue( valuePtr ); _valueQueue.enqueue( valuePtr );
qDebug() << " # #### ENQ: " <<_valueQueue.size(); //qDebug() << " # #### ENQ: " <<_valueQueue.size();
// Wir schicken den event gleich wieder weiter ... // Wir schicken den event gleich wieder weiter ...
QMetaObject::invokeMethod(this, "onProcessValue", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "onProcessValue", Qt::QueuedConnection);
@@ -160,12 +160,12 @@ void BCTransmitter::onProcessValue()
if (_valueQueue.isEmpty()) if (_valueQueue.isEmpty())
{ {
//_isBusy = false; //_isBusy = false;
qDebug() << " --- XXXXXXXXXX Warum so oft?"; //qDebug() << " --- XXXXXXXXXX Warum so oft?";
emit valueQueueEmpty(); emit valueQueueEmpty();
break; // Schleife verlassen, warten auf neue Events break; // Schleife verlassen, warten auf neue Events
} }
valuePtr =_valueQueue.dequeue(); valuePtr =_valueQueue.dequeue();
qDebug() << " # #### DEQ: " <<_valueQueue.size(); //qDebug() << " # #### DEQ: " <<_valueQueue.size();
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock! } // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
// Kosmetik // Kosmetik
@@ -174,19 +174,20 @@ void BCTransmitter::onProcessValue()
// Kosmetik // Kosmetik
//const BCValue& value = *(valuePtr.get()); //const BCValue& value = *(valuePtr.get());
qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label; //qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label;
// Value ist 'under construction' // Value ist 'under construction'
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked ); //emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked );
uint32_t devID = static_cast<uint32_t>(value.deviceID); uint32_t devID = static_cast<uint32_t>(value.deviceID);
uint8_t regID = static_cast<uint8_t> (value.registerID); uint8_t regID = static_cast<uint8_t> (value.registerID);
QString newVisibleValue; // Für den Fehlerfall: Wir senden den alten Wert einfach zurück
BCValue::State newState = BCValue::State::NoState; uint32_t newValue = value.rawUIntValue;
BCValue::Flag newState = BCValue::Flag::Failed;;
if(value.state.testFlag( BCValue::State::WriteMe ) ) if(value.flags.testFlag( BCValue::Flag::WriteMe ) )
{ {
@@ -194,23 +195,18 @@ void BCTransmitter::onProcessValue()
// oder sollen wir hier beides erlauben ? readFlag & writeFlag ? // oder sollen wir hier beides erlauben ? readFlag & writeFlag ?
// Was kommt dann zuerst? Schreiben und lesen als verify ? // Was kommt dann zuerst? Schreiben und lesen als verify ?
else if( value.state.testFlag( BCValue::State::ReadMe ) ) else if( value.flags.testFlag( BCValue::Flag::ReadMe ) )
{ {
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen // wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
TransmitResult result = value.isWord ? readWordValue( devID, regID ) : readByteValue( devID, regID ); TransmitResult result = value.isWord() ? readWordValue( devID, regID ) : readByteValue( devID, regID );
if( result.has_value() ) if( result.has_value() )
{ {
// quark! das gehört hier nicht hin! newState = BCValue::Flag::InSync;
newVisibleValue = value.formatValues( result.value() ); newValue = result.value();
newState = BCValue::State::InSync;
}
else
{
newState = BCValue::State::Failed;
} }
} }
emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue ); emit valueUpdated( value.deviceID, value.indexRow, newState, newValue );
// __fix // __fix
//bc::processEventsFor(150); //bc::processEventsFor(150);
@@ -223,7 +219,7 @@ void BCTransmitter::onProcessValue()
TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID ) TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID )
{ {
//qDebug() << " --- YES: Read ByteValue: " << registerID; ////qDebug() << " --- YES: Read ByteValue: " << registerID;
// Wir lesen nur ein Byte und gut. // Wir lesen nur ein Byte und gut.
return _canDriver->readRawByte( deviceID, registerID ); return _canDriver->readRawByte( deviceID, registerID );
} }
@@ -231,7 +227,7 @@ TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t register
TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID ) TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID )
{ {
//qDebug() << " --- YES: Read WordValue: " << registerID; ////qDebug() << " --- YES: Read WordValue: " << registerID;
uint32_t result{}; uint32_t result{};
// hi byte Leseversuch. // hi byte Leseversuch.

View File

@@ -70,7 +70,7 @@ public slots:
signals: signals:
void valueQueueEmpty(); void valueQueueEmpty();
void valueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" ); void valueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue );
void driverStateChanged( BCDriver::DriverState state, const QString& message="" ); void driverStateChanged( BCDriver::DriverState state, const QString& message="" );
private: private:

View File

@@ -41,18 +41,22 @@
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_) BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
: deviceID{deviceID_}, registerID{registerID_} : deviceID{deviceID_}, registerID{registerID_}
{ {
visibleValue = "--";
} }
QString BCValue::formatValues( uint32_t value ) const QString BCValue::formatValue() const
{ {
if( factor == 1 ) if( factor == 1 )
return QString::number( value ); return QString::number( rawUIntValue );
double result = value * factor; double result = rawUIntValue * factor;
return QString::number(result, 'f', 2); return QString::number(result, 'f', 2);
} }
bool BCValue::isWord() const
{
return flags.testFlag(BCValue::Flag::IsWord);
}
double BCValue::calcRatio() const double BCValue::calcRatio() const
{ {
@@ -73,7 +77,7 @@ double BCValue::calcRatio() const
return ratio; return ratio;
// Die eigentliche Formel // Die eigentliche Formel
ratio = ((rawValue - min) / range); ratio = ((rawDoubleValue - min) / range);
//ratio = (int) qBound( min,ratio, max); //ratio = (int) qBound( min,ratio, max);
} }
return ratio; return ratio;
@@ -83,8 +87,8 @@ void BCValue::dumpValue() const
{ {
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label; qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
qDebug() << "visibleValue: " << visibleValue << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " "; qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord; qDebug() << "indexRow: " << indexRow << " isWord: " << isWord();
qDebug(); qDebug();
} }

View File

@@ -72,46 +72,47 @@ public:
// später der Editor // später der Editor
enum class ValueType : uint8_t enum class ValueType : uint8_t
{ {
Plain, Plain, // nur lesen, sowas wie SerialNo
Bool, Bool,
Number, Number,
Float Float
}; };
enum class State : uint8_t enum class Flag : uint8_t
{ {
NoState = 0x00, NoFlag = 0x00,
ReadMe = 0x01, ReadMe = 0x01,
WriteMe = 0x02, WriteMe = 0x02,
ReadOnly = 0x04, ReadOnly = 0x04,
Locked = 0x08, Locked = 0x08,
Failed = 0x10, Failed = 0x10,
InSync = 0x20, InSync = 0x20,
OK = 0x40 OK = 0x40,
IsWord = 0x80
}; };
Q_DECLARE_FLAGS(States, State ) Q_DECLARE_FLAGS(Flags, Flag )
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ ); BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
QString formatValues( uint32_t value ) const; QString formatValue() const;
double calcRatio() const; double calcRatio() const;
void dumpValue() const; void dumpValue() const;
bool isWord() const;
mutable States state{BCValue::State::ReadOnly}; mutable Flags flags{BCValue::Flag::ReadOnly};
BCDevice::ID deviceID{BCDevice::ID::Invalid}; BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID registerID{BC::ID::Invalid}; BC::ID registerID{BC::ID::Invalid};
ValueType valueType{ValueType::Plain}; ValueType valueType{ValueType::Plain};
int indexRow{-1}; int indexRow{-1};
QString label; QString label;
mutable QString visibleValue; mutable double rawDoubleValue;
mutable double rawValue; mutable uint32_t rawUIntValue;
bool isWord{false}; QString unitLabel;
QString unitLabel; double factor{1};
double factor{1}; OptDouble optMin;
OptDouble optMin; OptDouble optMax;
OptDouble optMax;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States) Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)

View File

@@ -81,29 +81,20 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall * @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall
*/ */
void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& newVisisbleValue ) void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue )
{ {
if( row > -1 && row < _valueList.size() ) if( row > -1 && row < _valueList.size() )
{ {
const BCValue& value = *(_valueList[row].get()); const BCValue& value = *(_valueList[row].get());
QModelIndex idx = index(row,1);
//qDebug(); value.flags = state;
//qDebug() << " --- OLD:"<< newVisisbleValue; value.rawUIntValue = rawValue;
//value.dumpValue();
value.state = state; QModelIndex idx1 = index(row,1);
QModelIndex idx2 = index(row,2);
if( !newVisisbleValue.isEmpty() && newVisisbleValue != value.visibleValue )
{
value.visibleValue = newVisisbleValue;
}
//qDebug() << " --- NEW: " << newVisisbleValue;
//value.dumpValue();
// wir schicken auf jeden fall einen update request // wir schicken auf jeden fall einen update request
emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole}); emit dataChanged(idx1, idx2, {Qt::DisplayRole, Qt::EditRole});
} }
} }
@@ -161,9 +152,9 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const
if( col == 1) if( col == 1)
{ {
if( role == Qt::DisplayRole ) if( role == Qt::DisplayRole )
return QString("%1 %2").arg( value.visibleValue, value.unitLabel); return QString("%1 %2").arg( value.formatValue(), value.unitLabel);
return value.visibleValue; return value.formatValue();
} }
return QVariant(); return QVariant();
@@ -199,23 +190,19 @@ Qt::ItemFlags BCValueModel::flags(const QModelIndex& index) const
} }
bool BCValueModel::setData(const QModelIndex& index, const QVariant& value, int role) bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, int role)
{ {
// __fix!
if (index.isValid() && role == Qt::EditRole) if (index.isValid() && role == Qt::EditRole)
{ {
BCValuePtr item = _valueList[index.row()]; BCValuePtr value = _valueList[index.row()];
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
// Checken ob Int oder Double // Checken ob Int oder Double
if (value.canConvert<double>()) if (variant.canConvert<int>())
{ {
item->visibleValue = value.toString(); value->rawUIntValue = variant.toInt();
} }
_valueList[index.row()] = item;
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole}); emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
return true; return true;
} }

View File

@@ -66,9 +66,7 @@ public:
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex& index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
public slots: void updateValue(int row, BCValue::Flag state, uint32_t rawValue );
void onValueUpdated(int index, BCValue::State state, const QString& newVisisbleValue="" );
protected: protected:

View File

@@ -183,12 +183,12 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
auto setIfExists = [&]<typename T>( QStringView source, T& target ) auto setIfExists = [&]<typename T>( QStringView source, T& target )
{ {
if( !source.isEmpty() ) if( !source.isEmpty() )
{ {
bool ok; bool ok;
double testVal = source.toDouble(&ok); double testVal = source.toDouble(&ok);
if (ok) if (ok)
target = testVal; target = testVal;
} }
}; };
@@ -214,7 +214,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
setIfExists( params.Factor, newValue.factor ); setIfExists( params.Factor, newValue.factor );
setIfExists( params.Min, newValue.optMin ); setIfExists( params.Min, newValue.optMin );
setIfExists( params.Max, newValue.optMax ); setIfExists( params.Max, newValue.optMax );
setIfExists( params.IsWord, newValue.isWord ); //setIfExists( params.IsWord, newValue.isWord );
newValue.label = params.Label; newValue.label = params.Label;
newValue.unitLabel = params.UnitLabel; newValue.unitLabel = params.UnitLabel;