summaryrefslogtreecommitdiff
path: root/src/printerclient.h
blob: 232dad83f67296fd8f1ba6fc215b975df43e0495 (plain)
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
#pragma once

#include <QHostAddress>
#include <QNetworkAccessManager>
#include <QObject>
#include <QSerialPort>

class QSerialPort;

class IStand : public QObject
{
    Q_OBJECT

public:
    virtual ~IStand() = default;

signals:
    void moveFinished();

public:
    virtual bool resetPosSteps() = 0;
    virtual int posSteps() = 0;
    virtual double posMm() = 0;
    /*!
     * \warning be careful when rounding mm to steps
     */
    virtual bool moveMm(const double mm) = 0;
    virtual bool moveSteps(const int steps) = 0;
};

// TODO: think if QObject is needed
class Esp32Stand : public IStand
{
public:
    explicit Esp32Stand(const QHostAddress &address, const uint32_t port, const uint32_t stepsPerMm);
    ~Esp32Stand() override = default;

public:
    bool resetPosSteps() override;
    int posSteps() override;
    double posMm() override;
    bool moveMm(const double mm) override;
    bool moveSteps(const int steps) override;

private:
    QString m_apiRoot;
    uint32_t m_stepsPerMm{0};
    QNetworkAccessManager *m_manager{nullptr};
    int m_posSteps{0};
};

class PrinterClient : public QObject
{
    // Q_OBJECT

public:
    explicit PrinterClient(QObject *parent = nullptr);
    // ~PrinterClient() override = default;
    // ~PrinterClient

    // signals:
    // void newData(const QString output);

public:
    void sendCommand(const QString command);

private:
    void onReadyRead();
    void onErrorOccured(QSerialPort::SerialPortError error);

private:
    QSerialPort* m_serialPort { nullptr };
};