Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 50 | struct AtCore::AtCorePrivate { | |||
---|---|---|---|---|---|
53 | /** serial: pointer to the serial layer */ | 53 | /** serial: pointer to the serial layer */ | ||
54 | SerialLayer *serial = nullptr; | 54 | SerialLayer *serial = nullptr; | ||
55 | /** pluginLoader: QPluginLoader */ | 55 | /** pluginLoader: QPluginLoader */ | ||
56 | QPluginLoader pluginLoader; | 56 | QPluginLoader pluginLoader; | ||
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 | /** lastCommand: the last command sent to the printer */ | ||||
62 | QString lastCommand; | ||||
61 | /** extruderCount: extruder count */ | 63 | /** extruderCount: extruder count */ | ||
62 | int extruderCount = 1; | 64 | int extruderCount = 1; | ||
63 | /** temperature: Temperature object */ | 65 | /** temperature: Temperature object */ | ||
64 | Temperature temperature; | 66 | Temperature temperature; | ||
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; | ||
▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Line(s) | 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 | | |||
348 | void AtCore::newMessage(const QByteArray &message) | 350 | void AtCore::newMessage(const QByteArray &message) | ||
349 | { | 351 | { | ||
350 | //Evaluate the messages coming from the printer. | | |||
351 | d->lastMessage = message; | 352 | d->lastMessage = message; | ||
352 | //Check if the message has current coordinates. | 353 | //Check if the message has current coordinates. | ||
353 | if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | 354 | if (d->lastCommand.startsWith(GCode::toCommand(GCode::MCommands::M114)) | ||
355 | && d->lastMessage.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | ||||
354 | d->posString = message; | 356 | d->posString = message; | ||
355 | d->posString.resize(d->posString.indexOf('E')); | 357 | d->posString.resize(d->posString.indexOf('E')); | ||
356 | d->posString.replace(':', ""); | 358 | d->posString.replace(':', ""); | ||
357 | } | 359 | } | ||
358 | 360 | | |||
359 | //Check if have temperature info and decode it | 361 | //Check if have temperature info and decode it | ||
360 | if (d->lastMessage.contains("T:") || d->lastMessage.contains("B:")) { | 362 | if (d->lastMessage.contains("T:") || d->lastMessage.contains("B:")) { | ||
361 | temperature().decodeTemp(message); | 363 | temperature().decodeTemp(d->lastMessage); | ||
362 | } | 364 | } | ||
363 | emit receivedMessage(d->lastMessage); | 365 | emit receivedMessage(d->lastMessage); | ||
364 | } | 366 | } | ||
365 | 367 | | |||
366 | void AtCore::newCommand(const QByteArray &command) | 368 | void AtCore::newCommand(const QByteArray &command) | ||
367 | { | 369 | { | ||
368 | emit pushedCommand(command); | 370 | emit pushedCommand(command); | ||
369 | } | 371 | } | ||
▲ Show 20 Lines • Show All 341 Lines • ▼ Show 20 Line(s) | 712 | if (d->commandQueue.isEmpty()) { | |||
711 | return; | 713 | return; | ||
712 | } | 714 | } | ||
713 | 715 | | |||
714 | if (!serialInitialized()) { | 716 | if (!serialInitialized()) { | ||
715 | qCDebug(ATCORE_PLUGIN) << "Can't process queue ! Serial not initialized."; | 717 | qCDebug(ATCORE_PLUGIN) << "Can't process queue ! Serial not initialized."; | ||
716 | return; | 718 | return; | ||
717 | } | 719 | } | ||
718 | 720 | | |||
719 | QString text = d->commandQueue.takeAt(0); | 721 | d->lastCommand = d->commandQueue.takeAt(0); | ||
720 | 722 | | |||
721 | if (firmwarePluginLoaded()) { | 723 | if (firmwarePluginLoaded()) { | ||
722 | d->serial->pushCommand(firmwarePlugin()->translate(text)); | 724 | d->serial->pushCommand(firmwarePlugin()->translate(d->lastCommand)); | ||
723 | } else { | 725 | } else { | ||
724 | d->serial->pushCommand(text.toLocal8Bit()); | 726 | d->serial->pushCommand(d->lastCommand.toLocal8Bit()); | ||
725 | } | 727 | } | ||
726 | d->ready = false; | 728 | d->ready = false; | ||
727 | } | 729 | } | ||
728 | 730 | | |||
729 | void AtCore::checkTemperature() | 731 | void AtCore::checkTemperature() | ||
730 | { | 732 | { | ||
731 | //One request for the temperature in the queue at a time. | 733 | //One request for the temperature in the queue at a time. | ||
732 | if (d->commandQueue.contains(GCode::toCommand(GCode::MCommands::M105))) { | 734 | if (d->commandQueue.contains(GCode::toCommand(GCode::MCommands::M105))) { | ||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |