diff options
Diffstat (limited to 'src/printerclient.cpp')
| -rw-r--r-- | src/printerclient.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/printerclient.cpp b/src/printerclient.cpp index 3a548e9..c19e2a8 100644 --- a/src/printerclient.cpp +++ b/src/printerclient.cpp @@ -92,9 +92,28 @@ void PrinterClient::onErrorOccured(QSerialPort::SerialPortError error) Esp32Stand::Esp32Stand(const QHostAddress &address, const uint32_t port, const uint32_t stepsPerMm) : m_apiRoot{QStringLiteral("http://") + address.toString() + ':' + QString::number(port)} , INIT_FIELD(stepsPerMm) - , m_manager{new QNetworkAccessManager{this}} + // , m_manager{new QNetworkAccessManager{this}} + // WARNING: memleak + , m_manager{new QNetworkAccessManager{}} {} +bool Esp32Stand::resetPosSteps() +{ + m_posSteps = 0; + + return true; +} + +int Esp32Stand::posSteps() +{ + return m_posSteps; +} + +double Esp32Stand::posMm() +{ + return m_posSteps / double(m_stepsPerMm); +} + bool Esp32Stand::moveMm(const double mm) { return moveSteps(mm * m_stepsPerMm); @@ -103,23 +122,30 @@ bool Esp32Stand::moveMm(const double mm) bool Esp32Stand::moveSteps(const int steps) { qDebug() << __func__ << "move" << steps << "steps"; - QElapsedTimer t; - t.start(); + // QElapsedTimer t; + // t.start(); + QUrlQuery query; query.addQueryItem(QStringLiteral("steps"), QString::number(steps)); + // qDebug() << "here-2"; QUrl url{m_apiRoot + QStringLiteral("/move")}; url.setQuery(query); std::mutex mtx; + // qDebug() << "here-1"; + const auto reply = m_manager->get(QNetworkRequest{url}); + // qDebug() << "here-123"; mtx.lock(); + // qDebug() << "here"; connect(reply, &QNetworkReply::finished, this, [reply, &mtx]() { qDebug() << reply->readAll(); mtx.unlock(); }); + // qDebug() << "here2"; while (!reply->isFinished()) { reply->waitForReadyRead(100); @@ -131,7 +157,11 @@ bool Esp32Stand::moveSteps(const int steps) std::lock_guard g{mtx}; - qDebug() << __func__ << "moved" << steps << "steps" << t.elapsed(); + // qDebug() << __func__ << "moved" << steps << "steps" << t.elapsed(); + + m_posSteps += steps; + + emit moveFinished(); return true; } |
