summaryrefslogtreecommitdiff
path: root/src/printerclient.h
blob: 189bfb5118ec225a658eb7a5b5cb2256928103c6 (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
#pragma once

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

class QSerialPort;

class IStand
{
public:
    virtual ~IStand() = default;

public:
    /*!
     * \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 QObject, public IStand
{
public:
    explicit Esp32Stand(const QHostAddress &address, const uint32_t port, const uint32_t stepsPerMm);
    ~Esp32Stand() override = default;

public:
    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};
};

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 };
};