File indexing completed on 2024-05-12 04:41:11
0001 /* AtCore KDE Libary for 3D Printers 0002 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 SPDX-FileCopyrightText: 2016 Tomaz Canabrava <tcanabrava@kde.org> 0004 SPDX-FileCopyrightText: 2016-2018 Chris Rizzitello <rizzitello@kde.org> 0005 SPDX-FileCopyrightText: 2016-2018 Patrick José Pereira <patrickjp@kde.org> 0006 SPDX-FileCopyrightText: 2017 Lays Rodrigues <lays.rodrigues@kde.org> 0007 */ 0008 0009 #include <QLoggingCategory> 0010 #include <QString> 0011 0012 #include "atcore.h" 0013 #include "repetierplugin.h" 0014 0015 Q_LOGGING_CATEGORY(REPETIER_PLUGIN, "org.kde.atelier.core.firmware.repetier") 0016 0017 QString RepetierPlugin::name() const 0018 { 0019 return QStringLiteral("Repetier"); 0020 } 0021 0022 bool RepetierPlugin::isSdSupported() const 0023 { 0024 return true; 0025 } 0026 0027 RepetierPlugin::RepetierPlugin() 0028 { 0029 qCDebug(REPETIER_PLUGIN) << RepetierPlugin::name() << " plugin loaded!"; 0030 } 0031 0032 void RepetierPlugin::validateCommand(const QString &lastMessage) 0033 { 0034 if (lastMessage.contains(QStringLiteral("End file list"))) { 0035 core()->setReadingSdCardList(false); 0036 } else if (core()->isReadingSdCardList()) { 0037 // Below is to not add directories 0038 if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { 0039 QString fileName = lastMessage; 0040 fileName.chop(fileName.length() - fileName.lastIndexOf(QChar::fromLatin1(' '))); 0041 core()->appendSdCardFileList(fileName); 0042 } 0043 } else { 0044 if (lastMessage.contains(QStringLiteral("SD card"))) { 0045 if (lastMessage.contains(QStringLiteral("inserted"))) { 0046 core()->setSdMounted(true); 0047 } else if (lastMessage.contains(QStringLiteral("removed"))) { 0048 core()->setSdMounted(false); 0049 } 0050 } else if (lastMessage.contains(QStringLiteral("Begin file list"))) { 0051 core()->setSdMounted(true); 0052 core()->setReadingSdCardList(true); 0053 core()->clearSdCardFileList(); 0054 } else if (lastMessage.contains(QStringLiteral("SD printing byte"))) { 0055 if (lastMessage.contains(QStringLiteral("SD printing byte 0/0"))) { 0056 // not printing a file 0057 return; 0058 } 0059 if (core()->state() != AtCore::BUSY) { 0060 // This should only happen if Attached to an Sd printing machine. 0061 // Just tell the client were starting a job like normal. 0062 // For this to work the client should check if sdCardPrintStatus() 0063 // Upon the Connection to a known firmware with sdSupport 0064 core()->setState(AtCore::STARTPRINT); 0065 core()->setState(AtCore::BUSY); 0066 } 0067 QString temp = lastMessage; 0068 temp.replace(QStringLiteral("SD printing byte"), QString()); 0069 qlonglong total = temp.mid(temp.lastIndexOf(QChar::fromLatin1('/')) + 1, temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))).toLongLong(); 0070 if (total) { 0071 temp.chop(temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))); 0072 qlonglong remaining = total - temp.toLongLong(); 0073 float progress = float(total - remaining) * 100 / float(total); 0074 Q_EMIT core()->printProgressChanged(progress); 0075 if (progress >= 100) { 0076 core()->setState(AtCore::FINISHEDPRINT); 0077 core()->setState(AtCore::IDLE); 0078 } 0079 } else { 0080 core()->setState(AtCore::FINISHEDPRINT); 0081 core()->setState(AtCore::IDLE); 0082 } 0083 } 0084 if (lastMessage.contains(QStringLiteral("ok"))) { 0085 Q_EMIT readyForCommand(); 0086 } 0087 } 0088 }