diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -71,6 +71,7 @@ Q_PROPERTY(AtCore::STATES state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(bool sdMount READ isSdMounted WRITE setSdMounted NOTIFY sdMountChanged) Q_PROPERTY(QStringList sdFileList READ sdFileList NOTIFY sdCardFileListChanged) + Q_PROPERTY(bool autoTemperatureReport READ autoTemperatureReport WRITE setAutoTemperatureReport NOTIFY autoTemperatureReportChanged) friend class AtCoreTests; //Add friends as Sd Card support is extended to more plugins. @@ -235,6 +236,12 @@ */ bool isSdMounted() const; + /** + * @brief Check if using automatic Temperature reporting to monitor temperatures + * @return True if using automatic temperature reporting + */ + bool autoTemperatureReport() const; + signals: /** @@ -280,6 +287,18 @@ */ void temperatureTimerIntervalChanged(const int newTime); + /** + * @brief use of automatic temperature reporting has changed + * @param autoReport: True if using automatic Reporting mode. + */ + void autoTemperatureReportChanged(bool autoReport); + + /** + * @brief New interval for automatic temperature report + * @sa setautoTemperatureReport() + */ + void autoCheckTemperatureIntervalChanged(const int newTime); + /** * @brief The Printer's State Changed * @param newState : the new state of the printer @@ -474,6 +493,18 @@ */ void setTemperatureTimerInterval(int newTime); + /** @brief Set if atcore should Enable auto temperature reporting. Temperature timer will also be stopped. + * @param autoReport: True to enable automatic reporting of temperatures. + * @sa setAutoCheckTemperature + */ + void setAutoTemperatureReport(bool autoReport); + + /** + * @brief Tell the machine to start reporting its temperature automaticly + * @param newTime: Time in seconds between reports (0: disabled) + */ + Q_INVOKABLE void setAutoCheckTemperatureInterval(int newTime); + /** * @brief delete file from sd card */ diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -62,6 +62,8 @@ int extruderCount = 1; /** temperature: Temperature object */ Temperature temperature; + /** autoTemperatureReport: True if using auto Temperature Reporting*/ + bool autoTemperatureReport = false; /** commandQueue: the list of commands to send to the printer */ QStringList commandQueue; /** ready: True if printer is ready for a command */ @@ -345,10 +347,46 @@ } } +void AtCore::setAutoTemperatureReport(bool autoReport) +{ + if (autoReport == d->autoTemperatureReport) { + return; + } + emit autoTemperatureReportChanged(autoReport); + + if (autoReport) { + setTemperatureTimerInterval(0); + d->commandQueue.removeAll(GCode::toCommand(GCode::M105)); + setAutoCheckTemperatureInterval(5); + } else if (d->autoTemperatureReport) { + if (d->printerState < 2 || d->printerState == AtCore::ERRORSTATE) { + return; + } + setAutoCheckTemperatureInterval(0); + d->temperatureTimer.setInterval(5000); + } + d->autoTemperatureReport = autoReport; +} + +void AtCore::setAutoCheckTemperatureInterval(int newTime) +{ + pushCommand(GCode::toCommand(GCode::M155, QString::number(newTime))); + emit autoCheckTemperatureIntervalChanged(newTime); +} + +bool AtCore::autoTemperatureReport() const +{ + return d->autoTemperatureReport; +} + void AtCore::newMessage(const QByteArray &message) { //Evaluate the messages coming from the printer. d->lastMessage = message; + if (d->lastMessage.contains(QString::fromLatin1("Cap:AUTOREPORT_TEMP:1").toLocal8Bit())) { + setAutoTemperatureReport(true); + } + //Check if the message has current coordinates. if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { d->posString = message; @@ -445,7 +483,7 @@ if (firmwarePluginLoaded()) { disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); - if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { + if (firmwarePlugin()->name() != QStringLiteral("Grbl") && !d->autoTemperatureReport) { setTemperatureTimerInterval(0); } //Attempt to unload the firmware plugin. @@ -461,6 +499,9 @@ //Clear our copy of the sdcard filelist clearSdCardFileList(); setState(AtCore::STATES::DISCONNECTED); + if (d->autoTemperatureReport) { + setAutoTemperatureReport(false); + } d->serialTimer.start(); } } diff --git a/src/core/gcodecommands.h b/src/core/gcodecommands.h --- a/src/core/gcodecommands.h +++ b/src/core/gcodecommands.h @@ -70,7 +70,7 @@ M120, M121, M122, M123, M124, M126 = 126, M127, M128, M129, M130, M131, M132, M133, M134, M135, M136, M140 = 140, M141, M142, M143, M144, M146 = 146, M149 = 149, - M150 = 150, + M150 = 150, M155 = 155, M160 = 160, M163 = 163, M164 = 164, M190 = 190, M191, M200 = 200, M201, M202, M203, M204, M205, M206, M207, M208, M209, diff --git a/src/core/gcodecommands.cpp b/src/core/gcodecommands.cpp --- a/src/core/gcodecommands.cpp +++ b/src/core/gcodecommands.cpp @@ -251,6 +251,8 @@ return QObject::tr("M144: Stand by your bed"); case M150://Marlin return QObject::tr("M150: Set display color"); + case M155: //Look for Cap:AUTOREPORT_TEMP:1 in M115 to check for support + return QObject::tr("M155: Set Temperature auto report"); case M163://Repetier > 0.92 return QObject::tr("M163: Set weight of mixed material"); case M164://Repetier > 0.92 @@ -524,6 +526,7 @@ case M109: case M140: + case M155: case M190: case M220: case M221: diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -90,7 +90,10 @@ * @param disabled: True if items are disabled. */ void setDangeriousDocksDisabled(bool disabled); - + /** + * @brief Called when atcore changes it temperature reporting mode + */ + void updateAutoTemperatureReport(bool autoReport); private: AtCore *core; // Define max number of fans @@ -165,7 +168,7 @@ QPushButton *buttonConnect = nullptr; QCheckBox *cbReset = nullptr; QTimer *connectionTimer = nullptr; - + QSpinBox *sbTemperatureTimer = nullptr; void makeMoveDock(); QDockWidget *moveDock = nullptr; MovementWidget *movementWidget = nullptr; diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -54,6 +54,7 @@ connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); + connect(core, &AtCore::autoTemperatureReportChanged, this, &MainWindow::updateAutoTemperatureReport); comboPort->setFocus(Qt::OtherFocusReason); } @@ -199,14 +200,12 @@ auto timerLayout = new QHBoxLayout; auto lblTimer = new QLabel(tr("Seconds Between Temperature Checks"), this); - auto sbTemperatureTimer = new QSpinBox(this); + sbTemperatureTimer = new QSpinBox(this); sbTemperatureTimer->setRange(0, 90); - connect(sbTemperatureTimer, QOverload::of(&QSpinBox::valueChanged), this, [this](int value) { core->setTemperatureTimerInterval(value * 1000); }); - - connect(core, &AtCore::temperatureTimerIntervalChanged, this, [sbTemperatureTimer](int value) { + connect(core, &AtCore::temperatureTimerIntervalChanged, this, [this](int value) { if (value != sbTemperatureTimer->value()) { sbTemperatureTimer->blockSignals(true); sbTemperatureTimer->setValue(value / 1000); @@ -552,6 +551,7 @@ if (connectionTimer->isActive()) { connectionTimer->stop(); } + sbTemperatureTimer->setValue(0); stateString = QStringLiteral("Not Connected"); buttonConnect->setText(tr("Connect")); setConnectionWidgetsEnabled(true); @@ -623,3 +623,34 @@ comboPlugin->setEnabled(enabled); comboPort->setEnabled(enabled); } + +void MainWindow::updateAutoTemperatureReport(bool autoReport) +{ + disconnect(sbTemperatureTimer, QOverload::of(&QSpinBox::valueChanged), this, {}); + disconnect(core, &AtCore::temperatureTimerIntervalChanged, this, {}); + disconnect(core, &AtCore::autoCheckTemperatureIntervalChanged, this, {}); + + if (autoReport) { + connect(sbTemperatureTimer, QOverload::of(&QSpinBox::valueChanged), this, [this](int value) { + core->setAutoCheckTemperatureInterval(value); + }); + connect(core, &AtCore::autoCheckTemperatureIntervalChanged, this, [this](int value) { + if (value != sbTemperatureTimer->value()) { + sbTemperatureTimer->blockSignals(true); + sbTemperatureTimer->setValue(value); + sbTemperatureTimer->blockSignals(false); + } + }); + } else { + connect(sbTemperatureTimer, QOverload::of(&QSpinBox::valueChanged), this, [this](int value) { + core->setTemperatureTimerInterval(value * 1000); + }); + connect(core, &AtCore::temperatureTimerIntervalChanged, this, [this](int value) { + if (value != sbTemperatureTimer->value()) { + sbTemperatureTimer->blockSignals(true); + sbTemperatureTimer->setValue(value / 1000); + sbTemperatureTimer->blockSignals(false); + } + }); + } +} diff --git a/unittests/gcodetests.h b/unittests/gcodetests.h --- a/unittests/gcodetests.h +++ b/unittests/gcodetests.h @@ -58,6 +58,7 @@ void command_M117(); void command_M119(); void command_M140(); + void command_M155(); void command_M190(); void command_M220(); void command_M221(); diff --git a/unittests/gcodetests.cpp b/unittests/gcodetests.cpp --- a/unittests/gcodetests.cpp +++ b/unittests/gcodetests.cpp @@ -207,6 +207,12 @@ QVERIFY(GCode::toCommand(GCode::M140, QStringLiteral("100")) == QStringLiteral("M140 S100")); } +void GCodeTests::command_M155() +{ + QVERIFY(testMCodeNeedsArg(GCode::M155)); + QVERIFY(GCode::toCommand(GCode::M155, QStringLiteral("1")) == QStringLiteral("M155 S1")); +} + void GCodeTests::command_M190() { QVERIFY(testMCodeNeedsArg(GCode::M190));