Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/marlinplugin.cpp
Show All 33 Lines | |||||
34 | { | 34 | { | ||
35 | return QStringLiteral("Marlin"); | 35 | return QStringLiteral("Marlin"); | ||
36 | } | 36 | } | ||
37 | 37 | | |||
38 | MarlinPlugin::MarlinPlugin() | 38 | MarlinPlugin::MarlinPlugin() | ||
39 | { | 39 | { | ||
40 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | 40 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | ||
41 | } | 41 | } | ||
42 | | ||||
43 | void MarlinPlugin::validateCommand(const QString &lastMessage) | ||||
44 | { | ||||
45 | if (lastMessage.contains(QStringLiteral("End file list"))) { | ||||
46 | core()->setReadingSdCardList(false); | ||||
47 | } else if (core()->isReadingSdCardList()) { | ||||
48 | // Below is to not add directories | ||||
49 | if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { | ||||
50 | QString fileName = lastMessage; | ||||
51 | fileName.chop(fileName.length() - fileName.lastIndexOf(QChar::fromLatin1(' '))); | ||||
52 | core()->appendSdCardFileList(fileName); | ||||
53 | } | ||||
54 | } else { | ||||
55 | if (lastMessage.contains(QStringLiteral("SD card ok"))) { | ||||
56 | core()->setSdMounted(true); | ||||
57 | } else if (lastMessage.contains(QStringLiteral("SD init fail"))) { | ||||
patrickelectric: else ? | |||||
58 | core()->setSdMounted(false); | ||||
59 | } else if (lastMessage.contains(QStringLiteral("Begin file list"))) { | ||||
60 | core()->setSdMounted(true); | ||||
61 | core()->clearSdCardFileList(); | ||||
62 | core()->setReadingSdCardList(true); | ||||
patrickelectric: the test is not necessary, just core()->setSdMounted(true); | |||||
63 | } else if (lastMessage.contains(QStringLiteral("SD printing byte"))) { | ||||
64 | QString temp = lastMessage; | ||||
65 | temp.replace(QStringLiteral("SD printing byte"), QString()); | ||||
66 | qlonglong total = temp.mid(temp.lastIndexOf(QChar::fromLatin1('/')) + 1, temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))).toLongLong(); | ||||
67 | if (total != 0) { | ||||
patrickelectric: if(total) | |||||
68 | temp.chop(temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))); | ||||
69 | qlonglong remaining = total - temp.toLongLong(); | ||||
70 | float progress = float(total - remaining) * 100 / float(total); | ||||
71 | core()->printProgressChanged(progress); | ||||
patrickelectric: !total | |||||
72 | if (progress >= 100) { | ||||
73 | core()->setState(AtCore::FINISHEDPRINT); | ||||
74 | core()->setState(AtCore::IDLE); | ||||
75 | } | ||||
76 | } else { | ||||
77 | core()->setState(AtCore::FINISHEDPRINT); | ||||
78 | core()->setState(AtCore::IDLE); | ||||
patrickelectric: total - temp.toLongLong(); | |||||
79 | } | ||||
80 | } | ||||
81 | if (lastMessage.contains(QStringLiteral("ok"))) { | ||||
patrickelectric: Maybe, it's more safe to use progress >= 100 | |||||
82 | emit readyForCommand(); | ||||
83 | } | ||||
84 | } | ||||
85 | } |
else ?