-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgcodeplayer.h
More file actions
84 lines (65 loc) · 1.94 KB
/
gcodeplayer.h
File metadata and controls
84 lines (65 loc) · 1.94 KB
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
#ifndef GCODEPLAYER_H
#define GCODEPLAYER_H
#include <QObject>
#include <QTcpSocket>
#include "gcodeplayermodel.h"
class GcodePlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(GcodePlayerModel* model READ model CONSTANT)
Q_PROPERTY(int currentLineNumber READ currentLineNumber WRITE setCurrentLineNumber NOTIFY currentLineChanged)
Q_PROPERTY(int linesCount READ linesCount NOTIFY linesCountChanged)
Q_PROPERTY(State state READ state NOTIFY stateChanged);
Q_PROPERTY(ConnectionState connectionState READ connectionState NOTIFY connectionStateChanged)
public:
explicit GcodePlayer(QObject *parent = nullptr);
enum State {
Stopped,
Playing,
Paused,
Error
};
Q_ENUM(State)
enum ConnectionState {
Disconnected,
Connecting,
Connected
};
Q_ENUM(ConnectionState)
static void registerQmlTypes();
GcodePlayerModel *model() const;
Q_INVOKABLE void loadFile(const QUrl &fileUrl);
int currentLineNumber() const;
void setCurrentLineNumber(int currentLineNumber);
int linesCount() const;
State state() const;
ConnectionState connectionState() const;
signals:
void currentLineChanged();
void linesCountChanged();
void stateChanged();
void connectionStateChanged();
void connectionStateChanged(bool connected);
public slots:
void connectToMC();
void play();
void pause();
void stop();
void send(const QString &command);
private slots:
void onSocketStateChanged(QAbstractSocket::SocketState state);
void onSocketError(QAbstractSocket::SocketError error);
void onMCResponse();
private:
void sendNextLine();
void processMCResponse(const QString &line);
GcodePlayerModel *m_model;
int m_currentLineNumber;
int m_linesCount;
State m_state;
ConnectionState m_connectionState;
QTcpSocket *m_tcp;
QString m_tcpLine;
bool m_querySent;
};
#endif // GCODEPLAYER_H