diff --git a/src/core/temperature.cpp b/src/core/temperature.cpp index d30ad24..575e150 100644 --- a/src/core/temperature.cpp +++ b/src/core/temperature.cpp @@ -1,166 +1,154 @@ /* AtCore Copyright (C) <2016> Authors: Tomaz Canabrava Patrick José Pereira Chris Rizzitello This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include #include #include "temperature.h" /** * @brief The TemperaturePrivate class * * Private Data of Temperature */ struct Temperature::TemperaturePrivate { /** Regex to capture Bed Temperature. Looks for B: then grabs ##.## */ static const QRegularExpression bedRegEx; /** bedTemp: Bed current temperature */ float bedTemp = 0.0; /** bedTargetTemp: Bed target temperature */ float bedTargetTemp = 0.0; /** extruderTemp: Extruder current temperature */ float extruderTemp = 0.0; /** extruderTargetTemp: Extruder target temperature */ float extruderTargetTemp = 0.0; /** Regex to capture Bed Target Temperature: Find B:## /## and grab the second set of numbers */ static const QRegularExpression targetBedRegEx; /** Regex to capture Extruder Target Temperature Finds T:## /## and grabs the second set of numbers */ static const QRegularExpression targetTempRegEx; /** Regex to capture Extruder Temperature. Looks for T: then grabs ##.## */ static const QRegularExpression tempRegEx; }; /** * @brief Temperature::TemperaturePrivate::bedRegEx * Look for B: capture Any int or float as "bed" * Examples: * B: 25.0/50.0 (Captures 25.0) * B: 25/50 (Captures 25) */ const QRegularExpression Temperature::TemperaturePrivate::bedRegEx = QRegularExpression(QStringLiteral(R"(B:(?\d+\.?\d*))")); /** * @brief Temperature::TemperaturePrivate::targetBedRegEx * Look for B: [anything ] /. Capture any int or float after the '/' as "bedTarget" * Examples: * B: 25.0 /50.0 (Captures 50.0) * B: 25/50 (Captures 50) */ const QRegularExpression Temperature::TemperaturePrivate::targetBedRegEx = QRegularExpression(QStringLiteral(R"(B:[^\/]*\/(?\d+\.?\d*))")); /** * @brief Temperature::TemperaturePrivate::targetTempRegEx * Look for T: [anything ] /. Capture any int or float after the '/' as "extruderTarget" * Examples: * T: 25.0 /50.0 (Captures 50.0) * T: 25/50 (Captures 50) */ const QRegularExpression Temperature::TemperaturePrivate::targetTempRegEx = QRegularExpression(QStringLiteral(R"(T:[^\/]*\/(?\d+\.?\d*))")); /** * @brief Temperature::TemperaturePrivate::tempRegEx * Look for T: capture Any int or float as "extruder" * Examples: * T: 25.0 /50 (Captures 25.0) * T: 25/50 (Captures 25) */ const QRegularExpression Temperature::TemperaturePrivate::tempRegEx = QRegularExpression(QStringLiteral(R"(T:(?\d+\.?\d*))")); Temperature::Temperature(QObject *parent) : QObject(parent) , d(new TemperaturePrivate) { } float Temperature::bedTargetTemperature() const { return d->bedTargetTemp; } float Temperature::bedTemperature() const { return d->bedTemp; } float Temperature::extruderTargetTemperature() const { return d->extruderTargetTemp; } float Temperature::extruderTemperature() const { return d->extruderTemp; } -void Temperature::setBedTargetTemperature(float temp) -{ - d->bedTargetTemp = temp; - emit bedTargetTemperatureChanged(temp); -} - -void Temperature::setBedTemperature(float temp) -{ - d->bedTemp = temp; - emit bedTemperatureChanged(temp); -} - -void Temperature::setExtruderTargetTemperature(float temp) -{ - d->extruderTargetTemp = temp; - emit extruderTargetTemperatureChanged(temp); -} - -void Temperature::setExtruderTemperature(float temp) -{ - d->extruderTemp = temp; - emit extruderTemperatureChanged(temp); -} - void Temperature::decodeTemp(const QByteArray &msg) { QString msgString = QString::fromLatin1(msg); QRegularExpressionMatch tempCheck = d->tempRegEx.match(msgString); QRegularExpressionMatch targetTempCheck = d->targetTempRegEx.match(msgString); if (tempCheck.hasMatch()) { - setExtruderTemperature(tempCheck.captured(QStringLiteral("extruder")).toFloat()); + d->extruderTemp = tempCheck.captured(QStringLiteral("extruder")).toFloat(); + emit extruderTemperatureChanged(); } if (targetTempCheck.hasMatch()) { - setExtruderTargetTemperature(targetTempCheck.captured(QStringLiteral("extruderTarget")).toFloat()); + d->extruderTargetTemp = targetTempCheck.captured(QStringLiteral("extruderTarget")).toFloat(); + emit extruderTargetTemperatureChanged(); } if (msg.indexOf(QStringLiteral("B:")) != -1) { QRegularExpressionMatch bedCheck = d->bedRegEx.match(msgString); QRegularExpressionMatch targetBedCheck = d->targetBedRegEx.match(msgString); if (bedCheck.hasMatch()) { - setBedTemperature(bedCheck.captured(QStringLiteral("bed")).toFloat()); + d->bedTemp = bedCheck.captured(QStringLiteral("bed")).toFloat(); + emit bedTemperatureChanged(); } if (targetBedCheck.hasMatch()) { - setBedTargetTemperature(targetBedCheck.captured(QStringLiteral("bedTarget")).toFloat()); + d->bedTargetTemp = targetBedCheck.captured(QStringLiteral("bedTarget")).toFloat(); + emit bedTargetTemperatureChanged(); } } } + +void Temperature::resetData() +{ + d->extruderTemp = 0.0; + d->extruderTargetTemp = 0.0; + d->bedTemp = 0.0; + d->bedTargetTemp = 0.0; +} diff --git a/src/core/temperature.h b/src/core/temperature.h index b4f76b2..13a11cc 100644 --- a/src/core/temperature.h +++ b/src/core/temperature.h @@ -1,129 +1,107 @@ /* AtCore Copyright (C) <2016> Authors: Tomaz Canabrava Patrick José Pereira This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #pragma once #include #include "atcore_export.h" /** * @brief The Temperature class * * Read and hold the Temperature info for the printer */ class ATCORE_EXPORT Temperature : public QObject { Q_OBJECT - Q_PROPERTY(float bedTemperature READ bedTemperature WRITE setBedTemperature NOTIFY bedTemperatureChanged) - Q_PROPERTY(float bedTargetTemperature READ bedTargetTemperature WRITE setBedTargetTemperature NOTIFY bedTargetTemperatureChanged) - Q_PROPERTY(float extruderTemperature READ extruderTemperature WRITE setExtruderTemperature NOTIFY extruderTemperatureChanged) - Q_PROPERTY(float extruderTargetTemperature READ extruderTargetTemperature WRITE setExtruderTargetTemperature NOTIFY extruderTargetTemperatureChanged) + Q_PROPERTY(float bedTemperature READ bedTemperature NOTIFY bedTemperatureChanged) + Q_PROPERTY(float bedTargetTemperature READ bedTargetTemperature NOTIFY bedTargetTemperatureChanged) + Q_PROPERTY(float extruderTemperature READ extruderTemperature NOTIFY extruderTemperatureChanged) + Q_PROPERTY(float extruderTargetTemperature READ extruderTargetTemperature NOTIFY extruderTargetTemperatureChanged) + + friend class TemperatureTests; public: /** * @brief Create a new Temperature object * @param parent */ explicit Temperature(QObject *parent = nullptr); /** * @brief Get bed current temperature */ float bedTemperature() const; /** * @brief Get bed target temperature */ float bedTargetTemperature() const; - /** - * @brief Get extruder temperature - */ - float extruderTemperature() const; - - /** - * @brief Get extruder target temperature - */ - float extruderTargetTemperature() const; - /** * @brief decode Temp values from string \p msg * @param msg: string to read vaules from */ void decodeTemp(const QByteArray &msg); -public slots: /** - * @brief Set bed temperature - * @param temp: bed temperature - */ - void setBedTemperature(float temp); - - /** - * @brief Set bed target temperature - * @param temp: bed target temperature + * @brief Get extruder temperature */ - void setBedTargetTemperature(float temp); + float extruderTemperature() const; /** - * @brief Set exturder temperature - * @param temp: bed temperature + * @brief Get extruder target temperature */ - void setExtruderTemperature(float temp); - - /** - * @brief Set extruder target temperature - * @param temp: extruder target temperature - */ - void setExtruderTargetTemperature(float temp); + float extruderTargetTemperature() const; signals: /** * @brief bed temperature has changed - * @param temp : new bed temperature */ - void bedTemperatureChanged(float temp); + void bedTemperatureChanged(); /** * @brief bed target temperature has changed - * @param temp : new bed target temperature */ - void bedTargetTemperatureChanged(float temp); + void bedTargetTemperatureChanged(); /** * @brief extruder temperature has changed - * @param temp : new extruder temperature */ - void extruderTemperatureChanged(float temp); + void extruderTemperatureChanged(); /** * @brief extruder target temperature has changed - * @param temp : new extruder target temperature */ - void extruderTargetTemperatureChanged(float temp); + void extruderTargetTemperatureChanged(); +protected: + /** + * @brief Reset internal temperature data, For Tests-Only + */ + void resetData(); private: struct TemperaturePrivate; TemperaturePrivate *d; }; diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp index bc5bac0..d0be87e 100644 --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -1,625 +1,629 @@ /* AtCore Test Client Copyright (C) <2016 - 2019> Authors: Patrick José Pereira Lays Rodrigues Chris Rizzitello Tomaz Canabrava This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include "mainwindow.h" #include "seriallayer.h" #include "gcodecommands.h" #include "about.h" Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") int MainWindow::fanCount = 4; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), core(new AtCore(this)) { setWindowTitle(tr("AtCore - Test Client")); setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); QCoreApplication::setApplicationVersion(core->version()); initMenu(); initStatusBar(); initWidgets(); connect(core, &AtCore::atcoreMessage, logWidget, &LogWidget::appendLog); logWidget->appendLog(tr("Attempting to locate Serial Ports")); core->setSerialTimerInterval(1000); 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() { QMenu *menuFile = new QMenu(tr("File")); QAction *actionQuit = new QAction(style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Quit")); connect(actionQuit, &QAction::triggered, this, &MainWindow::close); menuFile->addAction(actionQuit); menuView = new QMenu(tr("View")); QAction *actionShowDockTitles = new QAction(tr("Show Dock Titles")); actionShowDockTitles->setCheckable(true); actionShowDockTitles->setChecked(true); connect(actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); menuView->addAction(actionShowDockTitles); QMenu *menuHelp = new QMenu(tr("Help")); QAction *actionAbout = new QAction(tr("About")); actionAbout->setShortcut(QKeySequence(Qt::Key_F1)); connect(actionAbout, &QAction::triggered, this, [] { auto *dialog = new About; dialog->exec(); }); menuHelp->addAction(actionAbout); menuBar()->addMenu(menuFile); menuBar()->addMenu(menuView); menuBar()->addMenu(menuHelp); } void MainWindow::initStatusBar() { statusWidget = new StatusWidget; connect(statusWidget, &StatusWidget::stopPressed, core, &AtCore::stop); connect(core, &AtCore::printProgressChanged, statusWidget, &StatusWidget::updatePrintProgress); connect(core, &AtCore::sdMountChanged, statusWidget, &StatusWidget::setSD); statusBar()->addPermanentWidget(statusWidget, 100); } void MainWindow::initWidgets() { //Make the Docks makeCommandDock(); makePrintDock(); makeTempTimelineDock(); makeLogDock(); makeConnectDock(); makeMoveDock(); makeTempControlsDock(); makeSdDock(); setDangeriousDocksDisabled(true); setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); tabifyDockWidget(moveDock, tempControlsDock); tabifyDockWidget(moveDock, sdDock); moveDock->raise(); tabifyDockWidget(connectDock, printDock); tabifyDockWidget(connectDock, commandDock); connectDock->raise(); setCentralWidget(nullptr); //More Gui stuff //hide the printing progress bar. statusWidget->showPrintArea(false); } void MainWindow::makeCommandDock() { commandWidget = new CommandWidget; //Connect the commandPressed signal connect(commandWidget, &CommandWidget::commandPressed, [this](const QString & command) { core->pushCommand(command); }); //Connect the messagePressed signal connect(commandWidget, &CommandWidget::messagePressed, [this](const QString & message) { core->showMessage(message); }); //Create the dock, and set the Widget. commandDock = new QDockWidget(tr("Commands"), this); commandDock->setWidget(commandWidget); //Push the toggle view action into our view menu menuView->insertAction(nullptr, commandDock->toggleViewAction()); //Place the Dock into a DockWidget Area. //Failure todo this will create some odd side effects at runtime addDockWidget(Qt::LeftDockWidgetArea, commandDock); } void MainWindow::makePrintDock() { printWidget = new PrintWidget; connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); connect(printWidget, &PrintWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); connect(printWidget, &PrintWidget::printSpeedChanged, this, [this](const int speed) { core->setPrinterSpeed(uint(std::max(1, speed))); }); connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { core->setFlowRate(uint(std::max(1, rate))); }); printDock = new QDockWidget(tr("Print"), this); printDock->setWidget(printWidget); menuView->insertAction(nullptr, printDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, printDock); } void MainWindow::makeTempTimelineDock() { plotWidget = new PlotWidget; //make and connect our plots in the widget. plotWidget->addPlot(tr("Actual Bed")); - connect(core->temperature().get(), &Temperature::bedTemperatureChanged, this, [this](float temp) { + connect(core->temperature().get(), &Temperature::bedTemperatureChanged, this, [this] { + float temp = core->temperature().get()->bedTemperature(); checkTemperature(0x00, 0, temp); plotWidget->appendPoint(tr("Actual Bed"), temp); }); plotWidget->addPlot(tr("Target Bed")); - connect(core->temperature().get(), &Temperature::bedTargetTemperatureChanged, this, [this](float temp) { + connect(core->temperature().get(), &Temperature::bedTargetTemperatureChanged, this, [this] { + float temp = core->temperature().get()->bedTargetTemperature(); checkTemperature(0x01, 0, temp); plotWidget->appendPoint(tr("Target Bed"), temp); }); plotWidget->addPlot(tr("Actual Ext.1")); - connect(core->temperature().get(), &Temperature::extruderTemperatureChanged, this, [this](float temp) { + connect(core->temperature().get(), &Temperature::extruderTemperatureChanged, this, [this] { + float temp = core->temperature().get()->extruderTemperature(); checkTemperature(0x02, 0, temp); plotWidget->appendPoint(tr("Actual Ext.1"), temp); }); plotWidget->addPlot(tr("Target Ext.1")); - connect(core->temperature().get(), &Temperature::extruderTargetTemperatureChanged, this, [this](float temp) { + connect(core->temperature().get(), &Temperature::extruderTargetTemperatureChanged, this, [this] { + float temp = core->temperature().get()->extruderTargetTemperature(); checkTemperature(0x03, 0, temp); 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(tempDockMainWidget); menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, tempTimelineDock); } void MainWindow::makeLogDock() { logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))); logDock = new QDockWidget(tr("Session Log"), this); logDock->setWidget(logWidget); menuView->insertAction(nullptr, logDock->toggleViewAction()); addDockWidget(Qt::RightDockWidgetArea, logDock); } void MainWindow::makeConnectDock() { auto *mainLayout = new QVBoxLayout; auto *newLabel = new QLabel(tr("Port:")); comboPort = new QComboBox; comboPort->setEditable(true); auto *hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboPort, 75); mainLayout->addLayout(hBoxLayout); newLabel = new QLabel(tr("Baud Rate:")); comboBAUD = new QComboBox; comboBAUD->addItems(core->portSpeeds()); comboBAUD->setCurrentIndex(9); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboBAUD, 75); mainLayout->addLayout(hBoxLayout); newLabel = new QLabel(tr("Use Plugin:")); comboPlugin = new QComboBox; comboPlugin->addItem(tr("Autodetect")); comboPlugin->addItems(core->availableFirmwarePlugins()); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(comboPlugin, 75); mainLayout->addLayout(hBoxLayout); cbReset = new QCheckBox(tr("Attempt to stop Reset on connect")); cbReset->setHidden(true); mainLayout->addWidget(cbReset); connect(comboPlugin, &QComboBox::currentTextChanged, this, [this](const QString & currentText) { cbReset->setHidden(!core->availableFirmwarePlugins().contains(currentText)); }); buttonConnect = new QPushButton(tr("Connect")); connect(buttonConnect, &QPushButton::clicked, this, &MainWindow::connectPBClicked); connectionTimer = new QTimer(this); connectionTimer->setInterval(20000); connectionTimer->setSingleShot(true); connect(connectionTimer, &QTimer::timeout, this, [this] { buttonConnect->clicked(); QMessageBox::critical(this, tr("Connection Error"), tr("Your machine did not respond after 20 seconds.\n\nBefore connecting again check that your printer is on and your are connecting using the correct BAUD Rate for your device.")); }); mainLayout->addWidget(buttonConnect); auto *dockContents = new QWidget; dockContents->setLayout(mainLayout); connectDock = new QDockWidget(tr("Connect"), this); connectDock->setWidget(dockContents); menuView->insertAction(nullptr, connectDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, connectDock); } void MainWindow::makeMoveDock() { movementWidget = new MovementWidget(true, this); connect(movementWidget, &MovementWidget::homeAllPressed, this, [this] { logWidget->appendLog(tr("Home All")); core->home(); }); connect(movementWidget, &MovementWidget::homeXPressed, this, [this] { logWidget->appendLog(tr("Home X")); core->home(AtCore::X); }); connect(movementWidget, &MovementWidget::homeYPressed, this, [this] { logWidget->appendLog(tr("Home Y")); core->home(AtCore::Y); }); connect(movementWidget, &MovementWidget::homeZPressed, this, [this] { logWidget->appendLog(tr("Home Z")); core->home(AtCore::Z); }); connect(movementWidget, &MovementWidget::absoluteMove, this, [this](const QLatin1Char & axis, const double & value) { logWidget->appendLog(GCode::description(GCode::G1)); core->move(axis, value); }); connect(movementWidget, &MovementWidget::disableMotorsPressed, this, [this] { core->disableMotors(0); }); connect(movementWidget, &MovementWidget::relativeMove, this, [this](const QLatin1Char & axis, const double & value) { core->setRelativePosition(); core->move(axis, value); core->setAbsolutePosition(); }); connect(movementWidget, &MovementWidget::unitsChanged, this, [this](int units) { auto selection = static_cast(units); core->setUnits(selection); }); moveDock = new QDockWidget(tr("Movement"), this); moveDock->setWidget(movementWidget); menuView->insertAction(nullptr, moveDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, moveDock); } void MainWindow::makeTempControlsDock() { temperatureWidget = new TemperatureWidget; connect(temperatureWidget, &TemperatureWidget::bedTempChanged, core, &AtCore::setBedTemp); connect(temperatureWidget, &TemperatureWidget::extTempChanged, core, &AtCore::setExtruderTemp); tempControlsDock = new QDockWidget(tr("Temperatures"), this); tempControlsDock->setWidget(temperatureWidget); menuView->insertAction(nullptr, tempControlsDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, tempControlsDock); } void MainWindow::makeSdDock() { sdWidget = new SdWidget; connect(sdWidget, &SdWidget::requestSdList, core, &AtCore::sdFileList); connect(sdWidget, &SdWidget::printSdFile, this, [this](const QString & fileName) { if (fileName.isEmpty()) { QMessageBox::information(this, tr("Print Error"), tr("You must Select a file from the list")); } else { core->print(fileName, true); } }); connect(sdWidget, &SdWidget::deleteSdFile, this, [this](const QString & fileName) { if (fileName.isEmpty()) { QMessageBox::information(this, tr("Delete Error"), tr("You must Select a file from the list")); } else { core->sdDelete(fileName); } }); sdDock = new QDockWidget(tr("Sd Card"), this); sdDock->setWidget(sdWidget); menuView->insertAction(nullptr, sdDock->toggleViewAction()); addDockWidget(Qt::LeftDockWidgetArea, sdDock); } void MainWindow::closeEvent(QCloseEvent *event) { core->close(); event->accept(); } void MainWindow::checkTemperature(uint sensorType, uint number, float temp) { QString msg; switch (sensorType) { case 0x00: // bed msg = QString::fromLatin1("Bed Temperature"); break; case 0x01: // bed target msg = QString::fromLatin1("Bed Target Temperature"); break; case 0x02: // extruder msg = QString::fromLatin1("Extruder[%1] Temperature").arg(QString::number(number));; break; case 0x03: // extruder target msg = QString::fromLatin1("Extruder[%1] Target Temperature").arg(QString::number(number)); break; case 0x04: // enclosure msg = QString::fromLatin1("Enclosure Temperature"); break; case 0x05: // enclosure target msg = QString::fromLatin1("Enclosure Target Temperature"); break; } msg.append(QString::fromLatin1(": %1").arg(QString::number(double(temp), 'f', 2))); logWidget->appendLog(msg); } /** * @brief MainWindow::locateSerialPort * Locate all active serial ports on the computer and add to the list * of serial ports */ void MainWindow::locateSerialPort(const QStringList &ports) { comboPort->clear(); if (!ports.isEmpty()) { comboPort->addItems(ports); logWidget->appendLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); } else { QString portError(tr("No available ports! Please connect a serial device to continue!")); if (! logWidget->endsWith(portError)) { logWidget->appendLog(portError); } } } void MainWindow::connectPBClicked() { if (core->state() == AtCore::DISCONNECTED) { if (core->newConnection(comboPort->currentText(), comboBAUD->currentText().toInt(), comboPlugin->currentText(), cbReset->isChecked())) { connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); connect(core, &AtCore::pushedCommand, logWidget, &LogWidget::appendSLog); logWidget->appendLog(tr("Serial connected")); if (core->availableFirmwarePlugins().contains(comboPlugin->currentText())) { if (cbReset->isChecked()) { //Wait a few seconds after connect to avoid the normal errors QTimer::singleShot(5000, core, &AtCore::sdCardPrintStatus); } } } } else { disconnect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog); disconnect(core, &AtCore::pushedCommand, logWidget, &LogWidget::appendSLog); core->closeConnection(); core->setState(AtCore::DISCONNECTED); logWidget->appendLog(tr("Disconnected")); } } void MainWindow::printPBClicked() { QString fileName; switch (core->state()) { case AtCore::DISCONNECTED: QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); break; case AtCore::CONNECTING: QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); comboPlugin->setCurrentText(QStringLiteral("repetier")); break; case AtCore::IDLE: fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), tr("*.gcode")); if (fileName.isNull()) { logWidget->appendLog(tr("No File Selected")); } else { logWidget->appendLog(tr("Print: %1").arg(fileName)); core->print(fileName); } break; case AtCore::BUSY: core->pause(printWidget->postPauseCommand()); break; case AtCore::PAUSE: core->resume(); break; default: qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; } } void MainWindow::printerStateChanged(AtCore::STATES state) { QString stateString; switch (state) { case AtCore::IDLE: if (connectionTimer->isActive()) { connectionTimer->stop(); } buttonConnect->setText(tr("Disconnect")); printWidget->setPrintText(tr("Print File")); stateString = tr("Connected to ") + core->connectedPort(); sdDock->setVisible(core->firmwarePlugin()->isSdSupported()); break; case AtCore::STARTPRINT: stateString = tr("START PRINT"); printWidget->setPrintText(tr("Pause Print")); statusWidget->showPrintArea(true); break; case AtCore::FINISHEDPRINT: stateString = tr("Finished Print"); printWidget->setPrintText(tr("Print File")); statusWidget->showPrintArea(false); break; case AtCore::PAUSE: stateString = tr("Paused"); printWidget->setPrintText(tr("Resume Print")); break; case AtCore::BUSY: stateString = tr("Printing"); printWidget->setPrintText(tr("Pause Print")); break; case AtCore::DISCONNECTED: if (connectionTimer->isActive()) { connectionTimer->stop(); } stateString = QStringLiteral("Not Connected"); buttonConnect->setText(tr("Connect")); setConnectionWidgetsEnabled(true); setDangeriousDocksDisabled(true); break; case AtCore::CONNECTING: stateString = QStringLiteral("Connecting"); buttonConnect->setText(tr("Abort")); connectionTimer->start(); setConnectionWidgetsEnabled(false); setDangeriousDocksDisabled(false); break; case AtCore::STOP: stateString = tr("Stopping Print"); break; case AtCore::ERRORSTATE: stateString = tr("Command ERROR"); break; } statusWidget->setState(stateString); } void MainWindow::toggleDockTitles(bool checked) { if (checked) { delete connectDock->titleBarWidget(); delete logDock->titleBarWidget(); delete tempTimelineDock->titleBarWidget(); delete commandDock->titleBarWidget(); delete moveDock->titleBarWidget(); delete tempControlsDock->titleBarWidget(); delete printDock->titleBarWidget(); delete sdDock->titleBarWidget(); } else { connectDock->setTitleBarWidget(new QWidget()); logDock->setTitleBarWidget(new QWidget()); tempTimelineDock->setTitleBarWidget(new QWidget()); commandDock->setTitleBarWidget(new QWidget()); moveDock->setTitleBarWidget(new QWidget()); tempControlsDock->setTitleBarWidget(new QWidget()); printDock->setTitleBarWidget(new QWidget()); sdDock->setTitleBarWidget(new QWidget()); } } void MainWindow::setDangeriousDocksDisabled(bool disabled) { commandDock->widget()->setDisabled(disabled); moveDock->widget()->setDisabled(disabled); tempControlsDock->widget()->setDisabled(disabled); printDock->widget()->setDisabled(disabled); sdDock->widget()->setDisabled(disabled); if (!disabled) { temperatureWidget->updateExtruderCount(core->extruderCount()); printWidget->updateFanCount(fanCount); } else { printWidget->setPrintText(tr("Print File")); statusWidget->showPrintArea(false); } } void MainWindow::setConnectionWidgetsEnabled(bool enabled) { comboBAUD->setEnabled(enabled); comboPlugin->setEnabled(enabled); comboPort->setEnabled(enabled); } diff --git a/unittests/temperaturetests.cpp b/unittests/temperaturetests.cpp index c462f15..e7a3af7 100644 --- a/unittests/temperaturetests.cpp +++ b/unittests/temperaturetests.cpp @@ -1,134 +1,95 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include "temperaturetests.h" void TemperatureTests::initTestCase() { temperature = new Temperature(this); } void TemperatureTests::cleanup() { - temperature->setBedTemperature(0); - temperature->setBedTargetTemperature(0); - temperature->setExtruderTemperature(0); - temperature->setExtruderTargetTemperature(0); -} - -void TemperatureTests::setExtruderTemperature() -{ - temperature->setExtruderTemperature(20); - QVERIFY(temperature->extruderTemperature() == 20); - - temperature->setExtruderTemperature(20.25); - QVERIFY(temperature->extruderTemperature() == 20.25); -} - -void TemperatureTests::setExtruderTargetTemperature() -{ - temperature->setExtruderTargetTemperature(20); - QVERIFY(temperature->extruderTargetTemperature() == 20); - - temperature->setExtruderTargetTemperature(20.25); - QVERIFY(temperature->extruderTargetTemperature() == 20.25); -} - -void TemperatureTests::setBedTemperature() -{ - temperature->setBedTemperature(20); - QVERIFY(temperature->bedTemperature() == 20); - - temperature->setBedTemperature(20.25); - QVERIFY(temperature->bedTemperature() == 20.25); -} - -void TemperatureTests::setBedTargetTemperature() -{ - temperature->setBedTargetTemperature(20); - QVERIFY(temperature->bedTargetTemperature() == 20); - - temperature->setBedTargetTemperature(20.25); - QVERIFY(temperature->bedTargetTemperature() == 20.25); + temperature->resetData(); } void TemperatureTests::testDecodeAprinter() { temperature->decodeTemp(QByteArray("ok B:49.06 /55 T:64.78 /215")); QVERIFY(temperature->extruderTemperature() == float(64.78)); QVERIFY(temperature->extruderTargetTemperature() == 215); QVERIFY(temperature->bedTemperature() == float(49.06)); QVERIFY(temperature->bedTargetTemperature() == 55); } void TemperatureTests::testDecodeMarlin() { temperature->decodeTemp(QByteArray("ok T:49.74 /60.00 B:36.23 /50.00 @:0 B@:0")); QVERIFY(temperature->extruderTemperature() == float(49.74)); QVERIFY(temperature->extruderTargetTemperature() == 60); QVERIFY(temperature->bedTemperature() == float(36.23)); QVERIFY(temperature->bedTargetTemperature() == 50); } void TemperatureTests::testDecodeMarlinCreality() { temperature->decodeTemp(QByteArray("ok T:48.8 /215.0 B:57.5 /70.0 T0:48.8 /0.0 @:0 B@:0")); QVERIFY(temperature->extruderTemperature() == float(48.8)); QVERIFY(temperature->extruderTargetTemperature() == 215); QVERIFY(temperature->bedTemperature() == float(57.5)); QVERIFY(temperature->bedTargetTemperature() == 70); } void TemperatureTests::testDecodeRepetier() { temperature->decodeTemp(QByteArray("T:25.47 /230 B:69.42 /80 B@:255 @:0")); QVERIFY(temperature->extruderTemperature() == float(25.47)); QVERIFY(temperature->extruderTargetTemperature() == 230); QVERIFY(temperature->bedTemperature() == float(69.42)); QVERIFY(temperature->bedTargetTemperature() == 80); } void TemperatureTests::testDecodeSmoothie() { temperature->decodeTemp(QByteArray("ok T:76.36 /220.0 @0 B:24.1 /60.0 @")); QVERIFY(temperature->extruderTemperature() == float(76.36)); QVERIFY(temperature->extruderTargetTemperature() == 220); QVERIFY(temperature->bedTemperature() == float(24.1)); QVERIFY(temperature->bedTargetTemperature() == 60); } void TemperatureTests::testDecodeSprinter() { temperature->decodeTemp(QByteArray("ok T:154 @:0 B:150")); QVERIFY(temperature->extruderTemperature() == 154); QVERIFY(temperature->bedTemperature() == 150); } void TemperatureTests::testDecodeTeacup() { temperature->decodeTemp(QByteArray("T:15.50/210.0 B:46.80/82.0")); QVERIFY(temperature->extruderTemperature() == float(15.50)); QVERIFY(temperature->extruderTargetTemperature() == 210); QVERIFY(temperature->bedTemperature() == float(46.80)); QVERIFY(temperature->bedTargetTemperature() == 82); } QTEST_MAIN(TemperatureTests) diff --git a/unittests/temperaturetests.h b/unittests/temperaturetests.h index 27a55a0..c843477 100644 --- a/unittests/temperaturetests.h +++ b/unittests/temperaturetests.h @@ -1,42 +1,38 @@ /* This file is part of the KDE project Copyright (C) 2017 Chris Rizzitello This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "../src/core/temperature.h" class TemperatureTests: public QObject { Q_OBJECT private slots: void initTestCase(); void cleanup(); - void setExtruderTemperature(); - void setExtruderTargetTemperature(); - void setBedTemperature(); - void setBedTargetTemperature(); void testDecodeAprinter(); void testDecodeMarlin(); void testDecodeMarlinCreality(); void testDecodeRepetier(); void testDecodeSmoothie(); void testDecodeSprinter(); void testDecodeTeacup(); private: Temperature *temperature; };