Changeset View
Changeset View
Standalone View
Standalone View
testclient/mainwindow.cpp
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | |||||
149 | void MainWindow::makePrintDock() | 149 | void MainWindow::makePrintDock() | ||
150 | { | 150 | { | ||
151 | printWidget = new PrintWidget; | 151 | printWidget = new PrintWidget; | ||
152 | connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); | 152 | connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); | ||
153 | connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); | 153 | connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); | ||
154 | connect(printWidget, &PrintWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); | 154 | connect(printWidget, &PrintWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); | ||
155 | 155 | | |||
156 | connect(printWidget, &PrintWidget::printSpeedChanged, this, [this](const int speed) { | 156 | connect(printWidget, &PrintWidget::printSpeedChanged, this, [this](const int speed) { | ||
157 | core->setPrinterSpeed(speed); | 157 | core->setPrinterSpeed(uint(std::max(1, speed))); | ||
patrickelectric: negative numbers will overflow. | |||||
rizzitello: The range here is 1-300. It will not be negative. | |||||
How can you assure that to be future proof ? patrickelectric: How can you assure that to be future proof ?
You should use std::max | |||||
158 | }); | 158 | }); | ||
159 | 159 | | |||
160 | connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { | 160 | connect(printWidget, &PrintWidget::flowRateChanged, [this](const int rate) { | ||
161 | core->setFlowRate(rate); | 161 | core->setFlowRate(uint(std::max(1, rate))); | ||
162 | }); | 162 | }); | ||
163 | 163 | | |||
164 | printDock = new QDockWidget(tr("Print"), this); | 164 | printDock = new QDockWidget(tr("Print"), this); | ||
165 | printDock->setWidget(printWidget); | 165 | printDock->setWidget(printWidget); | ||
166 | 166 | | |||
167 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | 167 | menuView->insertAction(nullptr, printDock->toggleViewAction()); | ||
168 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | 168 | addDockWidget(Qt::LeftDockWidgetArea, printDock); | ||
169 | } | 169 | } | ||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 363 | { | |||
365 | event->accept(); | 365 | event->accept(); | ||
366 | } | 366 | } | ||
367 | 367 | | |||
368 | MainWindow::~MainWindow() | 368 | MainWindow::~MainWindow() | ||
369 | { | 369 | { | ||
370 | 370 | | |||
371 | } | 371 | } | ||
372 | 372 | | |||
373 | void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) | 373 | void MainWindow::checkTemperature(uint sensorType, uint number, float temp) | ||
374 | { | 374 | { | ||
375 | QString msg; | 375 | QString msg; | ||
376 | switch (sensorType) { | 376 | switch (sensorType) { | ||
377 | case 0x00: // bed | 377 | case 0x00: // bed | ||
378 | msg = QString::fromLatin1("Bed Temperature "); | 378 | msg = QString::fromLatin1("Bed Temperature "); | ||
379 | break; | 379 | break; | ||
380 | 380 | | |||
381 | case 0x01: // bed target | 381 | case 0x01: // bed target | ||
Show All 13 Lines | 393 | case 0x04: // enclosure | |||
395 | break; | 395 | break; | ||
396 | 396 | | |||
397 | case 0x05: // enclosure target | 397 | case 0x05: // enclosure target | ||
398 | msg = QString::fromLatin1("Enclosure Target Temperature "); | 398 | msg = QString::fromLatin1("Enclosure Target Temperature "); | ||
399 | break; | 399 | break; | ||
400 | } | 400 | } | ||
401 | 401 | | |||
402 | msg.append(QString::fromLatin1("[%1] : %2").arg( | 402 | msg.append(QString::fromLatin1("[%1] : %2").arg( | ||
403 | QString::number(number), QString::number(temp) | 403 | QString::number(number), QString::number(double(temp), 'f', 2) | ||
404 | )); | 404 | )); | ||
405 | 405 | | |||
406 | logWidget->appendLog(msg); | 406 | logWidget->appendLog(msg); | ||
407 | } | 407 | } | ||
408 | /** | 408 | /** | ||
409 | * @brief MainWindow::locateSerialPort | 409 | * @brief MainWindow::locateSerialPort | ||
410 | * Locate all active serial ports on the computer and add to the list | 410 | * Locate all active serial ports on the computer and add to the list | ||
411 | * of serial ports | 411 | * of serial ports | ||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |
negative numbers will overflow.