Changeset View
Changeset View
Standalone View
Standalone View
src/core/atcore.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | 43 | | |||
44 | Q_LOGGING_CATEGORY(ATCORE_PLUGIN, "org.kde.atelier.core.plugin") | 44 | Q_LOGGING_CATEGORY(ATCORE_PLUGIN, "org.kde.atelier.core.plugin") | ||
45 | Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") | 45 | Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") | ||
46 | /** | 46 | /** | ||
47 | * @brief The AtCorePrivate struct | 47 | * @brief The AtCorePrivate struct | ||
48 | * Provides a private data set for atcore. | 48 | * Provides a private data set for atcore. | ||
49 | */ | 49 | */ | ||
50 | struct AtCore::AtCorePrivate { | 50 | struct AtCore::AtCorePrivate { | ||
51 | IFirmware *firmwarePlugin = nullptr;//!< @param firmwarePlugin: pointer to firmware plugin | 51 | /** firmwarePlugin: pointer to firmware plugin */ | ||
52 | SerialLayer *serial = nullptr; //!< @param serial: pointer to the serial layer | 52 | IFirmware *firmwarePlugin = nullptr; | ||
53 | QPluginLoader pluginLoader; //!< @param pluginLoader: QPluginLoader | 53 | /** serial: pointer to the serial layer */ | ||
54 | QMap<QString, QString> plugins; //!< @param plugins: Map of plugins name / path | 54 | SerialLayer *serial = nullptr; | ||
55 | QByteArray lastMessage; //!< @param lastMessage: lastMessage from the printer | 55 | /** pluginLoader: QPluginLoader */ | ||
56 | int extruderCount = 1; //!< @param extruderCount: extruder count | 56 | QPluginLoader pluginLoader; | ||
57 | Temperature temperature; //!< @param temperature: Temperature object | 57 | /** plugins: Map of plugins name / path */ | ||
58 | QStringList commandQueue; //!< @param commandQueue: the list of commands to send to the printer | 58 | QMap<QString, QString> plugins; | ||
59 | bool ready = false; //!< @param ready: True if printer is ready for a command | 59 | /** lastMessage: lastMessage from the printer */ | ||
60 | QTimer *tempTimer = nullptr; //!< @param tempTimer: timer connected to the checkTemperature function | 60 | QByteArray lastMessage; | ||
61 | float percentage; //!< @param percentage: print job percent | 61 | /** extruderCount: extruder count */ | ||
patrickelectric: why not 0.0 ? | |||||
62 | QByteArray posString; //!< @param posString: stored string from last M114 return | 62 | int extruderCount = 1; | ||
63 | AtCore::STATES printerState; //!< @param printerState: State of the Printer | 63 | /** temperature: Temperature object */ | ||
64 | QStringList serialPorts; //!< @param seralPorts: Detected serial Ports | 64 | Temperature temperature; | ||
65 | QTimer *serialTimer = nullptr; //!< @param serialTimer: Timer connected to locateSerialPorts | 65 | /** commandQueue: the list of commands to send to the printer */ | ||
66 | bool sdCardMounted = false; //!< @param sdCardMounted: True if Sd Card is mounted. | 66 | QStringList commandQueue; | ||
67 | bool sdCardReadingFileList = false; //!< @param sdCardReadingFileList: True while getting file names from sd card | 67 | /** ready: True if printer is ready for a command */ | ||
68 | bool sdCardPrinting = false; //!< @param sdCardPrinting: True if currently printing from sd card. | 68 | bool ready = false; | ||
69 | QString sdCardFileName; //!< @param sdCardFileName: name of file being used from sd card. | 69 | /** tempTimer: timer connected to the checkTemperature function */ | ||
70 | QStringList sdCardFileList; //!< @param sdCardFileList: List of files on sd card. | 70 | QTimer *tempTimer = nullptr; | ||
Can we move the comments to be one space from the variable ? Or to separate it in blocks or in the previous line ? Everytime that something get bigger all lines need to change... patrickelectric: Can we move the comments to be one space from the variable ? Or to separate it in blocks or in… | |||||
71 | /** percentage: print job percent */ | ||||
72 | float percentage = 0.0; | ||||
73 | /** posString: stored string from last M114 return */ | ||||
74 | QByteArray posString; | ||||
75 | /** printerState: State of the Printer */ | ||||
76 | AtCore::STATES printerState = AtCore::DISCONNECTED; | ||||
77 | /** seralPorts: Detected serial Ports */ | ||||
78 | QStringList serialPorts; | ||||
79 | /** serialTimer: Timer connected to locateSerialPorts */ | ||||
80 | QTimer *serialTimer = nullptr; | ||||
81 | /** sdCardMounted: True if Sd Card is mounted. */ | ||||
82 | bool sdCardMounted = false; | ||||
83 | /** sdCardReadingFileList: True while getting file names from sd card */ | ||||
84 | bool sdCardReadingFileList = false; | ||||
85 | /** sdCardPrinting: True if currently printing from sd card. */ | ||||
86 | bool sdCardPrinting = false; | ||||
87 | /** sdCardFileName: name of file being used from sd card. */ | ||||
88 | QString sdCardFileName; | ||||
89 | /** sdCardFileList: List of files on sd card. */ | ||||
Is there a why to use /** */ and not /* */ or ? ( makes it more simples). patrickelectric: Is there a why to use /** */ and not /* */ or // ? (// makes it more simples). | |||||
rizzitello: They are Doxygen comments. | |||||
90 | QStringList sdCardFileList; | ||||
71 | }; | 91 | }; | ||
72 | 92 | | |||
73 | AtCore::AtCore(QObject *parent) : | 93 | AtCore::AtCore(QObject *parent) : | ||
74 | QObject(parent), | 94 | QObject(parent), | ||
75 | d(new AtCorePrivate) | 95 | d(new AtCorePrivate) | ||
76 | { | 96 | { | ||
77 | //Register MetaTypes | 97 | //Register MetaTypes | ||
78 | qRegisterMetaType<AtCore::STATES>("AtCore::STATES"); | 98 | qRegisterMetaType<AtCore::STATES>("AtCore::STATES"); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 150 | { | |||
134 | } | 154 | } | ||
135 | 155 | | |||
136 | if (state() == AtCore::STATES::CONNECTING) { | 156 | if (state() == AtCore::STATES::CONNECTING) { | ||
137 | //Most Firmwares will return "start" on connect, some return their firmware name. | 157 | //Most Firmwares will return "start" on connect, some return their firmware name. | ||
138 | if (message.contains("start")) { | 158 | if (message.contains("start")) { | ||
139 | qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; | 159 | qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; | ||
140 | QTimer::singleShot(500, this, &AtCore::requestFirmware); | 160 | QTimer::singleShot(500, this, &AtCore::requestFirmware); | ||
141 | return; | 161 | return; | ||
142 | } else if (message.contains("Grbl")) { | 162 | } | ||
163 | | ||||
164 | if (message.contains("Grbl")) { | ||||
143 | loadFirmwarePlugin(QString::fromLatin1("grbl")); | 165 | loadFirmwarePlugin(QString::fromLatin1("grbl")); | ||
144 | return; | 166 | return; | ||
145 | } else if (message.contains("Smoothie")) { | 167 | } | ||
168 | | ||||
169 | if (message.contains("Smoothie")) { | ||||
146 | loadFirmwarePlugin(QString::fromLatin1("smoothie")); | 170 | loadFirmwarePlugin(QString::fromLatin1("smoothie")); | ||
147 | return; | 171 | return; | ||
148 | } | 172 | } | ||
149 | 173 | | |||
150 | qCDebug(ATCORE_CORE) << "Waiting for firmware detect."; | 174 | qCDebug(ATCORE_CORE) << "Waiting for firmware detect."; | ||
151 | emit atcoreMessage(tr("Waiting for firmware detect.")); | 175 | emit atcoreMessage(tr("Waiting for firmware detect.")); | ||
152 | } | 176 | } | ||
153 | qCDebug(ATCORE_CORE) << "Find Firmware: " << message; | 177 | qCDebug(ATCORE_CORE) << "Find Firmware: " << message; | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 239 | { | |||
220 | d->serial = new SerialLayer(port, baud); | 244 | d->serial = new SerialLayer(port, baud); | ||
221 | connect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); | 245 | connect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); | ||
222 | if (serialInitialized() && d->serial->isWritable()) { | 246 | if (serialInitialized() && d->serial->isWritable()) { | ||
223 | setState(AtCore::CONNECTING); | 247 | setState(AtCore::CONNECTING); | ||
224 | connect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newCommand); | 248 | connect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newCommand); | ||
225 | connect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 249 | connect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
226 | d->serialTimer->stop(); | 250 | d->serialTimer->stop(); | ||
227 | return true; | 251 | return true; | ||
228 | } else { | 252 | } | ||
253 | | ||||
229 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | 254 | qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; | ||
230 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | 255 | emit atcoreMessage(tr("Failed to open device in read/write mode.")); | ||
231 | return false; | 256 | return false; | ||
232 | } | 257 | | ||
233 | } | 258 | } | ||
234 | 259 | | |||
235 | bool AtCore::serialInitialized() const | 260 | bool AtCore::serialInitialized() const | ||
236 | { | 261 | { | ||
237 | if (!d->serial) { | 262 | if (!d->serial) { | ||
238 | return false; | 263 | return false; | ||
239 | } | 264 | } | ||
240 | return d->serial->isOpen(); | 265 | return d->serial->isOpen(); | ||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 376 | if (sdPrint) { | |||
357 | d->sdCardPrinting = true; | 382 | d->sdCardPrinting = true; | ||
358 | connect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); | 383 | connect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); | ||
359 | return; | 384 | return; | ||
360 | } | 385 | } | ||
361 | } | 386 | } | ||
362 | //Process the gcode with a printThread. | 387 | //Process the gcode with a printThread. | ||
363 | //The Thread processes the gcode without freezing the libary. | 388 | //The Thread processes the gcode without freezing the libary. | ||
364 | //Only sends a command back when the printer is ready, avoiding buffer overflow in the printer. | 389 | //Only sends a command back when the printer is ready, avoiding buffer overflow in the printer. | ||
365 | QThread *thread = new QThread(); | 390 | auto thread = new QThread(); | ||
366 | PrintThread *printThread = new PrintThread(this, fileName); | 391 | auto printThread = new PrintThread(this, fileName); | ||
367 | printThread->moveToThread(thread); | 392 | printThread->moveToThread(thread); | ||
368 | 393 | | |||
369 | connect(printThread, &PrintThread::printProgressChanged, this, &AtCore::printProgressChanged, Qt::QueuedConnection); | 394 | connect(printThread, &PrintThread::printProgressChanged, this, &AtCore::printProgressChanged, Qt::QueuedConnection); | ||
370 | connect(thread, &QThread::started, printThread, &PrintThread::start); | 395 | connect(thread, &QThread::started, printThread, &PrintThread::start); | ||
371 | connect(printThread, &PrintThread::finished, thread, &QThread::quit); | 396 | connect(printThread, &PrintThread::finished, thread, &QThread::quit); | ||
372 | connect(thread, &QThread::finished, printThread, &PrintThread::deleteLater); | 397 | connect(thread, &QThread::finished, printThread, &PrintThread::deleteLater); | ||
373 | if (!thread->isRunning()) { | 398 | if (!thread->isRunning()) { | ||
374 | thread->start(); | 399 | thread->start(); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 419 | if (serialInitialized()) { | |||
416 | d->serial->close(); | 441 | d->serial->close(); | ||
417 | //Clear our copy of the sdcard filelist | 442 | //Clear our copy of the sdcard filelist | ||
418 | clearSdCardFileList(); | 443 | clearSdCardFileList(); | ||
419 | setState(AtCore::STATES::DISCONNECTED); | 444 | setState(AtCore::STATES::DISCONNECTED); | ||
420 | d->serialTimer->start(); | 445 | d->serialTimer->start(); | ||
421 | } | 446 | } | ||
422 | } | 447 | } | ||
423 | 448 | | |||
424 | AtCore::STATES AtCore::state(void) | 449 | AtCore::STATES AtCore::state() | ||
425 | { | 450 | { | ||
426 | return d->printerState; | 451 | return d->printerState; | ||
427 | } | 452 | } | ||
428 | 453 | | |||
429 | void AtCore::setState(AtCore::STATES state) | 454 | void AtCore::setState(AtCore::STATES state) | ||
430 | { | 455 | { | ||
431 | if (state != d->printerState) { | 456 | if (state != d->printerState) { | ||
432 | qCDebug(ATCORE_CORE) << QStringLiteral("Atcore state changed from [%1] to [%2]") | 457 | qCDebug(ATCORE_CORE) << QStringLiteral("Atcore state changed from [%1] to [%2]") | ||
433 | .arg(QVariant::fromValue(d->printerState).value<QString>(), | 458 | .arg(QVariant::fromValue(d->printerState).toString(), | ||
434 | QVariant::fromValue(state).value<QString>()); | 459 | QVariant::fromValue(state).toString()); | ||
435 | d->printerState = state; | 460 | d->printerState = state; | ||
436 | if (state == AtCore::STATES::FINISHEDPRINT && d->sdCardPrinting) { | 461 | if (state == AtCore::STATES::FINISHEDPRINT && d->sdCardPrinting) { | ||
437 | //Clean up the sd card print | 462 | //Clean up the sd card print | ||
438 | d->sdCardPrinting = false; | 463 | d->sdCardPrinting = false; | ||
439 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); | 464 | disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); | ||
440 | } | 465 | } | ||
441 | emit stateChanged(d->printerState); | 466 | emit stateChanged(d->printerState); | ||
442 | } | 467 | } | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 511 | if (serialInitialized()) { | |||
490 | pushCommand(GCode::toCommand(GCode::MCommands::M115)); | 515 | pushCommand(GCode::toCommand(GCode::MCommands::M115)); | ||
491 | } else { | 516 | } else { | ||
492 | qCDebug(ATCORE_CORE) << "There is no open device to send commands"; | 517 | qCDebug(ATCORE_CORE) << "There is no open device to send commands"; | ||
493 | } | 518 | } | ||
494 | } | 519 | } | ||
495 | 520 | | |||
496 | bool AtCore::firmwarePluginLoaded() const | 521 | bool AtCore::firmwarePluginLoaded() const | ||
497 | { | 522 | { | ||
498 | if (firmwarePlugin()) { | 523 | return firmwarePlugin(); | ||
499 | return true; | | |||
500 | } else { | | |||
501 | return false; | | |||
502 | } | | |||
503 | } | 524 | } | ||
504 | 525 | | |||
505 | QMap<QString, QString> AtCore::findFirmwarePlugins(const QString &path) | 526 | QMap<QString, QString> AtCore::findFirmwarePlugins(const QString &path) | ||
506 | { | 527 | { | ||
507 | QMap<QString, QString> detectedPlugins; | 528 | QMap<QString, QString> detectedPlugins; | ||
508 | QStringList files = QDir(path).entryList(QDir::Files); | 529 | QStringList files = QDir(path).entryList(QDir::Files); | ||
509 | for (const QString &f : files) { | 530 | for (const QString &f : files) { | ||
510 | QString file = f; | 531 | QString file = f; | ||
▲ Show 20 Lines • Show All 352 Lines • Show Last 20 Lines |
why not 0.0 ?