diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,7 @@ ifirmware.cpp temperature.cpp printthread.cpp + machineinfo.cpp ) add_library(AtCore SHARED ${AtCoreLib_SRCS}) @@ -40,6 +41,7 @@ IFirmware SerialLayer Temperature + MachineInfo REQUIRED_HEADERS ATCORE_HEADERS ) diff --git a/src/core/machineinfo.h b/src/core/machineinfo.h new file mode 100644 --- /dev/null +++ b/src/core/machineinfo.h @@ -0,0 +1,84 @@ +/* AtCore + Copyright (C) <2019> + + Authors: + Chris Rizzitello + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#pragma once + +#include +#include + +class MachineInfo : public QObject +{ + Q_OBJECT +public: + /** + * @brief KEYS enum Possible keys for the printer settings + */ + enum KEY { + NAME, //!< Profile Name + BAUDRATE, //!< Machine BAUD Rate + FIRMWARE, //! &profile) const; + Q_INVOKABLE QStringList profileNames() const; + +signals: + /** + * @brief A profile has changed + * @param changedProfileName: name of changed profile. + */ + void profileChanged(const QString &changedProfileName) const; + +private: + explicit MachineInfo(QObject *parent = nullptr); + /** + * @brief Map of MachineInfo::KEY -> QString + */ + static const QMap nameMap; + + /** + * @brief m_settings our settings object. + */ + QSettings *m_settings = nullptr; + +}; diff --git a/src/core/machineinfo.cpp b/src/core/machineinfo.cpp new file mode 100644 --- /dev/null +++ b/src/core/machineinfo.cpp @@ -0,0 +1,105 @@ +/* AtCore + Copyright (C) <2019> + + Authors: + Chris Rizzitello + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "machineinfo.h" + +#include +#include +#include +#include + +const QMap MachineInfo::nameMap = { + {NAME, QStringLiteral("Name")} + , {BAUDRATE, QStringLiteral("bps")} + , {FIRMWARE, QStringLiteral("firmware")} + , {MAXBEDTEMP, QStringLiteral("maximumTemperatureBed")} + , {MAXEXTTEMP, QStringLiteral("maximumTemperatureExtruder")} + , {POSTPAUSE, QStringLiteral("postPause")} + , {HEATEDBED, QStringLiteral("heatedBed")} + , {ISCARTESIAN, QStringLiteral("isCartesian")} + , {XMAX, QStringLiteral("dimensionX")} + , {YMAX, QStringLiteral("dimensionY")} + , {ZMAX, QStringLiteral("dimensionZ")} + , {AUTOTEMPREPORT, QStringLiteral("autoReportTemp")} +}; + +const MachineInfo &MachineInfo::getInstance() +{ + static MachineInfo m; + return m; +} + +MachineInfo::MachineInfo(QObject *parent) : QObject(parent) +{ + if (QFile(QString(QCoreApplication::applicationDirPath() + QDir::separator() + QStringLiteral("profiles.ini"))).exists()) { + m_settings = new QSettings(QCoreApplication::applicationDirPath() + QDir::separator() + QStringLiteral("profiles"), QSettings::IniFormat, this); + } else { + m_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral("atcore"), QStringLiteral("profiles"), this); + } +} + +QVariantMap MachineInfo::profile(const QString &profileName) const +{ + m_settings->beginGroup(profileName); + QVariantMap data{ + {nameMap[BAUDRATE], m_settings->value(nameMap[BAUDRATE], QStringLiteral("115200"))} + , {nameMap[MAXBEDTEMP], m_settings->value(nameMap[MAXBEDTEMP], QStringLiteral("0"))} + , {nameMap[MAXEXTTEMP], m_settings->value(nameMap[MAXEXTTEMP], QStringLiteral("0"))} + , {nameMap[FIRMWARE], m_settings->value(nameMap[FIRMWARE], QStringLiteral("Auto-Detect"))} + , {nameMap[POSTPAUSE], m_settings->value(nameMap[POSTPAUSE], QString())} + , {nameMap[HEATEDBED], m_settings->value(nameMap[HEATEDBED], true)} + , {nameMap[NAME], m_settings->group()} + , {nameMap[ISCARTESIAN], m_settings->value(nameMap[ISCARTESIAN], true)} + , {nameMap[XMAX], m_settings->value(nameMap[XMAX], QStringLiteral("200"))} + , {nameMap[YMAX], m_settings->value(nameMap[YMAX], QStringLiteral("200"))} + , {nameMap[ZMAX], m_settings->value(nameMap[ZMAX], QStringLiteral("180"))} + , {nameMap[AUTOTEMPREPORT], m_settings->value(nameMap[AUTOTEMPREPORT], false)} + }; + m_settings->endGroup(); + return data; +} + +void MachineInfo::storeProfile(const QMap &profile) const +{ + m_settings->beginGroup(profile[NAME].toString()); + m_settings->setValue(nameMap[FIRMWARE], profile[FIRMWARE]); + m_settings->setValue(nameMap[BAUDRATE], profile[BAUDRATE]); + m_settings->setValue(nameMap[MAXBEDTEMP], profile[MAXBEDTEMP]); + m_settings->setValue(nameMap[MAXEXTTEMP], profile[MAXEXTTEMP]); + m_settings->setValue(nameMap[POSTPAUSE], profile[POSTPAUSE]); + m_settings->setValue(nameMap[HEATEDBED], profile[HEATEDBED]); + m_settings->setValue(nameMap[ISCARTESIAN], profile[ISCARTESIAN]); + m_settings->setValue(nameMap[XMAX], profile[XMAX]); + m_settings->setValue(nameMap[YMAX], profile[YMAX]); + m_settings->setValue(nameMap[ZMAX], profile[ZMAX]); + m_settings->setValue(nameMap[AUTOTEMPREPORT], profile[AUTOTEMPREPORT]); + m_settings->endGroup(); + emit profileChanged(profile[NAME].toString()); +} + +QStringList MachineInfo::profileNames() const +{ + QStringList groups = m_settings->childGroups(); + return groups; +} + diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -417,7 +417,7 @@ break; case 0x02: // extruder - msg = QString::fromLatin1("Extruder[%1] Temperature").arg(QString::number(number));; + msg = QString::fromLatin1("Extruder[%1] Temperature").arg(QString::number(number)); break; case 0x03: // extruder target