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 @@ -479,6 +498,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 @@ -64,6 +64,8 @@ int extruderCount = 1; /** temperature: Temperature object */ std::shared_ptr temperature = nullptr; + /** 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 */ @@ -349,9 +351,46 @@ } } +void AtCore::setAutoTemperatureReport(bool autoReport) +{ + if (autoReport == d->autoTemperatureReport) { + return; + } + + d->autoTemperatureReport = autoReport; + emit autoTemperatureReportChanged(autoReport); + + if (autoReport) { + setTemperatureTimerInterval(0); + d->commandQueue.removeAll(GCode::toCommand(GCode::M105)); + setAutoCheckTemperatureInterval(5); + } else { + setAutoCheckTemperatureInterval(0); + setTemperatureTimerInterval(5000); + } + +} + +void AtCore::setAutoCheckTemperatureInterval(int newTime) +{ + if (state() >= 2 && state() != AtCore::ERRORSTATE) { + pushCommand(GCode::toCommand(GCode::M155, QString::number(newTime))); + } + emit autoCheckTemperatureIntervalChanged(newTime); +} + +bool AtCore::autoTemperatureReport() const +{ + return d->autoTemperatureReport; +} + void AtCore::newMessage(const QByteArray &message) { d->lastMessage = message; + if (d->lastMessage.contains(QString::fromLatin1("Cap:AUTOREPORT_TEMP:1").toLocal8Bit())) { + setAutoTemperatureReport(true); + } + //Check if the message has current coordinates. if (d->lastCommand.startsWith(GCode::toCommand(GCode::MCommands::M114)) && d->lastMessage.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { @@ -449,9 +488,12 @@ if (firmwarePluginLoaded()) { disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); - if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { - setTemperatureTimerInterval(0); + if (d->autoTemperatureReport) { + blockSignals(true); + setAutoTemperatureReport(false); + blockSignals(false); } + setTemperatureTimerInterval(0); //Attempt to unload the firmware plugin. QString name = firmwarePlugin()->name(); QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -90,7 +90,11 @@ * @param disabled: True if items are disabled. */ void setDangeriousDocksDisabled(bool disabled); - + /** + * @brief Called when atcore changes it temperature reporting mode + * @param autoReport: True if using temperature auto reporting + */ + void updateAutoTemperatureReport(bool autoReport); private: AtCore *core; // Define max number of fans @@ -165,7 +169,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); } @@ -203,14 +204,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); @@ -556,6 +555,7 @@ if (connectionTimer->isActive()) { connectionTimer->stop(); } + sbTemperatureTimer->setValue(0); stateString = QStringLiteral("Not Connected"); buttonConnect->setText(tr("Connect")); setConnectionWidgetsEnabled(true); @@ -627,3 +627,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); + } + }); + } +}