Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/sprinterplugin.cpp
Show All 20 Lines | |||||
21 | #include "sprinterplugin.h" | 21 | #include "sprinterplugin.h" | ||
22 | #include "temperature.h" | 22 | #include "temperature.h" | ||
23 | #include "atcore.h" | 23 | #include "atcore.h" | ||
24 | 24 | | |||
25 | #include <QLoggingCategory> | 25 | #include <QLoggingCategory> | ||
26 | #include <QString> | 26 | #include <QString> | ||
27 | 27 | | |||
28 | QString SprinterPlugin::_ok = QStringLiteral("ok"); | 28 | QString SprinterPlugin::_ok = QStringLiteral("ok"); | ||
29 | QString SprinterPlugin::_extruderTemp = QStringLiteral("T:"); | | |||
30 | QString SprinterPlugin::_bedTemp = QStringLiteral("B:"); | | |||
31 | 29 | | |||
32 | Q_LOGGING_CATEGORY(SPRINTER_PLUGIN, "org.kde.atelier.core.firmware.sprinter"); | 30 | Q_LOGGING_CATEGORY(SPRINTER_PLUGIN, "org.kde.atelier.core.firmware.sprinter"); | ||
33 | 31 | | |||
34 | QString SprinterPlugin::name() const | 32 | QString SprinterPlugin::name() const | ||
35 | { | 33 | { | ||
36 | return QStringLiteral("Sprinter"); | 34 | return QStringLiteral("Sprinter"); | ||
37 | } | 35 | } | ||
38 | 36 | | |||
39 | SprinterPlugin::SprinterPlugin() | 37 | SprinterPlugin::SprinterPlugin() | ||
40 | { | 38 | { | ||
41 | qCDebug(SPRINTER_PLUGIN) << name() << " plugin loaded!"; | 39 | qCDebug(SPRINTER_PLUGIN) << name() << " plugin loaded!"; | ||
42 | } | 40 | } | ||
43 | 41 | | |||
44 | void SprinterPlugin::extractTemp(const QString &lastMessage) | | |||
45 | { | | |||
46 | // ok T:185.4 @:0 B:60.5 | | |||
47 | QStringList list = lastMessage.split(QChar::fromLatin1(' ')); | | |||
48 | | ||||
49 | // T:185.4 - current temperature | | |||
50 | core()->temperature().setExtruderTemperature(list[1].mid(2).toFloat()); | | |||
51 | if (lastMessage.contains(_bedTemp)) { | | |||
52 | // B:185.4 - current temperature | | |||
53 | core()->temperature().setBedTemperature(list[3].mid(2).toFloat()); | | |||
54 | } | | |||
55 | } | | |||
56 | | ||||
57 | void SprinterPlugin::validateCommand(const QString &lastMessage) | 42 | void SprinterPlugin::validateCommand(const QString &lastMessage) | ||
58 | { | 43 | { | ||
59 | if (lastMessage.contains(_extruderTemp) || lastMessage.contains(_bedTemp)) { | | |||
60 | extractTemp(lastMessage); | | |||
61 | } | | |||
62 | if (lastMessage.contains(_ok)) { | 44 | if (lastMessage.contains(_ok)) { | ||
63 | emit readyForCommand(); | 45 | emit readyForCommand(); | ||
64 | } | 46 | } | ||
65 | } | 47 | } | ||
66 | 48 | | |||
67 | QByteArray SprinterPlugin::translate(const QString &command) | 49 | QByteArray SprinterPlugin::translate(const QString &command) | ||
68 | { | 50 | { | ||
69 | return command.toLocal8Bit(); | 51 | return command.toLocal8Bit(); | ||
70 | } | 52 | } | ||
71 | 53 | |