Changeset View
Changeset View
Standalone View
Standalone View
src/core/temperature.cpp
Show All 25 Lines | |||||
26 | #include <cmath> | 26 | #include <cmath> | ||
27 | 27 | | |||
28 | #include "temperature.h" | 28 | #include "temperature.h" | ||
29 | /** | 29 | /** | ||
30 | * @brief The TemperaturePrivate class | 30 | * @brief The TemperaturePrivate class | ||
31 | * | 31 | * | ||
32 | * Private Data of Temperature | 32 | * Private Data of Temperature | ||
33 | */ | 33 | */ | ||
34 | class Temperature::TemperaturePrivate | 34 | | ||
35 | { | 35 | struct Temperature::TemperaturePrivate { | ||
36 | public: | 36 | /** Regex to capture Bed Temperature grabs : B: to the next space */ | ||
37 | float extruderTemp = 0.0; //!< @param extruderTemp: Extruder current temperature | 37 | static const QRegularExpression bedRegEx; | ||
38 | float extruderTargetTemp = 0.0; //!< @param extruderTargetTemp: Extruder target temperature | 38 | /** bedTemp: Bed current temperature */ | ||
39 | float bedTemp = 0.0; //!< @param bedTemp: Bed current temperature | 39 | float bedTemp = 0.0; | ||
40 | float bedTargetTemp = 0.0; //!< @param bedTargetTemp: Bed target temperature | 40 | /** bedTargetTemp: Bed target temperature */ | ||
41 | float bedTargetTemp = 0.0; | ||||
patrickelectric: alphabetic order | |||||
42 | /** extruderTemp: Extruder current temperature */ | ||||
43 | float extruderTemp = 0.0; | ||||
44 | /** extruderTargetTemp: Extruder target temperature */ | ||||
45 | float extruderTargetTemp = 0.0; | ||||
46 | /** Regex to capture Bed Target Temperature: Find B:## /## and grab the second set of numbers */ | ||||
47 | static const QRegularExpression targetBedRegEx; | ||||
48 | /** Regex to capture Extruder Target Temperature Finds T:## /## and grabs the second set of numbers */ | ||||
49 | static const QRegularExpression targetTempRegEx; | ||||
50 | /** Regex to capture Extruder Temperature Grabs "T: to next space" */ | ||||
51 | static const QRegularExpression tempRegEx; | ||||
41 | }; | 52 | }; | ||
42 | 53 | | |||
54 | const QRegularExpression Temperature::TemperaturePrivate::bedRegEx = QRegularExpression(QStringLiteral(R"(B:(?<bed>\d+\.\d*))")); | ||||
55 | const QRegularExpression Temperature::TemperaturePrivate::targetBedRegEx = QRegularExpression(QStringLiteral(R"(B:[^\/]*\/(?<bedTarget>\d+\.?\d*))")); | ||||
56 | const QRegularExpression Temperature::TemperaturePrivate::targetTempRegEx = QRegularExpression(QStringLiteral(R"(T:[^\/]*\/(?<extruderTarget>\d+\.?\d*))")); | ||||
57 | const QRegularExpression Temperature::TemperaturePrivate::tempRegEx = QRegularExpression(QStringLiteral(R"(T:(?<extruder>\d+\.\d*))")); | ||||
patrickelectric: you can use auto here. | |||||
It will not build if auto is used. Compiler complains about redefined variable. rizzitello: It will not build if auto is used. Compiler complains about redefined variable. | |||||
58 | | ||||
43 | Temperature::Temperature(QObject *parent) | 59 | Temperature::Temperature(QObject *parent) | ||
44 | : QObject(parent) | 60 | : QObject(parent) | ||
45 | , d(new TemperaturePrivate) | 61 | , d(new TemperaturePrivate) | ||
46 | { | 62 | { | ||
47 | } | 63 | } | ||
48 | 64 | | |||
49 | float Temperature::bedTargetTemperature() const | 65 | float Temperature::bedTargetTemperature() const | ||
50 | { | 66 | { | ||
Show All 36 Lines | |||||
87 | void Temperature::setExtruderTemperature(float temp) | 103 | void Temperature::setExtruderTemperature(float temp) | ||
88 | { | 104 | { | ||
89 | d->extruderTemp = temp; | 105 | d->extruderTemp = temp; | ||
90 | emit extruderTemperatureChanged(temp); | 106 | emit extruderTemperatureChanged(temp); | ||
91 | } | 107 | } | ||
92 | 108 | | |||
93 | void Temperature::decodeTemp(const QByteArray &msg) | 109 | void Temperature::decodeTemp(const QByteArray &msg) | ||
94 | { | 110 | { | ||
95 | //Capture after T: until next space | 111 | QString msgString = QString::fromLatin1(msg); | ||
96 | static const QRegularExpression tempRegEx(QStringLiteral(R"(T:(?<extruder>\d+\.\d*))")); | 112 | QRegularExpressionMatch tempCheck = d->tempRegEx.match(msgString); | ||
97 | QRegularExpressionMatch tempCheck = tempRegEx.match(QString::fromLatin1(msg)); | 113 | QRegularExpressionMatch targetTempCheck = d->targetTempRegEx.match(msgString); | ||
patrickelectric: msgString = QString::fromLatin1(msg) to avoid the usage of fromLatin1 | |||||
98 | //Find T:## /## and store the second set of numbers | | |||
99 | static const QRegularExpression targetTempRegEx(QStringLiteral(R"(T:[^\/]*\/(?<extruderTarget>\d+\.?\d*))")); | | |||
100 | QRegularExpressionMatch targetTempCheck = targetTempRegEx.match(QString::fromLatin1(msg)); | | |||
101 | 114 | | |||
102 | if (tempCheck.hasMatch()) { | 115 | if (tempCheck.hasMatch()) { | ||
103 | setExtruderTemperature(tempCheck.captured(QStringLiteral("extruder")).toFloat()); | 116 | setExtruderTemperature(tempCheck.captured(QStringLiteral("extruder")).toFloat()); | ||
104 | } | 117 | } | ||
105 | 118 | | |||
106 | if (targetTempCheck.hasMatch()) { | 119 | if (targetTempCheck.hasMatch()) { | ||
107 | setExtruderTargetTemperature(targetTempCheck.captured(QStringLiteral("extruderTarget")).toFloat()); | 120 | setExtruderTargetTemperature(targetTempCheck.captured(QStringLiteral("extruderTarget")).toFloat()); | ||
108 | } | 121 | } | ||
109 | 122 | | |||
110 | if (msg.indexOf(QStringLiteral("B:")) != -1) { | 123 | if (msg.indexOf(QStringLiteral("B:")) != -1) { | ||
111 | //Capture after B: until next space | 124 | QRegularExpressionMatch bedCheck = d->bedRegEx.match(msgString); | ||
112 | static const QRegularExpression bedRegEx(QStringLiteral(R"(B:(?<bed>\d+\.\d*))")); | 125 | QRegularExpressionMatch targetBedCheck = d->targetBedRegEx.match(msgString); | ||
113 | QRegularExpressionMatch bedCheck = bedRegEx.match(QString::fromLatin1(msg)); | | |||
114 | //Find B:## /## and store the second set of numbers | | |||
115 | static QRegularExpression targetBedRegEx(QStringLiteral(R"(B:[^\/]*\/(?<bedTarget>\d+\.?\d*))")); | | |||
116 | QRegularExpressionMatch targetBedCheck = targetBedRegEx.match(QString::fromLatin1(msg)); | | |||
117 | 126 | | |||
118 | if (bedCheck.hasMatch()) { | 127 | if (bedCheck.hasMatch()) { | ||
119 | setBedTemperature(bedCheck.captured(QStringLiteral("bed")).toFloat()); | 128 | setBedTemperature(bedCheck.captured(QStringLiteral("bed")).toFloat()); | ||
120 | } | 129 | } | ||
121 | 130 | | |||
122 | if (targetBedCheck.hasMatch()) { | 131 | if (targetBedCheck.hasMatch()) { | ||
123 | setBedTargetTemperature(targetBedCheck.captured(QStringLiteral("bedTarget")).toFloat()); | 132 | setBedTargetTemperature(targetBedCheck.captured(QStringLiteral("bedTarget")).toFloat()); | ||
124 | } | 133 | } | ||
125 | } | 134 | } | ||
126 | } | 135 | } |
alphabetic order