Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/marlinplugin.cpp
Show All 16 Lines | 1 | /* AtCore KDE Libary for 3D Printers | |||
---|---|---|---|---|---|
17 | This library is distributed in the hope that it will be useful, | 17 | This library is distributed in the hope that it will be useful, | ||
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
20 | Lesser General Public License for more details. | 20 | Lesser General Public License for more details. | ||
21 | 21 | | |||
22 | You should have received a copy of the GNU Lesser General Public | 22 | You should have received a copy of the GNU Lesser General Public | ||
23 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 23 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
24 | */ | 24 | */ | ||
25 | #include <QFileInfo> | ||||
25 | #include <QLoggingCategory> | 26 | #include <QLoggingCategory> | ||
27 | #include <QRegularExpression> | ||||
26 | #include <QString> | 28 | #include <QString> | ||
27 | 29 | | |||
28 | #include "marlinplugin.h" | 30 | #include "marlinplugin.h" | ||
29 | #include "atcore.h" | 31 | #include "atcore.h" | ||
30 | 32 | | |||
31 | Q_LOGGING_CATEGORY(MARLIN_PLUGIN, "org.kde.atelier.core.firmware.marlin") | 33 | Q_LOGGING_CATEGORY(MARLIN_PLUGIN, "org.kde.atelier.core.firmware.marlin") | ||
32 | 34 | | |||
33 | QString MarlinPlugin::name() const | 35 | QString MarlinPlugin::name() const | ||
34 | { | 36 | { | ||
35 | return QStringLiteral("Marlin"); | 37 | return QStringLiteral("Marlin"); | ||
36 | } | 38 | } | ||
37 | 39 | | |||
38 | bool MarlinPlugin::isSdSupported() const | 40 | bool MarlinPlugin::isSdSupported() const | ||
39 | { | 41 | { | ||
40 | return true; | 42 | return true; | ||
41 | } | 43 | } | ||
42 | 44 | | |||
43 | MarlinPlugin::MarlinPlugin() | 45 | MarlinPlugin::MarlinPlugin() | ||
44 | { | 46 | { | ||
45 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | 47 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | ||
46 | } | 48 | } | ||
47 | 49 | | |||
50 | QByteArray MarlinPlugin::translate(const QString &command) | ||||
51 | { | ||||
52 | //Capture M28 <string> | ||||
53 | static const auto marlin_M28RegEx = QRegularExpression(QStringLiteral("M28 \\S+")); | ||||
patrickelectric: M280 is a valid gcode. | |||||
Good point I will change it to a Regex that looks for M28 <string> rizzitello: Good point I will change it to a Regex that looks for M28 <string> | |||||
54 | //Capture both M29 and M29 <string> but not M290 | ||||
55 | static const auto marlin_M29RegEx = QRegularExpression(QStringLiteral("M29( \\S*)?[^0]")); | ||||
56 | | ||||
57 | QString temp = command; | ||||
58 | if (marlin_M28RegEx.match(command).hasMatch()) { | ||||
59 | QString filename = temp.mid(4, temp.length()); | ||||
60 | filename = shortName(filename); | ||||
61 | temp = QStringLiteral("M28 %1").arg(filename); | ||||
62 | | ||||
63 | } else if (marlin_M29RegEx.match(command).hasMatch()) { | ||||
64 | if (temp.length() > 3) { | ||||
65 | //command contains file name | ||||
66 | QString filename = temp.mid(4, temp.length()); | ||||
67 | filename = shortName(filename); | ||||
68 | temp = QStringLiteral("M29 %1").arg(filename); | ||||
69 | } else { | ||||
70 | temp = QStringLiteral("M29"); | ||||
71 | } | ||||
temp = QStringLiteral("M29"); tcanabrava: temp = QStringLiteral("M29");
if (temp.length()) {
...
temp += " " + filename;
} ? | |||||
72 | } | ||||
73 | | ||||
74 | return temp.toLocal8Bit(); | ||||
75 | } | ||||
76 | | ||||
48 | void MarlinPlugin::validateCommand(const QString &lastMessage) | 77 | void MarlinPlugin::validateCommand(const QString &lastMessage) | ||
49 | { | 78 | { | ||
50 | if (lastMessage.contains(QStringLiteral("End file list"))) { | 79 | if (lastMessage.contains(QStringLiteral("End file list"))) { | ||
51 | core()->setReadingSdCardList(false); | 80 | core()->setReadingSdCardList(false); | ||
52 | } else if (core()->isReadingSdCardList()) { | 81 | } else if (core()->isReadingSdCardList()) { | ||
53 | // Below is to not add directories | 82 | // Below is to not add directories | ||
54 | if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { | 83 | if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { | ||
55 | QString fileName = lastMessage; | 84 | QString fileName = lastMessage; | ||
Show All 35 Lines | 118 | } else { | |||
91 | core()->setState(AtCore::IDLE); | 120 | core()->setState(AtCore::IDLE); | ||
92 | } | 121 | } | ||
93 | } | 122 | } | ||
94 | if (lastMessage.contains(QStringLiteral("ok"))) { | 123 | if (lastMessage.contains(QStringLiteral("ok"))) { | ||
95 | emit readyForCommand(); | 124 | emit readyForCommand(); | ||
96 | } | 125 | } | ||
97 | } | 126 | } | ||
98 | } | 127 | } | ||
128 | | ||||
129 | QString MarlinPlugin::shortName(const QString &fileName) | ||||
130 | { | ||||
131 | //Generate an 8.3 Like FileName. | ||||
132 | QString newName(QStringLiteral(".")); | ||||
tcanabrava: QLatin1Char('.') ? | |||||
133 | QFileInfo info(fileName); | ||||
patrickelectric: Check qfileinfo | |||||
This class does not currently include QFileInfo is that lighter then doing this one call? rizzitello: This class does not currently include QFileInfo is that lighter then doing this one call? | |||||
patrickelectric: There is at least 3 places to use qfileinfo in this patch. | |||||
Sorry, about this file, I do see why not, and this will be only be called once. patrickelectric: Sorry, about this file, I do see why not, and this will be only be called once. | |||||
134 | newName.prepend(info.baseName().toUpper()); | ||||
135 | | ||||
136 | if (newName.length() > 8) { | ||||
137 | newName.resize(8); | ||||
138 | } | ||||
139 | | ||||
140 | newName.append(info.suffix().toUpper()); | ||||
141 | newName.replace(QStringLiteral(".GCODE"), QStringLiteral(".GCO")); | ||||
142 | return newName; | ||||
143 | } |
M280 is a valid gcode.