Changeset View
Changeset View
Standalone View
Standalone View
src/temperature.cpp
Show All 12 Lines | 1 | /* AtCore | |||
---|---|---|---|---|---|
13 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
17 | 17 | | |||
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | | ||||
22 | #include <QRegularExpressionMatch> | ||||
23 | | ||||
21 | #include "temperature.h" | 24 | #include "temperature.h" | ||
22 | #include <cmath> | 25 | #include <cmath> | ||
23 | 26 | | |||
24 | class TemperaturePrivate | 27 | class TemperaturePrivate | ||
25 | { | 28 | { | ||
26 | public: | 29 | public: | ||
27 | float extruderTemp; | 30 | float extruderTemp; | ||
28 | float extruderTargetTemp; | 31 | float extruderTargetTemp; | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 75 | { | |||
74 | emit extruderTargetTemperatureChanged(temp); | 77 | emit extruderTargetTemperatureChanged(temp); | ||
75 | } | 78 | } | ||
76 | 79 | | |||
77 | void Temperature::setExtruderTemperature(float temp) | 80 | void Temperature::setExtruderTemperature(float temp) | ||
78 | { | 81 | { | ||
79 | d->extruderTemp = temp; | 82 | d->extruderTemp = temp; | ||
80 | emit extruderTemperatureChanged(temp); | 83 | emit extruderTemperatureChanged(temp); | ||
81 | } | 84 | } | ||
85 | | ||||
86 | void Temperature::decodeTemp(const QByteArray &msg) | ||||
87 | { | ||||
88 | QRegularExpression tempRegEx(QStringLiteral("(T:(?<extruder>\\d+\\.?\\d*))")); | ||||
89 | QRegularExpression targetTempRegEx(QStringLiteral("(\\/)(?<extruderTarget>\\d*)(.+)")); | ||||
90 | QRegularExpressionMatch tempCheck = tempRegEx.match(QString::fromLatin1(msg)); | ||||
91 | QRegularExpressionMatch targetTempCheck = targetTempRegEx.match(QString::fromLatin1(msg)); | ||||
92 | | ||||
93 | if (tempCheck.hasMatch()) { | ||||
94 | setExtruderTemperature(tempCheck.captured(QStringLiteral("extruder")).toFloat()); | ||||
95 | } | ||||
96 | if (targetTempCheck.hasMatch()) { | ||||
97 | setExtruderTargetTemperature(targetTempCheck.captured(QStringLiteral("extruderTarget")).toFloat()); | ||||
98 | } | ||||
99 | | ||||
100 | if (msg.contains(QString::fromLatin1("B:").toLocal8Bit())) { | ||||
101 | QRegularExpression bedRegEx(QStringLiteral("(B:(?<bed>\\d+\\.?\\d*))")); | ||||
102 | QRegularExpressionMatch bedCheck = bedRegEx.match(QString::fromLatin1(msg)); | ||||
103 | QRegularExpression targetBedRegEx(QStringLiteral("B:(.+)(\\/)(?<bedTarget>\\d+)")); | ||||
104 | QRegularExpressionMatch targetBedCheck = targetBedRegEx.match(QString::fromLatin1(msg)); | ||||
105 | | ||||
106 | if (bedCheck.hasMatch()) { | ||||
107 | setBedTemperature(bedCheck.captured(QStringLiteral("bed")).toFloat()); | ||||
108 | } | ||||
109 | | ||||
110 | if (targetBedCheck.hasMatch()) { | ||||
111 | setBedTargetTemperature(targetBedCheck.captured(QStringLiteral("bedTarget")).toFloat()); | ||||
112 | } | ||||
113 | | ||||
114 | } | ||||
115 | } | ||||
116 | No newline at end of file |