Changeset View
Standalone View
src/plugins/grblplugin.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
48 | { | 48 | { | ||
49 | if (lastMessage.contains(QStringLiteral("ok"))) { | 49 | if (lastMessage.contains(QStringLiteral("ok"))) { | ||
50 | emit readyForCommand(); | 50 | emit readyForCommand(); | ||
51 | } | 51 | } | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | QByteArray GrblPlugin::translate(const QString &command) | 54 | QByteArray GrblPlugin::translate(const QString &command) | ||
55 | { | 55 | { | ||
56 | QString temp = command; | 56 | QStringList temp({command}); | ||
57 | | ||||
57 | //Match all G and M commands followed by one or more digits up to and include the space, | 58 | //Match all G and M commands followed by one or more digits up to and include the space, | ||
58 | //if thats followed by a letter capture any non G or M starting text | 59 | //if thats followed by a letter capture any non G or M starting text | ||
59 | //else just grab the digits that follow. | 60 | //else just grab the digits that follow. | ||
60 | //ex: G28 X Y M1 would capture "G28 X Y" and "M1" | 61 | //ex: G28 X Y M1 would capture "G28 X Y" and "M1" | ||
61 | static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.(?(?=\\D)[^GM]+|\\d+)?")); | 62 | static const auto regEx = QRegularExpression(QStringLiteral("[gGmM]\\d+(?(?=\\D)[^gGmM]+\\d+)?")); | ||
62 | 63 | QRegularExpressionMatch secondCommand = regEx.match(command); | |||
63 | QRegularExpressionMatch secondCommand = regEx.match(temp, 1); | | |||
64 | 64 | | |||
65 | if (secondCommand.hasMatch()) { | 65 | if (secondCommand.hasMatch()) { | ||
66 | QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(temp); | 66 | QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(command); | ||
67 | temp.clear(); | 67 | temp.clear(); | ||
68 | while (commandMatch.hasNext()) { | 68 | while (commandMatch.hasNext()) { | ||
69 | QRegularExpressionMatch t = commandMatch.next(); | 69 | QRegularExpressionMatch t = commandMatch.next(); | ||
70 | temp.append(t.captured().simplified()); | 70 | temp.append(t.captured().simplified()); | ||
rizzitello: what if this is a G91 or G90? | |||||
71 | if (commandMatch.hasNext()) { | | |||
72 | temp.append(QStringLiteral("\r\n")); | | |||
73 | } | 71 | } | ||
74 | } | 72 | } | ||
73 | | ||||
74 | for (int i = 0; i < temp.size(); i++) { | ||||
rizzitello: for (const QString & string : QString temp )? | |||||
have you tested this with our cnc test file? cncteste.gcode1 KBDownload rizzitello: have you tested this with our cnc test file?
{F6231175}
| |||||
Can't be const, I'm editing it. patrickelectric: Can't be const, I'm editing it.
But it's possible to change to Qstring& cmd : temp. This is a… | |||||
rizzitello: Ok | |||||
75 | if (temp[i].contains(QStringLiteral("G91"))) { | ||||
76 | _isInRelativeMode = true; | ||||
77 | temp[i] = QString(); | ||||
78 | } else if (temp[i].contains(QStringLiteral("G90"))) { | ||||
79 | _isInRelativeMode = false; | ||||
80 | temp[i] = QString(); | ||||
81 | } else if (temp[i].contains(QStringLiteral("G1 ")) || temp[i].contains(QStringLiteral("G01 "))) { | ||||
82 | if (_isInRelativeMode) { | ||||
83 | temp[i] = temp[i].replace(QStringLiteral("G1 "), QStringLiteral("G91 ")); | ||||
84 | temp[i] = temp[i].replace(QStringLiteral("G01 "), QStringLiteral("G91 ")); | ||||
85 | } | ||||
86 | } else if (temp[i].contains(QStringLiteral("M84"))) { | ||||
87 | temp[i] = QStringLiteral("M3 S0"); | ||||
88 | } | ||||
75 | } | 89 | } | ||
If not else If Since grbl can have several commands on one line we want to check for each of our possible commands to be replaced so if we have command like "G91 G1 X5 M84 S0" New Translation strings are missing test cases. rizzitello: If not else If
Since grbl can have several commands on one line we want to check for each of… | |||||
76 | return temp.toLocal8Bit(); | 90 | temp.removeAll(QString()); | ||
91 | return temp.join(QStringLiteral("\n\r")).toLocal8Bit(); | ||||
rizzitello: temp.replace("G91", "");
| |||||
77 | } | 92 | } | ||
rizzitello: temp.replace( "M84", "M3 S0");
check also for M84 S<int>
a Regex like "M84( \\Sd+)?[^0-9]"… | |||||
patrickelectric: M84 does not exist in grbl. Why do you want a check for M84 SX ? What is the meaning of that… | |||||
when we send disable motors we send a M84 S0 command. rizzitello: >On Marlin, Repetier and RepRapFirmware, M84 can also be used to configure or disable the idle… | |||||
patrickelectric: Got it. |
what if this is a G91 or G90?