Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 50 | struct AtCore::AtCorePrivate { | |||
---|---|---|---|---|---|
57 | /** plugins: Map of plugins name / path */ | 57 | /** plugins: Map of plugins name / path */ | ||
58 | QMap<QString, QString> plugins; | 58 | QMap<QString, QString> plugins; | ||
59 | /** lastMessage: lastMessage from the printer */ | 59 | /** lastMessage: lastMessage from the printer */ | ||
60 | QByteArray lastMessage; | 60 | QByteArray lastMessage; | ||
61 | /** extruderCount: extruder count */ | 61 | /** extruderCount: extruder count */ | ||
62 | int extruderCount = 1; | 62 | int extruderCount = 1; | ||
63 | /** temperature: Temperature object */ | 63 | /** temperature: Temperature object */ | ||
64 | Temperature temperature; | 64 | Temperature temperature; | ||
65 | /** autoTemperatureReport: True if using auto Temperature Reporting*/ | ||||
66 | bool autoTemperatureReport = false; | ||||
65 | /** commandQueue: the list of commands to send to the printer */ | 67 | /** commandQueue: the list of commands to send to the printer */ | ||
66 | QStringList commandQueue; | 68 | QStringList commandQueue; | ||
67 | /** ready: True if printer is ready for a command */ | 69 | /** ready: True if printer is ready for a command */ | ||
68 | bool ready = false; | 70 | bool ready = false; | ||
69 | /** temperatureTimer: timer connected to the checkTemperature function */ | 71 | /** temperatureTimer: timer connected to the checkTemperature function */ | ||
70 | QTimer temperatureTimer; | 72 | QTimer temperatureTimer; | ||
71 | /** sdPrintProgressTimer: timer used to check in on sdJobs */ | 73 | /** sdPrintProgressTimer: timer used to check in on sdJobs */ | ||
72 | QTimer sdPrintProgressTimer; | 74 | QTimer sdPrintProgressTimer; | ||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Line(s) | 337 | { | |||
340 | } | 342 | } | ||
341 | if (!newTime && d->temperatureTimer.isActive()) { | 343 | if (!newTime && d->temperatureTimer.isActive()) { | ||
342 | d->temperatureTimer.stop(); | 344 | d->temperatureTimer.stop(); | ||
343 | } else { | 345 | } else { | ||
344 | d->temperatureTimer.start(newTime); | 346 | d->temperatureTimer.start(newTime); | ||
345 | } | 347 | } | ||
346 | } | 348 | } | ||
347 | 349 | | |||
350 | void AtCore::setAutoTemperatureReport(bool autoReport) | ||||
351 | { | ||||
352 | if (autoReport == d->autoTemperatureReport) { | ||||
353 | return; | ||||
354 | } | ||||
355 | emit autoTemperatureReportChanged(autoReport); | ||||
patrickelectric: This should be after `d->autoTemperatureReport = autoReport` no ? | |||||
356 | | ||||
357 | if (autoReport) { | ||||
358 | setTemperatureTimerInterval(0); | ||||
359 | d->commandQueue.removeAll(GCode::toCommand(GCode::M105)); | ||||
360 | setAutoCheckTemperatureInterval(5); | ||||
361 | } else if (d->autoTemperatureReport) { | ||||
362 | if (d->printerState < 2 || d->printerState == AtCore::ERRORSTATE) { | ||||
363 | return; | ||||
364 | } | ||||
365 | setAutoCheckTemperatureInterval(0); | ||||
366 | d->temperatureTimer.setInterval(5000); | ||||
367 | } | ||||
368 | d->autoTemperatureReport = autoReport; | ||||
369 | } | ||||
370 | | ||||
371 | void AtCore::setAutoCheckTemperatureInterval(int newTime) | ||||
372 | { | ||||
373 | pushCommand(GCode::toCommand(GCode::M155, QString::number(newTime))); | ||||
374 | emit autoCheckTemperatureIntervalChanged(newTime); | ||||
375 | } | ||||
376 | | ||||
377 | bool AtCore::autoTemperatureReport() const | ||||
378 | { | ||||
379 | return d->autoTemperatureReport; | ||||
380 | } | ||||
381 | | ||||
348 | void AtCore::newMessage(const QByteArray &message) | 382 | void AtCore::newMessage(const QByteArray &message) | ||
349 | { | 383 | { | ||
350 | //Evaluate the messages coming from the printer. | 384 | //Evaluate the messages coming from the printer. | ||
351 | d->lastMessage = message; | 385 | d->lastMessage = message; | ||
386 | if (d->lastMessage.contains(QString::fromLatin1("Cap:AUTOREPORT_TEMP:1").toLocal8Bit())) { | ||||
387 | setAutoTemperatureReport(true); | ||||
388 | } | ||||
389 | | ||||
352 | //Check if the message has current coordinates. | 390 | //Check if the message has current coordinates. | ||
353 | if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | 391 | if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | ||
354 | d->posString = message; | 392 | d->posString = message; | ||
355 | d->posString.resize(d->posString.indexOf('E')); | 393 | d->posString.resize(d->posString.indexOf('E')); | ||
356 | d->posString.replace(':', ""); | 394 | d->posString.replace(':', ""); | ||
357 | } | 395 | } | ||
358 | 396 | | |||
359 | //Check if have temperature info and decode it | 397 | //Check if have temperature info and decode it | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 477 | if (serialInitialized()) { | |||
440 | if (AtCore::state() == AtCore::STATES::BUSY && !d->sdCardPrinting) { | 478 | if (AtCore::state() == AtCore::STATES::BUSY && !d->sdCardPrinting) { | ||
441 | //We have to clean up the print job if printing from the host. | 479 | //We have to clean up the print job if printing from the host. | ||
442 | //However disconnecting while printing from sd card should not affect the print job. | 480 | //However disconnecting while printing from sd card should not affect the print job. | ||
443 | setState(AtCore::STATES::STOP); | 481 | setState(AtCore::STATES::STOP); | ||
444 | } | 482 | } | ||
445 | if (firmwarePluginLoaded()) { | 483 | if (firmwarePluginLoaded()) { | ||
446 | disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); | 484 | disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); | ||
447 | disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); | 485 | disconnect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::newMessage); | ||
448 | if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { | 486 | if (firmwarePlugin()->name() != QStringLiteral("Grbl") && !d->autoTemperatureReport) { | ||
449 | setTemperatureTimerInterval(0); | 487 | setTemperatureTimerInterval(0); | ||
450 | } | 488 | } | ||
451 | //Attempt to unload the firmware plugin. | 489 | //Attempt to unload the firmware plugin. | ||
452 | QString name = firmwarePlugin()->name(); | 490 | QString name = firmwarePlugin()->name(); | ||
453 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | 491 | QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close."); | ||
454 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | 492 | qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg); | ||
455 | d->firmwarePlugin = nullptr; | 493 | d->firmwarePlugin = nullptr; | ||
456 | } | 494 | } | ||
457 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | 495 | //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection. | ||
458 | disconnect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); | 496 | disconnect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||
459 | disconnect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newMessage); | 497 | disconnect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newMessage); | ||
460 | d->serial->close(); | 498 | d->serial->close(); | ||
461 | //Clear our copy of the sdcard filelist | 499 | //Clear our copy of the sdcard filelist | ||
462 | clearSdCardFileList(); | 500 | clearSdCardFileList(); | ||
463 | setState(AtCore::STATES::DISCONNECTED); | 501 | setState(AtCore::STATES::DISCONNECTED); | ||
502 | if (d->autoTemperatureReport) { | ||||
503 | setAutoTemperatureReport(false); | ||||
504 | } | ||||
464 | d->serialTimer.start(); | 505 | d->serialTimer.start(); | ||
465 | } | 506 | } | ||
466 | } | 507 | } | ||
467 | 508 | | |||
468 | AtCore::STATES AtCore::state() | 509 | AtCore::STATES AtCore::state() | ||
469 | { | 510 | { | ||
470 | return d->printerState; | 511 | return d->printerState; | ||
471 | } | 512 | } | ||
▲ Show 20 Lines • Show All 433 Lines • Show Last 20 Lines |
This should be after d->autoTemperatureReport = autoReport no ?