diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,6 +13,7 @@ ifirmware.cpp temperature.cpp printthread.cpp + beddeform.cpp ) add_library(AtCore SHARED ${AtCoreLib_SRCS}) @@ -40,6 +41,7 @@ IFirmware SerialLayer Temperature + BedDeform REQUIRED_HEADERS ATCORE_HEADERS ) diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -32,6 +32,7 @@ #include "ifirmware.h" #include "temperature.h" #include "atcore_export.h" +#include "beddeform.h" class SerialLayer; class IFirmware; @@ -535,6 +536,10 @@ */ void handleSerialError(QSerialPort::SerialPortError error); + /** + * @brief The Bed Deform data as told by the Firmware. + */ + BedDeform &bedDeform() const; private: /** diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -62,6 +62,8 @@ int extruderCount = 1; /** temperature: Temperature object */ Temperature temperature; + /** bedDeform: BedDeform object */ + BedDeform bedDeform; /** commandQueue: the list of commands to send to the printer */ QStringList commandQueue; /** ready: True if printer is ready for a command */ @@ -90,6 +92,8 @@ QString sdCardFileName; /** sdCardFileList: List of files on sd card. */ QStringList sdCardFileList; + /** tempMultiString: Hold temp returns for multiline returns when needed */ + QStringList tempMultiString; }; AtCore::AtCore(QObject *parent) : @@ -103,6 +107,12 @@ connect(&d->sdPrintProgressTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); connect(&d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); connect(&d->temperatureTimer, &QTimer::timeout, this, &AtCore::checkTemperature); + + //<<<<<>>>>>>> + connect(&d->bedDeform, &BedDeform::dataChanged, this, [](const QList> &bedData) { + qDebug() << bedData; + }); + //Attempt to find our plugins qCDebug(ATCORE_PLUGIN) << "Detecting Plugin path"; QStringList paths = AtCoreDirectories::pluginDir; @@ -349,6 +359,12 @@ { //Evaluate the messages coming from the printer. d->lastMessage = message; + if (d->lastCommand.startsWith(GCode::toCommand(GCode::GCode::G29))) { + if (d->lastMessage.contains("ok")) { + d->bedDeform.decodeDeform(d->tempMultiString); + } + d->tempMultiString.append(QString::fromLatin1(d->lastMessage)); + } //Check if the message has current coordinates. if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { d->posString = message; @@ -903,3 +919,8 @@ qCDebug(ATCORE_CORE) << "SerialError:" << errorString; emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString)); } + +BedDeform &AtCore::bedDeform() const +{ + return d->bedDeform; +} diff --git a/src/core/beddeform.h b/src/core/beddeform.h new file mode 100644 --- /dev/null +++ b/src/core/beddeform.h @@ -0,0 +1,47 @@ +/* AtCore + Copyright (C) <2019> + + Authors: + Chris Rizzitello + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ +#pragma once + +#include +#include "atcore_export.h" + +/** + * @brief The Bed Deform class + * + * Read and hold data for the Bed Deformation of the printer + */ + +class ATCORE_EXPORT BedDeform : public QObject +{ + Q_OBJECT + +public: + explicit BedDeform(QObject *parent = nullptr); + void decodeDeform(const QStringList &rawData); + QList> bedData(); +signals: + void dataChanged(const QList> &data); +private: + struct BedDeformPrivate; + BedDeformPrivate *d; +}; diff --git a/src/core/beddeform.cpp b/src/core/beddeform.cpp new file mode 100644 --- /dev/null +++ b/src/core/beddeform.cpp @@ -0,0 +1,66 @@ +/* AtCore + Copyright (C) <2019> + + Authors: + Chris Rizzitello + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ +#include + +#include "beddeform.h" + +struct BedDeform::BedDeformPrivate { + /** bedData Beddeform data*/ + QList> bedData; + /** Regex to capture lines containing valid data */ + static const QRegularExpression lineRegEx; + /** Regex to capture Data from in lines*/ + static const QRegularExpression valueRegEx; +}; + +const QRegularExpression BedDeform::BedDeformPrivate::lineRegEx = QRegularExpression(QStringLiteral(R"((?:\d\s(\+|\-)))")); +const QRegularExpression BedDeform::BedDeformPrivate::valueRegEx = QRegularExpression(QStringLiteral(R"((?\-?\d+\.?\d+))")); + +BedDeform::BedDeform(QObject *parent) + : QObject(parent) + , d(new BedDeformPrivate) +{ +} + +void BedDeform::decodeDeform(const QStringList &rawData) +{ + d->bedData.clear(); + QList coreList; + for (const QString &line : rawData) { + QRegularExpressionMatch lineCheck = d->lineRegEx.match(line); + if (lineCheck.hasMatch()) { + QRegularExpressionMatchIterator valueCheck = d->valueRegEx.globalMatch(line); + while (valueCheck.hasNext()) { + coreList.append(valueCheck.next().captured(0).toDouble()); + } + d->bedData.append(coreList); + coreList.clear(); + } + } + emit dataChanged(d->bedData); +} + +QList> BedDeform::bedData() +{ + return d->bedData; +}