forked from apsystems/GrblHoming
-
Notifications
You must be signed in to change notification settings - Fork 190
/
gcode.h
186 lines (166 loc) · 5.29 KB
/
gcode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/****************************************************************
* gcode.h
* GrblHoming - zapmaker fork on github
*
* 15 Nov 2012
* GPL License (see LICENSE file)
* Software is provided AS-IS
****************************************************************/
#ifndef GCODE_H
#define GCODE_H
#include "log4qtdef.h"
#include <QString>
#include <QFile>
#include <QThread>
#include <QTextStream>
#include "definitions.h"
#include "rs232.h"
#include "coord3d.h"
#include "controlparams.h"
#define BUF_SIZE 300
#define RESPONSE_OK "ok"
#define RESPONSE_ERROR "error"
// as defined in the grbl project on github...
#define GRBL_RX_BUFFER_SIZE 128
#define CTRL_X '\x18'
#define DEFAULT_AXIS_COUNT 3
#define MAX_AXIS_COUNT 4
class CmdResponse
{
public:
CmdResponse(const char *buf, int c, int l) : cmd(buf), count(c), line(l)
{
waitForMe = false;
if (buf[0] == 'M')
{
int value = cmd.mid(1,-1).toInt();
if (value == 9)
waitForMe = true;
}
}
public:
QString cmd;
int count;
int line;
bool waitForMe;
};
class DecimalFilter
{
public:
DecimalFilter(QString t) : token(t), decimals(0) {}
public:
QString token;
int decimals;
};
class GCode : public QObject
{
Q_OBJECT
public:
GCode();
void setAbort();
void setReset();
void setShutdown();
int getSettingsItemCount();
int getNumaxis();
static void trimToEnd(QString& strline, QChar);
signals:
void addList(QString line);
void addListFull(QStringList list);
void addListOut(QString line);
void sendMsg(QString msg);
void stopSending();
void portIsClosed(bool reopen);
void portIsOpen(bool sendCode);
void setCommandText(QString value);
void adjustedAxis();
void gcodeResult(int id, QString result);
void setProgress(int);
void setQueuedCommands(int, bool);
void resetTimer(bool timeIt);
void enableGrblDialogButton();
void updateCoordinates(Coord3D machineCoord, Coord3D workCoord);
void setLastState(QString state);
void setUnitsWork(QString value);
void setUnitsMachine(QString value);
void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
void setVisCurrLine(int currLine);
void setLcdState(bool valid);
void setVisualLivenessCurrPos(bool isLiveCP);
public slots:
void openPort(QString commPortStr, QString baudRate);
void closePort(bool reopen);
void sendGcode(QString line);
void sendGcodeAndGetResult(int id, QString line);
void sendFile(QString path);
void gotoXYZFourth(QString line);
void axisAdj(char axis, float coord, bool inv, bool absoluteAfterAxisAdj, int sliderZCount);
void setResponseWait(ControlParams controlParams);
void grblSetHome();
void sendGrblReset();
void sendGrblUnlock();
void goToHome();
protected:
void timerEvent(QTimerEvent *event);
private:
enum PosReqStatus
{
POS_REQ_RESULT_OK,
POS_REQ_RESULT_ERROR,
POS_REQ_RESULT_TIMER_SKIP,
POS_REQ_RESULT_UNAVAILABLE
};
private:
bool sendGcodeLocal(QString line, bool recordResponseOnFail = false, int waitSec = -1, bool aggressive = false, int currLine = 0);
bool waitForOk(QString& result, int waitCount, bool sentReqForLocation, bool sentReqForParserState, bool aggressive, bool finalize);
bool waitForStartupBanner(QString& result, int waitSec, bool failOnNoFound);
bool sendGcodeInternal(QString line, QString& result, bool recordResponseOnFail, int waitSec, bool aggressive, int currLine = 0);
QString removeUnsupportedCommands(QString line);
QString reducePrecision(QString line);
bool isGCommandValid(float value, bool& toEndOfLine);
bool isMCommandValid(float value);
bool isPortOpen();
QString getMoveAmountFromString(QString prefix, QString item);
bool SendJog(QString strline, bool absoluteAfterAxisAdj);
void parseCoordinates(const QString& received, bool aggressive);
void pollPosWaitForIdle(bool checkMeasurementUnits);
void checkAndSetCorrectMeasurementUnits();
void setOldFormatMeasurementUnitControl();
void setUnitsTypeDisplay(bool millimeters);
void setConfigureMmMode(bool setGrblUnits);
void setConfigureInchesMode(bool setGrblUnits);
QStringList doZRateLimit(QString strline, QString& msg, bool& xyRateSet);
void sendStatusList(QStringList& listToSend);
void clearToHome();
bool checkGrbl(const QString& result);
PosReqStatus positionUpdate(bool forceIfEnabled = false);
bool checkForGetPosStr(QString& line);
void setLivenessState(bool valid);
private:
RS232 port;
AtomicIntBool abortState;
AtomicIntBool resetState;
AtomicIntBool shutdownState;
ControlParams controlParams;
int errorCount;
QString currComPort;
bool doubleDollarFormat;
AtomicIntBool settingsItemCount;
QString lastState;
bool incorrectMeasurementUnits;
bool incorrectLcdDisplayUnits;
Coord3D machineCoord, workCoord;
Coord3D machineCoordLastIdlePos, workCoordLastIdlePos;
double maxZ;
QList<CmdResponse> sendCount;
QTime parseCoordTimer;
bool motionOccurred;
int sliderZCount;
QStringList grblCmdErrors;
QStringList grblFilteredCmds;
QTime pollPosTimer;
bool positionValid;
int sentI;
int rcvdI;
int numaxis;
};
#endif // GCODE_H