diff --git a/src/atcore.h b/src/atcore.h --- a/src/atcore.h +++ b/src/atcore.h @@ -61,22 +61,14 @@ METRIC, IMPERIAL }; -//TODO: PrinterStatus should also move to d->pointer; -struct KATCORE_EXPORT PrinterStatus { - float percentage; - QByteArray posString; - Temperature temps; - PrinterState printerState; -}; - class KATCORE_EXPORT AtCore : public QObject { Q_OBJECT public: AtCore(QObject *parent = nullptr); QList serialPorts() const; void initSerial(const QString &port, int baud); - bool isInitialized(); + bool isInitialized() const; void setSerial(SerialLayer *serial); SerialLayer *serial() const; void setPlugin(IFirmware *plugin); @@ -98,12 +90,12 @@ * @brief extruderCount * @return The number of detected Extruders Default is 1 */ - int extruderCount(); + int extruderCount() const; /** * @brief Return true if plugin is loaded */ - bool pluginLoaded(); + bool pluginLoaded() const; /** * @brief Request firmware sending M115 command @@ -113,12 +105,12 @@ /** * @brief Return printed percentage */ - float percentagePrinted(); + float percentagePrinted() const; /** * @brief Request a list of firmware plugins */ - QStringList availablePlugins(); + QStringList availablePlugins() const; /** * @brief Load A firmware @@ -137,7 +129,7 @@ * * @return QByteArray */ - QByteArray popCommand(); + QByteArray popCommand() const; /** * @brief Close the serial connection diff --git a/src/atcore.cpp b/src/atcore.cpp --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -49,12 +49,15 @@ QDir pluginsDir; QMap plugins; QByteArray lastMessage; - PrinterStatus printerStatus; int extruderCount = 1; Temperature temperature; QStringList commandQueue; bool ready = false; QTimer *tempTimer = nullptr; + float percentage; + QByteArray posString; + Temperature temps; + PrinterState printerState; }; AtCore::AtCore(QObject *parent) : @@ -212,7 +215,7 @@ connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); } -bool AtCore::isInitialized() +bool AtCore::isInitialized() const { if (!d->serial) { return false; @@ -229,9 +232,9 @@ { d->lastMessage = message; if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { - d->printerStatus.posString = message; - d->printerStatus.posString.resize(d->printerStatus.posString.indexOf('E')); - d->printerStatus.posString.replace(':', ""); + d->posString = message; + d->posString.resize(d->posString.indexOf('E')); + d->posString.replace(':', ""); } //Check if have temperature info and decode it @@ -249,9 +252,9 @@ pushCommand(GCode::toCommand(GCode::G90)); } -float AtCore::percentagePrinted() +float AtCore::percentagePrinted() const { - return d->printerStatus.percentage; + return d->percentage; } void AtCore::print(const QString &fileName) @@ -302,20 +305,20 @@ PrinterState AtCore::state(void) { - return d->printerStatus.printerState; + return d->printerState; } void AtCore::setState(PrinterState state) { - if (state != d->printerStatus.printerState) { + if (state != d->printerState) { qCDebug(ATCORE_CORE) << "Atcore state changed from [" \ - << d->printerStatus.printerState << "] to [" << state << "]"; - d->printerStatus.printerState = state; - emit(stateChanged(d->printerStatus.printerState)); + << d->printerState << "] to [" << state << "]"; + d->printerState = state; + emit(stateChanged(d->printerState)); } } -QByteArray AtCore::popCommand() +QByteArray AtCore::popCommand() const { return serial()->popCommand(); } @@ -348,7 +351,7 @@ } } -bool AtCore::pluginLoaded() +bool AtCore::pluginLoaded() const { if (plugin()) { return true; @@ -388,7 +391,7 @@ qCDebug(ATCORE_CORE) << tr("plugins[%1]=%2").arg(file, pluginString); } } -QStringList AtCore::availablePlugins() +QStringList AtCore::availablePlugins() const { return d->plugins.keys(); } @@ -413,7 +416,7 @@ void AtCore::resume() { - pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->printerStatus.posString))); + pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->posString))); setState(BUSY); } @@ -482,7 +485,7 @@ } } -int AtCore::extruderCount() +int AtCore::extruderCount() const { return d->extruderCount; } diff --git a/src/seriallayer.h b/src/seriallayer.h --- a/src/seriallayer.h +++ b/src/seriallayer.h @@ -110,19 +110,19 @@ * * @return bool */ - bool commandAvailable(); + bool commandAvailable() const; /** * @brief Return FIFO command from printer * * @return QByteArray */ - QByteArray popCommand(); + QByteArray popCommand() const; /** * @brief Return a QStringList of valids serial baud rates * * @return QStringList */ - QStringList validBaudRates(); + QStringList validBaudRates() const; }; diff --git a/src/seriallayer.cpp b/src/seriallayer.cpp --- a/src/seriallayer.cpp +++ b/src/seriallayer.cpp @@ -124,17 +124,17 @@ d->_sByteCommands.clear(); } -QByteArray SerialLayer::popCommand() +QByteArray SerialLayer::popCommand() const { return commandAvailable() ? d->_rByteCommands.takeFirst() : QByteArray(); } -bool SerialLayer::commandAvailable() +bool SerialLayer::commandAvailable() const { return !d->_rByteCommands.isEmpty(); } -QStringList SerialLayer::validBaudRates() +QStringList SerialLayer::validBaudRates() const { return _validBaudRates; }