diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -270,11 +270,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 +469,12 @@ */ void setSerialTimerInterval(int newTime); + /** + * @brief Set the time between checks for new Temperature (0 is default) + * @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 = nullptr; + /** sdProgressTimer: timer used to check in on sdJobs */ + QTimer *sdProgressTimer = nullptr; /** percentage: print job percent */ float percentage = 0.0; /** posString: stored string from last M114 return */ @@ -99,9 +101,6 @@ setState(AtCore::STATES::DISCONNECTED); //Create and start the timer that checks for temperature. - d->tempTimer = new QTimer(this); - d->tempTimer->setInterval(5000); - d->tempTimer->setSingleShot(false); //Attempt to find our plugins qCDebug(ATCORE_PLUGIN) << "Detecting Plugin path"; QStringList paths = AtCoreDirectories::pluginDir; @@ -222,8 +221,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); } @@ -322,6 +320,30 @@ d->serialTimer->start(newTime); } +void AtCore::setTemperatureTimerInterval(int newTime) +{ + if (newTime <= 0) { + if (d->temperatureTimer->isActive()) { + d->temperatureTimer->stop(); + } + disconnect(d->temperatureTimer, &QTimer::timeout, this, &AtCore::checkTemperature); + delete d->temperatureTimer; + d->temperatureTimer = nullptr; + return; + } + if (!d->temperatureTimer) { + //There is no timer. We need to create one. + d->temperatureTimer = new QTimer(); + connect(d->temperatureTimer, &QTimer::timeout, this, &AtCore::checkTemperature); + } + //emit the newtime if it has changed. + if (newTime != d->temperatureTimer->interval()) { + emit temperatureTimerIntervalChanged(newTime); + } + //Start the timer. + d->temperatureTimer->start(newTime); +} + void AtCore::newMessage(const QByteArray &message) { //Evaluate the messages coming from the printer. @@ -377,7 +399,9 @@ pushCommand(GCode::toCommand(GCode::MCommands::M24)); setState(AtCore::STATES::BUSY); d->sdCardPrinting = true; - connect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + d->sdProgressTimer = new QTimer(this); + d->sdProgressTimer->start(5000); + connect(d->sdProgressTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); return; } } @@ -423,8 +447,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(); @@ -458,7 +481,12 @@ if (state == AtCore::STATES::FINISHEDPRINT && d->sdCardPrinting) { //Clean up the sd card print d->sdCardPrinting = false; - disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + if (d->sdProgressTimer->isActive()) { + d->sdProgressTimer->stop(); + } + disconnect(d->sdProgressTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + delete d->sdProgressTimer; + d->sdProgressTimer = nullptr; } 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); }