diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f176f96 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +BionxControl.pro.user +build/ diff --git a/BionxControl.pro b/BionxControl.pro index 2a056bf..778c812 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -26,21 +26,21 @@ windows SOURCES += \ bccommand.cpp \ - bccommandmanager.cpp \ bccommandrunner.cpp \ bcvalue.cpp \ bcvaluemanager.cpp \ + bcvaluemodel.cpp \ main.cpp \ bcmainwindow.cpp HEADERS += \ bc.h \ bccommand.h \ - bccommandmanager.h \ bccommandrunner.h \ bcmainwindow.h \ bcvalue.h \ - bcvaluemanager.h + bcvaluemanager.h \ + bcvaluemodel.h FORMS += \ bcmainwindow.ui diff --git a/bc.h b/bc.h index 77321d3..13f0398 100644 --- a/bc.h +++ b/bc.h @@ -27,6 +27,7 @@ ***************************************************************************/ + #ifndef BC_H #define BC_H diff --git a/bccommand.cpp b/bccommand.cpp index d77f4dc..9f92b1d 100644 --- a/bccommand.cpp +++ b/bccommand.cpp @@ -27,6 +27,7 @@ ***************************************************************************/ + #include @@ -44,3 +45,5 @@ uint8_t BCCommand::getLongValue() { return 0; } + + diff --git a/bccommand.h b/bccommand.h index d4a481d..f97a66b 100644 --- a/bccommand.h +++ b/bccommand.h @@ -27,6 +27,7 @@ ***************************************************************************/ + #ifndef BCCOMMAND_H #define BCCOMMAND_H @@ -34,7 +35,6 @@ #include -class BCCommandRunner; struct BCCommand { @@ -50,6 +50,8 @@ struct BCCommand }; +class BCCommandRunner; + diff --git a/bccommandmanager.cpp b/bccommandmanager.cpp deleted file mode 100644 index f65e3e2..0000000 --- a/bccommandmanager.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - - diff --git a/bccommandmanager.h b/bccommandmanager.h deleted file mode 100644 index da90b20..0000000 --- a/bccommandmanager.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef BCCOMMANDMANAGER_H -#define BCCOMMANDMANAGER_H - - -#endif // BCCOMMANDMANAGER_H diff --git a/bcvalue.cpp b/bcvalue.cpp index 7ba0501..ac788c5 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -1,17 +1,31 @@ +/*************************************************************************** + + BionxControl + Copyright © 2025 christoph holzheuer + christoph.holzheuer@gmail.com + + Using: + + BigXionFlasher USB V 0.2.4 rev. 97 + © 2011-2013 by Thomas Koenig + @see www.bigxionflasher.org + + Bionx Bike Info + © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) + @see www.ts-soft.de + + mhs_can_drv.c 3.00 + © 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany + Demlehner Klaus, info@mhs-elektronik.de + @see www.mhs-elektronik.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 - - -BCRawValue::BCRawValue(BCDevice::ID deviceID_, BC::ID targetID_) - : deviceID{deviceID_}, targetID{targetID_} -{ -} - -void BCRawValue::setLongValue( uint8_t value) -{ - -} - -uint8_t BCRawValue::getLongValue() -{ - return 0; -} diff --git a/bcvalue.h b/bcvalue.h index 64d2c06..51efa80 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -1,25 +1,42 @@ +/*************************************************************************** + + BionxControl + Copyright © 2025 christoph holzheuer + christoph.holzheuer@gmail.com + + Using: + + BigXionFlasher USB V 0.2.4 rev. 97 + © 2011-2013 by Thomas Koenig + @see www.bigxionflasher.org + + Bionx Bike Info + © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) + @see www.ts-soft.de + + mhs_can_drv.c 3.00 + © 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany + Demlehner Klaus, info@mhs-elektronik.de + @see www.mhs-elektronik.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 + + ***************************************************************************/ + + #ifndef BCRawValue_H #define BCRawValue_H -class BCRawValueRunner; - #include +#include + #include -struct BCRawValue -{ - - BCRawValue( BCDevice::ID deviceID, BC::ID targetID ); - - void setLongValue( uint8_t value); - uint8_t getLongValue(); - - QString label; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID targetID{BC::ID::Invalid}; - -}; struct BCUnit { @@ -33,8 +50,48 @@ struct BCUnit class BCValue { +public: + + BCValue() = default; + BCValue( BCDevice::ID deviceID, BC::ID targetID ); + + void setLongValue( uint8_t value); + uint8_t getLongValue(); + + QString label; + BCDevice::ID deviceID{BCDevice::ID::Invalid}; + BC::ID targetID{BC::ID::Invalid}; + double _value{-1}; +}; + +// abbreviations: +// SOC = State Of Charge +// LMD = Last Measured Discharge +// NIP = ? + +/* + +Needed ? +#include + +template +constexpr auto to_u(E e) noexcept { + return static_cast>(e); +} +*/ + +class BCValueShort +{ + }; +class BCValueLong +{ + +}; + +using BCValueList = QList; + #endif // BCRawValue_H diff --git a/bcvalue.h.autosave b/bcvalue.h.autosave deleted file mode 100644 index 9ebe4dd..0000000 --- a/bcvalue.h.autosave +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef BCRawValue_H -#define BCRawValue_H - - -class BCRawValueRunner; - -#include -#include - -struct BCRawValue -{ - - BCRawValue( BCDevice::ID deviceID, BC::ID targetID ); - - void setLongValue( uint8_t value); - uint8_t getLongValue(); - - QString label; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID targetID{BC::ID::Invalid}; - -}; - -struct BCUnit -{ - enum class ID - { - - }; - -}; - -class BCValue -{ -public: - BCValue( BCDevice::ID deviceID, BC::ID targetID ); - - void setLongValue( uint8_t value); - uint8_t getLongValue(); - - QString label; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID targetID{BC::ID::Invalid}; - double _value{-1}; -}; - - -class BCValueShort -{ - -}; - - -class BCValueLong -{ - -}; - - -#endif // BCRawValue_H diff --git a/bcvaluemanager.cpp b/bcvaluemanager.cpp index 0d93197..a858857 100644 --- a/bcvaluemanager.cpp +++ b/bcvaluemanager.cpp @@ -1,3 +1,122 @@ -#include "bcvaluemanager.h" +/*************************************************************************** -BCValueManager::BCValueManager() {} + BionxControl + Copyright © 2025 christoph holzheuer + christoph.holzheuer@gmail.com + + Using: + + BigXionFlasher USB V 0.2.4 rev. 97 + © 2011-2013 by Thomas Koenig + @see www.bigxionflasher.org + + Bionx Bike Info + © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) + @see www.ts-soft.de + + mhs_can_drv.c 3.00 + © 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany + Demlehner Klaus, info@mhs-elektronik.de + @see www.mhs-elektronik.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 +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +BCValueManager::BCValueManager() +{} + + + +void BCValueManager::loadXml() +{ + /* + QString fileName = QFileDialog::getOpenFileName(this, "XML öffnen", "", "XML Files (*.xml)"); + if (fileName.isEmpty()) return; + + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox::warning(this, "Fehler", "Datei konnte nicht geöffnet werden."); + return; + } + + QList parsedDevices; + QXmlStreamReader xml(&file); + + while (!xml.atEnd() && !xml.hasError()) { + QXmlStreamReader::TokenType token = xml.readNext(); + if (token == QXmlStreamReader::StartElement && xml.name() == u"device") { + Device d; + d.name = xml.attributes().value(u"name").toString(); + d.ip = xml.attributes().value(u"ip").toString(); + parsedDevices.append(d); + } + } + + if (xml.hasError()) + { + QMessageBox::critical(this, "Parsing Fehler", xml.errorString()); + } else { + m_model->setDevices(parsedDevices); + } +*/ +} + + // --- NEU: Speichern mit QXmlStreamWriter --- +void BCValueManager::saveXml() +{ + /* + QString fileName = QFileDialog::getSaveFileName(this, "XML speichern", "", "XML Files (*.xml)"); + if (fileName.isEmpty()) return; + + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::warning(this, "Fehler", "Datei konnte nicht zum Schreiben geöffnet werden."); + return; + } + + QXmlStreamWriter xml(&file); + xml.setAutoFormatting(true); // Sorgt für schöne Einrückungen (Tabs/Spaces) + xml.writeStartDocument(); + xml.writeStartElement("devices"); + + // Daten vom Model holen + const QList &devices = m_model->getDevices(); + + for (const Device &d : devices) { + xml.writeStartElement("device"); + xml.writeAttribute("name", d.name); + xml.writeAttribute("ip", d.ip); + xml.writeEndElement(); // + } + + xml.writeEndElement(); // + xml.writeEndDocument(); + + // Prüfen ob alles geschrieben wurde + if (file.error() != QFile::NoError) { + QMessageBox::critical(this, "Fehler", "Fehler beim Schreiben der Datei."); + } else { + statusBar()->showMessage("Datei erfolgreich gespeichert!", 3000); + } + */ +} diff --git a/bcvaluemanager.h b/bcvaluemanager.h index 4481cff..7e26698 100644 --- a/bcvaluemanager.h +++ b/bcvaluemanager.h @@ -1,10 +1,56 @@ +/*************************************************************************** + + BionxControl + Copyright © 2025 christoph holzheuer + christoph.holzheuer@gmail.com + + Using: + + BigXionFlasher USB V 0.2.4 rev. 97 + © 2011-2013 by Thomas Koenig + @see www.bigxionflasher.org + + Bionx Bike Info + © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) + @see www.ts-soft.de + + mhs_can_drv.c 3.00 + © 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany + Demlehner Klaus, info@mhs-elektronik.de + @see www.mhs-elektronik.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 + + ***************************************************************************/ + + #ifndef BCVALUEMANAGER_H #define BCVALUEMANAGER_H -class BCValueManager +#include + +class BCValueManager : public QObject { + Q_OBJECT + public: + + BCValueManager(); + ~BCValueManager() = default; + + BCValue* makeValue(); + + void loadXml(); + void saveXml(); + +protected: + + }; #endif // BCVALUEMANAGER_H diff --git a/main.cpp b/main.cpp index 8fde3c6..6543469 100644 --- a/main.cpp +++ b/main.cpp @@ -27,16 +27,42 @@ ***************************************************************************/ -#include -#include -#include +#include +#include // main.cpp #include #include #include +#include +#include + + +/* +#include + +void parseString(const QString &inputString) { +QMetaEnum metaEnum = QMetaEnum::fromType(); + +bool ok = false; +// keyToValue parst den String ("x1") und liefert den int-Wert +int intVal = metaEnum.keyToValue(inputString.toLatin1().constData(), &ok); + +if (ok) { + BCValue::ID id = static_cast(intVal); + // Erfolg! +} else { + // Fehler: String existiert nicht im Enum + qWarning() << "Unbekannter Enum String:" << inputString; +} +} +*/ + + + + #include int main(int argc, char *argv[]) @@ -52,9 +78,27 @@ int main(int argc, char *argv[]) qDebug() << " --- sach bloss das geht: " << x << " ui: " << uint8_t(x) << " : " << map[Color::Red]; - QApplication a(argc, argv); - //BCMainWindow w; - //w.show(); - return a.exec(); + + QApplication app(argc, argv); + BCMainWindow w; + w.show(); + + QMetaEnum metaEnum = QMetaEnum::fromType(); + + bool ok = false; + QString inputString = "x3"; + BC::ID yyy{}; + + // keyToValue parst den String ("x1") und liefert den int-Wert + int intVal = metaEnum.keyToValue(inputString.toLatin1().constData(), &ok); + if (ok) + yyy = static_cast(intVal); + + auto xxx = BC::ID::Battery_Config_Force_Done; + //QString result = fullString.section("::", -1); + qDebug() << " schön: " << xxx << " -- " << uint8_t(xxx) << " : " << yyy; + qDebug() << " nice: " << metaEnum.enumName() << " : " <className(); + + return app.exec(); }