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"))) { | ||||
56 | if (lastMessage.contains(QStringLiteral("inserted"))) { | ||||
57 | core()->setSdMounted(true); | ||||
patrickelectric: else ? | |||||
58 | } else if (lastMessage.contains(QStringLiteral("removed"))) { | ||||
59 | core()->setSdMounted(false); | ||||
60 | } | ||||
61 | } else if (lastMessage.contains(QStringLiteral("Begin file list"))) { | ||||
62 | if (!core()->isSdMounted()) { | ||||
patrickelectric: the test is not necessary, just core()->setSdMounted(true); | |||||
63 | core()->setSdMounted(true); | ||||
64 | } | ||||
65 | core()->setReadingSdCardList(true); | ||||
66 | core()->clearSdCardFileList(); | ||||
67 | } else if (lastMessage.contains(QStringLiteral("SD printing byte"))) { | ||||
patrickelectric: if(total) | |||||
68 | QString temp = lastMessage; | ||||
69 | temp.replace(QStringLiteral("SD printing byte"), QString()); | ||||
70 | qlonglong total = temp.mid(temp.lastIndexOf(QChar::fromLatin1('/')) + 1, temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))).toLongLong(); | ||||
71 | if (total == 0) { | ||||
patrickelectric: !total | |||||
72 | core()->setState(AtCore::FINISHEDPRINT); | ||||
73 | core()->setState(AtCore::IDLE); | ||||
74 | return; | ||||
75 | } | ||||
76 | temp.chop(temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))); | ||||
77 | qlonglong currentpos = temp.toLongLong(); | ||||
78 | qlonglong remaining = total - currentpos; | ||||
patrickelectric: total - temp.toLongLong(); | |||||
79 | float progress = float(total - remaining) * 100 / float(total); | ||||
80 | core()->printProgressChanged(progress); | ||||
81 | if (progress == 100) { | ||||
patrickelectric: Maybe, it's more safe to use progress >= 100 | |||||
82 | core()->setState(AtCore::FINISHEDPRINT); | ||||
83 | core()->setState(AtCore::IDLE); | ||||
84 | } | ||||
85 | } | ||||
86 | if (lastMessage.contains(QStringLiteral("ok"))) { | ||||
87 | emit readyForCommand(); | ||||
88 | } | ||||
89 | } | ||||
90 | } |
else ?