Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/marlinplugin.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | #include "marlinplugin.h" | 21 | #include "marlinplugin.h" | ||
22 | #include <QLoggingCategory> | 22 | #include <QLoggingCategory> | ||
23 | #include <QString> | 23 | #include <QString> | ||
24 | #include "temperature.h" | 24 | #include "temperature.h" | ||
25 | #include "atcore.h" | 25 | #include "atcore.h" | ||
26 | 26 | | |||
27 | QString MarlinPlugin::_ok = QStringLiteral("ok"); | 27 | QString MarlinPlugin::_ok = QStringLiteral("ok"); | ||
28 | QString MarlinPlugin::_extruderTemp = QStringLiteral("T:"); | | |||
29 | QString MarlinPlugin::_bedTemp = QStringLiteral("B:"); | | |||
30 | 28 | | |||
31 | Q_LOGGING_CATEGORY(MARLIN_PLUGIN, "org.kde.atelier.core.firmware.marlin"); | 29 | Q_LOGGING_CATEGORY(MARLIN_PLUGIN, "org.kde.atelier.core.firmware.marlin"); | ||
32 | 30 | | |||
33 | QString MarlinPlugin::name() const | 31 | QString MarlinPlugin::name() const | ||
34 | { | 32 | { | ||
35 | return QStringLiteral("Marlin"); | 33 | return QStringLiteral("Marlin"); | ||
36 | } | 34 | } | ||
37 | 35 | | |||
38 | float _lastBedTemp; | 36 | MarlinPlugin::MarlinPlugin() | ||
39 | float _lastExtruderTemp; | | |||
40 | float _lastTargetBedTemp; | | |||
41 | float _lastTargetExtruderTemp; | | |||
42 | | ||||
43 | MarlinPlugin::MarlinPlugin() : | | |||
44 | _lastBedTemp(0.0f), | | |||
45 | _lastExtruderTemp(0.0f), | | |||
46 | _lastTargetBedTemp(0.0f), | | |||
47 | _lastTargetExtruderTemp(0.0f) | | |||
48 | { | 37 | { | ||
49 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | 38 | qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; | ||
50 | } | 39 | } | ||
51 | 40 | | |||
52 | void MarlinPlugin::extractTemp(const QString &lastMessage) | | |||
53 | { | | |||
54 | QStringList list = lastMessage.split(QChar::fromLatin1(' ')); | | |||
55 | bool hasBed = lastMessage.contains(_bedTemp); | | |||
56 | if (list.length() < 5) { | | |||
57 | // T:151.10 E:0 B:63.2 | | |||
58 | // T:142.6 E:0 W:? | | |||
59 | | ||||
60 | if (list[0].indexOf(_extruderTemp) == 0) { | | |||
61 | _lastExtruderTemp = list[0].mid(2).toFloat(); | | |||
62 | } | | |||
63 | if (hasBed && list[2].indexOf(_bedTemp) == 0) { | | |||
64 | _lastBedTemp = list[2].mid(2).toFloat(); | | |||
65 | } | | |||
66 | } else { | | |||
67 | // ok T:185.4 /185.0 B:60.5 /60.0 | | |||
68 | | ||||
69 | // T:185.4 - current temperature | | |||
70 | _lastExtruderTemp = list[1].mid(2).toFloat(); | | |||
71 | // /185.0 - target temperature | | |||
72 | _lastTargetExtruderTemp = list[2].mid(1).toFloat(); | | |||
73 | if (hasBed) { | | |||
74 | // B:185.4 - current temperature | | |||
75 | _lastBedTemp = list[3].mid(2).toFloat(); | | |||
76 | // /60.0 - target temperature | | |||
77 | _lastTargetBedTemp = list[4].mid(1).toFloat(); | | |||
78 | } | | |||
79 | } | | |||
80 | core()->temperature().setExtruderTemperature(_lastExtruderTemp); | | |||
81 | core()->temperature().setExtruderTargetTemperature(_lastTargetExtruderTemp); | | |||
82 | if (hasBed) { | | |||
83 | core()->temperature().setBedTemperature(_lastBedTemp); | | |||
84 | core()->temperature().setBedTargetTemperature(_lastTargetBedTemp); | | |||
85 | } | | |||
86 | } | | |||
87 | | ||||
88 | void MarlinPlugin::validateCommand(const QString &lastMessage) | 41 | void MarlinPlugin::validateCommand(const QString &lastMessage) | ||
89 | { | 42 | { | ||
90 | if (lastMessage.contains(_extruderTemp) || lastMessage.contains(_bedTemp)) { | | |||
91 | extractTemp(lastMessage); | | |||
92 | } | | |||
93 | if (lastMessage.contains(_ok)) { | 43 | if (lastMessage.contains(_ok)) { | ||
94 | emit readyForCommand(); | 44 | emit readyForCommand(); | ||
95 | } | 45 | } | ||
96 | } | 46 | } | ||
97 | 47 | | |||
98 | QByteArray MarlinPlugin::translate(const QString &command) | 48 | QByteArray MarlinPlugin::translate(const QString &command) | ||
99 | { | 49 | { | ||
100 | return command.toLocal8Bit(); | 50 | return command.toLocal8Bit(); | ||
101 | } | 51 | } |