diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -63,6 +63,7 @@ Q_PROPERTY(QString version READ version) Q_PROPERTY(QStringList availableFirmwarePlugins READ availableFirmwarePlugins) Q_PROPERTY(int extruderCount READ extruderCount WRITE setExtruderCount NOTIFY extruderCountChanged) + Q_PROPERTY(int temperatureTimerInterval READ temperatureTimerInterval WRITE setTemperatureTimerInterval NOTIFY temperatureTimerIntervalChanged); Q_PROPERTY(int serialTimerInterval READ serialTimerInterval WRITE setSerialTimerInterval NOTIFY serialTimerIntervalChanged) Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY portsChanged) Q_PROPERTY(float percentagePrinted READ percentagePrinted NOTIFY printProgressChanged) @@ -212,6 +213,11 @@ */ int serialTimerInterval() const; + /** + * @brief Return the amount of miliseconds the temperatureTimer is set to. 0 = Disabled + */ + int temperatureTimerInterval() const; + /** * @brief Attempt to Mount an sd card * @param slot: Sd card Slot on machine (0 is default) @@ -270,11 +276,17 @@ void receivedMessage(const QByteArray &message); /** - * @brief New interval between serial timer + * @brief New interval for serial timer * @sa setSerialTimerInterval() */ void serialTimerIntervalChanged(const int newTime); + /** + * @brief New interval for temperature timer + * @sa setTemperatureTimerInterval() + */ + void temperatureTimerIntervalChanged(const int newTime); + /** * @brief The Printer's State Changed * @param newState : the new state of the printer @@ -463,6 +475,12 @@ */ void setSerialTimerInterval(int newTime); + /** + * @brief Set the time between checks for new Temperature (5000 is default on new connections) + * @param newTime: Milliseconds between checks. values <= 0 will Disable Checks. + */ + void setTemperatureTimerInterval(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 @@ -66,8 +66,10 @@ QStringList commandQueue; /** ready: True if printer is ready for a command */ bool ready = false; - /** tempTimer: timer connected to the checkTemperature function */ - QTimer *tempTimer = nullptr; + /** temperatureTimer: timer connected to the checkTemperature function */ + QTimer temperatureTimer; + /** sdPrintProgressTimer: timer used to check in on sdJobs */ + QTimer sdPrintProgressTimer; /** percentage: print job percent */ float percentage = 0.0; /** posString: stored string from last M114 return */ @@ -97,11 +99,10 @@ //Register MetaTypes qRegisterMetaType("AtCore::STATES"); setState(AtCore::STATES::DISCONNECTED); + //Connect our Timers + connect(&d->sdPrintProgressTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); connect(&d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); - //Create and start the timer that checks for temperature. - d->tempTimer = new QTimer(this); - d->tempTimer->setInterval(5000); - d->tempTimer->setSingleShot(false); + connect(&d->temperatureTimer, &QTimer::timeout, this, &AtCore::checkTemperature); //Attempt to find our plugins qCDebug(ATCORE_PLUGIN) << "Detecting Plugin path"; QStringList paths = AtCoreDirectories::pluginDir; @@ -222,8 +223,7 @@ connect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); d->ready = true; // ready on new firmware load if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { - connect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); - d->tempTimer->start(); + setTemperatureTimerInterval(5000); } setState(IDLE); } @@ -314,6 +314,24 @@ } } +int AtCore::temperatureTimerInterval() const +{ + return d->temperatureTimer.interval(); +} + +void AtCore::setTemperatureTimerInterval(int newTime) +{ + newTime = std::max(newTime, 0); + if (newTime != d->temperatureTimer.interval()) { + emit temperatureTimerIntervalChanged(newTime); + } + if (newTime == 0) { + d->temperatureTimer.stop(); + } else { + d->temperatureTimer.start(newTime); + } +} + void AtCore::newMessage(const QByteArray &message) { //Evaluate the messages coming from the printer. @@ -369,7 +387,7 @@ pushCommand(GCode::toCommand(GCode::MCommands::M24)); setState(AtCore::STATES::BUSY); d->sdCardPrinting = true; - connect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + d->sdPrintProgressTimer.start(5000); return; } } @@ -415,8 +433,7 @@ disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { - disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); - d->tempTimer->stop(); + setTemperatureTimerInterval(0); } //Attempt to unload the firmware plugin. QString name = firmwarePlugin()->name(); @@ -450,7 +467,7 @@ if (state == AtCore::STATES::FINISHEDPRINT && d->sdCardPrinting) { //Clean up the sd card print d->sdCardPrinting = false; - disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + d->sdPrintProgressTimer.stop(); } emit stateChanged(d->printerState); } 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); + comboPort->setFocus(Qt::OtherFocusReason); } void MainWindow::initMenu() @@ -196,8 +197,35 @@ plotWidget->appendPoint(tr("Target Ext.1"), temp); }); + auto timerLayout = new QHBoxLayout; + auto lblTimer = new QLabel(tr("Seconds Between Temperature Checks"), this); + auto 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) { + if (value != sbTemperatureTimer->value()) { + sbTemperatureTimer->blockSignals(true); + sbTemperatureTimer->setValue(value / 1000); + sbTemperatureTimer->blockSignals(false); + } + }); + + timerLayout->addWidget(lblTimer); + timerLayout->addWidget(sbTemperatureTimer); + + auto tempDockLayout = new QVBoxLayout; + tempDockLayout->addWidget(plotWidget); + tempDockLayout->addLayout(timerLayout); + + auto tempDockMainWidget = new QWidget(this); + tempDockMainWidget->setLayout(tempDockLayout); + tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); - tempTimelineDock->setWidget(plotWidget); + tempTimelineDock->setWidget(tempDockMainWidget); menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); }