Added & configured actions.
This commit is contained in:
15
bc.h
15
bc.h
@@ -134,6 +134,8 @@ public:
|
||||
//{%Region Console}
|
||||
|
||||
Invalid = 0x0,
|
||||
ID_Pimp = 0xF1, // dummy id to identify the tuning page
|
||||
|
||||
|
||||
ID_Console_Master = 0x08, // (Can Id In Master Mode)
|
||||
ID_Console_Slave = 0x48, // (Can Id In Slave Mode)
|
||||
@@ -706,12 +708,12 @@ public:
|
||||
|
||||
|
||||
//{%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,
|
||||
@@ -772,7 +774,8 @@ public:
|
||||
Battery = uint8_t( BC::ID::ID_Battery),
|
||||
Motor = uint8_t( BC::ID::ID_Motor ),
|
||||
BIB = uint8_t( BC::ID::ID_Bib ),
|
||||
Sensor = uint8_t( BC::ID::ID_Sensor )
|
||||
Sensor = uint8_t( BC::ID::ID_Sensor ),
|
||||
Pimp = uint8_t( BC::ID::ID_Pimp )
|
||||
};
|
||||
Q_ENUM(ID)
|
||||
};
|
||||
|
||||
@@ -78,6 +78,17 @@ BCDataManager::~BCDataManager()
|
||||
}
|
||||
|
||||
|
||||
BCTransmitter* BCDataManager::getTransmitter()
|
||||
{
|
||||
return &_transmitter;
|
||||
};
|
||||
|
||||
const BCValueList& BCDataManager::getCurrentValueList()
|
||||
{
|
||||
return _currentValues;
|
||||
}
|
||||
|
||||
|
||||
void BCDataManager::onCommandFinished(int id, bool success)
|
||||
{
|
||||
qDebug() << "[Manager] Command" << id << "finished. Success:" << success;
|
||||
@@ -128,19 +139,7 @@ void BCDataManager::onSyncFromDevice()
|
||||
*/
|
||||
}
|
||||
|
||||
std::optional<BCValueModel*> BCDataManager::getModel(BCDevice::ID deviceID )
|
||||
{
|
||||
if( _valueModels.contains( deviceID) )
|
||||
return _valueModels[deviceID];
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
BCTransmitter* BCDataManager::getTransmitter()
|
||||
{
|
||||
return &_transmitter;
|
||||
};
|
||||
|
||||
void BCDataManager::loadXmlBikeData()
|
||||
void BCDataManager::loadXmlBikeData( const QString& fileName )
|
||||
{
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
@@ -156,7 +155,7 @@ void BCDataManager::loadXmlBikeData()
|
||||
return;
|
||||
*/
|
||||
|
||||
QFile file(":/bikeinfo.xml");
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
// __fix throw
|
||||
@@ -182,28 +181,17 @@ void BCDataManager::loadXmlBikeData()
|
||||
{
|
||||
QString deviceType = _xml.attributes().value("Type"_L1).toString();
|
||||
printAttrs (_xml);
|
||||
// Wir wollen die Device-ID aus dem XML Tag ermitteln
|
||||
const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData();
|
||||
auto deviceID = _bcDeviceEnum.keyToValue64(deviceKey);
|
||||
auto optDeviceID = _bcDeviceEnum.keyToValue64(deviceKey);
|
||||
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
||||
if(deviceID.has_value())
|
||||
if( optDeviceID.has_value())
|
||||
{
|
||||
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << deviceID;
|
||||
|
||||
_currentDeviceID = BCDevice::ID( deviceID.value() );
|
||||
BCValueList parsedValues;
|
||||
loadXmlBikeDeviceData( parsedValues );
|
||||
if( parsedValues.count() )
|
||||
{
|
||||
BCValueModel* valueModel = new BCValueModel( this );
|
||||
// hier lacht der blaue HASE
|
||||
//valueModel->setValueList(parsedValues);
|
||||
_valueModels.insert( _currentDeviceID, valueModel );
|
||||
}
|
||||
qDebug() << " --- Device: " << _xml.name() << ": " << deviceType << " : " << optDeviceID;
|
||||
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
|
||||
loadXmlBikeDeviceData(currentDeviceID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_currentDeviceID = BCDevice::ID::Console;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -221,7 +209,7 @@ void BCDataManager::loadXmlBikeData()
|
||||
|
||||
}
|
||||
|
||||
void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
|
||||
void BCDataManager::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
{
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
@@ -234,17 +222,18 @@ void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
|
||||
|
||||
printAttrs (_xml);
|
||||
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
|
||||
qDebug() << " ---------------";
|
||||
qDebug() << " XXX ---------------";
|
||||
|
||||
// Wertliste für neues Device leeren
|
||||
_currentValues.clear();
|
||||
|
||||
//while (!_xml.atEnd() && !_xml.hasError())
|
||||
while( _xml.readNextStartElement() )
|
||||
{
|
||||
if( _xml.attributes().hasAttribute(BCTags::ID) )
|
||||
{
|
||||
//qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID);
|
||||
|
||||
QString id = _xml.attributes().value(BCTags::ID).toString();
|
||||
// füllen des Parameter packs
|
||||
BCDataParams params
|
||||
{
|
||||
.ID = id,
|
||||
@@ -253,18 +242,19 @@ void BCDataManager::loadXmlBikeDeviceData( BCValueList& parsedValues )
|
||||
.UnitType = _xml.attributes().value(BCTags::UnitType).toString(),
|
||||
};
|
||||
|
||||
// __fix! können ungültige werte erzeugt werden ?
|
||||
//BCDataValue newValue = BCData::makeDataValue( _currentDeviceID, params );
|
||||
//if(newValue)
|
||||
// parsedValues.push_back( newValue );
|
||||
std::optional<BCDataValue> newValue = makeDataValue( _currentDeviceID, params );
|
||||
// nur gültige Werte sind vorhanden und können gespeichert werden
|
||||
std::optional<BCDataValue> newValue = makeDataValue( deviceID, params );
|
||||
if(newValue)
|
||||
parsedValues.push_back( *newValue );
|
||||
_currentValues.push_back( *newValue );
|
||||
}
|
||||
|
||||
//printAttrs (_xml);
|
||||
// weiter zum nächsten Element
|
||||
_xml.skipCurrentElement();
|
||||
}
|
||||
|
||||
// Wenn dieses Device fertig geladen wurde, soll das MainWindow es abholen
|
||||
if( !_currentValues.isEmpty() )
|
||||
emit valueListReady( deviceID );
|
||||
|
||||
}
|
||||
|
||||
std::optional<BCDataValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
||||
|
||||
@@ -55,15 +55,18 @@ public:
|
||||
|
||||
std::optional<BCValueModel*> getModel(BCDevice::ID deviceID );
|
||||
BCTransmitter* getTransmitter();
|
||||
const BCValueList& getCurrentValueList();
|
||||
|
||||
public slots:
|
||||
|
||||
void loadXmlBikeData();
|
||||
void loadXmlBikeData( const QString& fileName );
|
||||
void saveBikeData();
|
||||
void onSyncFromDevice();
|
||||
|
||||
signals:
|
||||
|
||||
void valueListReady( BCDevice::ID deviceID );
|
||||
|
||||
// Internes Signal, um Daten an den Worker Thread zu senden
|
||||
void sendValueCommand( BC::OpID, const BCDataValue* cmd);
|
||||
//void valuedTouched(const BCDataValue& cmd);
|
||||
@@ -85,18 +88,15 @@ protected:
|
||||
QString UnitType;
|
||||
};
|
||||
|
||||
void loadXmlBikeDeviceData( BCValueList& parsedValues );
|
||||
void loadXmlBikeDeviceData( BCDevice::ID deviceID );
|
||||
|
||||
std::optional<BCDataValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
|
||||
|
||||
using BCDeviceModels = QMap<BCDevice::ID, BCValueModel*>;
|
||||
using BCValueTypeMap = QMap<QString,BCValueType*>;
|
||||
|
||||
QXmlStreamReader _xml;
|
||||
|
||||
BCDeviceModels _valueModels;
|
||||
BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid};
|
||||
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
||||
QXmlStreamReader _xml;
|
||||
BCValueList _currentValues;
|
||||
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
||||
|
||||
QThread _worker;
|
||||
BCTransmitter _transmitter;
|
||||
|
||||
@@ -80,6 +80,9 @@ public:
|
||||
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||
// void reset()
|
||||
|
||||
// später
|
||||
//protected:
|
||||
|
||||
//const BCValueType& valueType;
|
||||
//BCValueTypeCRef valueType;
|
||||
const BCValueType* valueType{};
|
||||
@@ -87,6 +90,7 @@ public:
|
||||
BC::ID registerID{BC::ID::Invalid};
|
||||
int rowInModel{-1};
|
||||
QString label;
|
||||
// ??
|
||||
mutable QString visibleValue;
|
||||
QVariant defaultValue;
|
||||
|
||||
@@ -95,8 +99,6 @@ public:
|
||||
|
||||
//mutable std::optional<uint32_t> rawValue;
|
||||
|
||||
|
||||
|
||||
};
|
||||
Q_DECLARE_METATYPE(BCDataValue*)
|
||||
|
||||
|
||||
113
bcmainwindow.cpp
113
bcmainwindow.cpp
@@ -44,15 +44,59 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
initData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
BCMainWindow::~BCMainWindow()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::initData()
|
||||
{
|
||||
// Die Daten und auch die Datenmodelle für die Views werden
|
||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||
|
||||
/*
|
||||
auto setDeviceModel = [&]( BCDevice::ID deviceID, BCDevicePanel* panel )
|
||||
{
|
||||
auto model = _dataManager.getModel( deviceID );
|
||||
if( model)
|
||||
{
|
||||
QAbstractItemView* valueView = panel->getValueView();
|
||||
valueView->setModel( *model );
|
||||
//valueView->resizeColumnsToContents();
|
||||
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
auto configureAction = [&]( QToolButton* button, QAction* action, BCDevice::ID deviceID )
|
||||
{
|
||||
button->setDefaultAction( action);
|
||||
connect( action, &QAction::triggered, this, &BCMainWindow::onActionButtonTriggered );
|
||||
connect( action, &QAction::toggled, this, &BCMainWindow::onActionButtonToggled );
|
||||
// new way
|
||||
connect( action, &QAction::triggered, this, [&]
|
||||
{
|
||||
onShowDevicePanel( deviceID );
|
||||
});
|
||||
};
|
||||
|
||||
// Wir wollen die Devices den Views zuordnen können
|
||||
_devicePanels[BCDevice::ID::Console] = _consolePanel;
|
||||
_devicePanels[BCDevice::ID::Battery] = _batteryPanel;
|
||||
_devicePanels[BCDevice::ID::Motor] = _motorPanel;
|
||||
|
||||
// Die actions an die Buttons binden
|
||||
_motorButton->setDefaultAction( _motorAction);
|
||||
_consoleButton->setDefaultAction( _consoleAction );
|
||||
_batteryButton->setDefaultAction( _batteryAction );
|
||||
_pimpButton->setDefaultAction( _pimpAction);
|
||||
configureAction(_motorButton, _motorAction, BCDevice::ID::Motor );
|
||||
configureAction(_consoleButton, _consoleAction, BCDevice::ID::Console );
|
||||
configureAction(_batteryButton, _batteryAction, BCDevice::ID::Battery );
|
||||
configureAction(_pimpButton, _pimpAction, BCDevice::ID::Pimp );
|
||||
|
||||
// die Daten des eBikes laden
|
||||
_dataManager.loadXmlBikeData();
|
||||
|
||||
// Die Daten und auch die Datenmodelle für die Views werden
|
||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||
@@ -92,42 +136,49 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
||||
connect( _syncButton, &QPushButton::clicked, &_dataManager, &BCDataManager::onSyncFromDevice );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
BCMainWindow::~BCMainWindow()
|
||||
{
|
||||
|
||||
// wir wollen Bescheid wissen, wenn ein Device (entspricht einem Datenmodel)
|
||||
// fertig eingelesen wurde.
|
||||
connect( &_dataManager, &BCDataManager::valueListReady, this, &BCMainWindow::onValueListReady );
|
||||
// die Daten des eBikes laden
|
||||
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::initData()
|
||||
{
|
||||
// Die Daten und auch die Datenmodelle für die Views werden
|
||||
// vom DataManager verwaltet und an die Views weitergereicht.
|
||||
|
||||
auto setDeviceModel = [&]( BCDevice::ID deviceID, BCDevicePanel* panel )
|
||||
|
||||
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
|
||||
{
|
||||
qDebug() << " --- onValueListReady!" << deviceID;
|
||||
if( _devicePanels.contains( deviceID ) )
|
||||
{
|
||||
auto model = _dataManager.getModel( deviceID );
|
||||
if( model)
|
||||
{
|
||||
QAbstractItemView* valueView = panel->getValueView();
|
||||
valueView->setModel( *model );
|
||||
//valueView->resizeColumnsToContents();
|
||||
//_valueView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
_dataManager.loadXmlBikeData();
|
||||
|
||||
|
||||
const BCValueList& newValueList = _dataManager.getCurrentValueList();
|
||||
_devicePanels[deviceID]->setValueList( newValueList );
|
||||
}
|
||||
}
|
||||
|
||||
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
||||
{
|
||||
qDebug() << " --- onShowDevicePanel:" << deviceID;
|
||||
if( _devicePanels.contains( deviceID ) )
|
||||
{
|
||||
//const BCValueList& newValueList = _dataManager.getCurrentValueList();
|
||||
//_devicePanels[deviceID]->setValueList( newValueList );
|
||||
}
|
||||
}
|
||||
|
||||
void BCMainWindow::onActionButtonTriggered( bool checked)
|
||||
{
|
||||
qDebug() << " --- onActionButtonTriggered: " << checked;
|
||||
|
||||
}
|
||||
|
||||
void BCMainWindow::onActionButtonToggled( bool checked)
|
||||
{
|
||||
qDebug() << " --- onActionButtonToggled: " << checked;
|
||||
}
|
||||
|
||||
|
||||
void BCMainWindow::onConnectButtonToggled(bool checked )
|
||||
{
|
||||
//_dataManager.setDriverConnectionState( checked );
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
#include <ui_bcmainwindow.h>
|
||||
#include <bcdatamanager.h>
|
||||
|
||||
|
||||
class AnimatedDelegate;
|
||||
class BCDevicePanel;
|
||||
|
||||
class BCMainWindow : public QMainWindow, public Ui_BCMainWindow
|
||||
{
|
||||
@@ -52,6 +51,10 @@ public:
|
||||
|
||||
public slots:
|
||||
|
||||
void onValueListReady( BCDevice::ID deviceID );
|
||||
void onShowDevicePanel( BCDevice::ID deviceID );
|
||||
void onActionButtonTriggered( bool checked);
|
||||
void onActionButtonToggled( bool checked);
|
||||
void onConnectButtonToggled(bool active );
|
||||
|
||||
protected:
|
||||
@@ -59,8 +62,12 @@ protected:
|
||||
void initData();
|
||||
|
||||
BCDataManager _dataManager;
|
||||
AnimatedDelegate* _delegate;
|
||||
|
||||
// Wir brauchen eine Verbindung zwischen den Views
|
||||
// und dem Device, das sie darstellen.
|
||||
|
||||
using BCDevicePanels = QMap<BCDevice::ID, BCDevicePanel*>;
|
||||
BCDevicePanels _devicePanels;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -151,6 +151,9 @@
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="_statusbar"/>
|
||||
<action name="_pimpAction">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:restart.png</normaloff>:restart.png</iconset>
|
||||
|
||||
@@ -49,21 +49,19 @@ void BCValueModel::addValue(const BCDataValue& val)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void BCValueModel::setValueList(BCValueList* valueList)
|
||||
const BCValueList& BCValueModel::getValueList()
|
||||
{
|
||||
return _valueList;
|
||||
}
|
||||
|
||||
|
||||
void BCValueModel::setValueList(const BCValueList& valueList)
|
||||
{
|
||||
beginResetModel();
|
||||
_valueList = valueList;
|
||||
endResetModel();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
BCValueList& BCValueModel::getValueList()
|
||||
{
|
||||
return _valueList;
|
||||
}
|
||||
*/
|
||||
|
||||
int BCValueModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
|
||||
@@ -53,9 +53,8 @@ public:
|
||||
explicit BCValueModel(QObject *parent = nullptr);
|
||||
|
||||
void addValue(const BCDataValue& val);
|
||||
|
||||
//void setValueList(BCValueList* valueList);
|
||||
//BCValueList *getValueList();
|
||||
void setValueList(const BCValueList& valueList);
|
||||
const BCValueList& getValueList();
|
||||
|
||||
// Pure Virtual Functions von QAbstractTableModel
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
@@ -70,6 +69,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Die eigentlichen Werte wohnen im tatsächlich hier, im Model.
|
||||
BCValueList _valueList;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user