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
@@ -24,14 +24,15 @@
License along with this library. If not, see .
*/
#pragma once
-
+#include
#include
#include
#include
#include "ifirmware.h"
#include "temperature.h"
#include "atcore_export.h"
+#include "beddeform.h"
class SerialLayer;
class IFirmware;
@@ -196,6 +197,11 @@
*/
float percentagePrinted() const;
+ /**
+ * @brief The Bed Deform data as told by the Firmware.
+ */
+ std::shared_ptr bedDeform();
+
/**
* @brief The temperature of the current hotend as told by the Firmware.
*/
diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp
--- a/src/core/atcore.cpp
+++ b/src/core/atcore.cpp
@@ -23,6 +23,7 @@
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
*/
+
#include
#include
#include
@@ -64,6 +65,8 @@
int extruderCount = 1;
/** temperature: Temperature object */
Temperature temperature;
+ /** bedDeform: BedDeform object */
+ std::shared_ptr bedDeform;
/** commandQueue: the list of commands to send to the printer */
QStringList commandQueue;
/** ready: True if printer is ready for a command */
@@ -92,19 +95,28 @@
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) :
QObject(parent),
d(new AtCorePrivate)
{
+ d->bedDeform.reset(new BedDeform);
//Register MetaTypes
qRegisterMetaType("AtCore::STATES");
setState(AtCore::STATES::DISCONNECTED);
//Connect our Timers
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.get(), &BedDeform::dataChanged, this, [](const QVariantList & bedData) {
+ qDebug() << bedData;
+ });
+
//Attempt to find our plugins
qCDebug(ATCORE_PLUGIN) << "Detecting Plugin path";
QStringList paths = AtCoreDirectories::pluginDir;
@@ -350,6 +362,12 @@
void AtCore::newMessage(const QByteArray &message)
{
d->lastMessage = message;
+ if (d->lastCommand.startsWith(GCode::toCommand(GCode::GCode::G29))) {
+ if (d->lastMessage.contains("ok")) {
+ d->bedDeform.get()->decodeDeform(d->tempMultiString);
+ }
+ d->tempMultiString.append(QString::fromLatin1(d->lastMessage));
+ }
//Check if the message has current coordinates.
if (d->lastCommand.startsWith(GCode::toCommand(GCode::MCommands::M114))
&& d->lastMessage.startsWith(QString::fromLatin1("X:").toLocal8Bit())) {
@@ -905,3 +923,8 @@
qCDebug(ATCORE_CORE) << "SerialError:" << errorString;
emit atcoreMessage(QStringLiteral("SerialError: %1").arg(errorString));
}
+
+std::shared_ptr AtCore::bedDeform()
+{
+ 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,68 @@
+/* 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
+
+#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
+ Q_PROPERTY(QVariantList bedDeformationGrid READ bedDeformationGrid NOTIFY dataChanged)
+public:
+ /**
+ * @brief BedDeform Create a new bedDeform object
+ * @param parent: Objects parent
+ */
+ explicit BedDeform(QObject *parent = nullptr);
+ /**
+ * @brief decodeDeform Decode the deform list from the provided lines
+ * @param rawData: raw returns containing deform data
+ */
+ void decodeDeform(const QStringList &rawData);
+ /**
+ * @brief get bed Deform info
+ * @return: bed Deform grid, Variant Format: QList>
+ * The Inner QList contains,
+ * one row worth of offsets for the deformation grid.
+ * the outer list is a list of rows data.
+ * For a grid with 2x3 proble points the size of the inner list will be 2 and the outer list 3
+ * example: QVariant(QVariantList, (QVariant(double, 0.25), QVariant(double, 0.225))
+ * ,QVariant(QVariantList, (QVariant(double, 0.045), QVariant(double, 0.01))
+ * , QVariant(QVariantList, (QVariant(double, -0.168), QVariant(double, -0.24)))
+ */
+ QVariantList bedDeformationGrid();
+signals:
+ void dataChanged(const QVariantList &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,74 @@
+/* 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*/
+ QVariantList bedData;
+ /** Regex to capture lines containing valid data */
+ static const QRegularExpression lineRegEx;
+ /** Regex to capture Data from in lines*/
+ static const QRegularExpression valueRegEx;
+};
+/**
+ * @brief Line with the pattern of digit(s) a single space then '+' or '-'.
+ * Examples:
+ * 0 -0.155 +5.123 -4.567
+ * 10 +8.901 -2.345 +6.789
+ */
+const QRegularExpression BedDeform::BedDeformPrivate::lineRegEx = QRegularExpression(QStringLiteral(R"((?:\d+\s(\+|\-)))"));
+/**
+ * @brief Numeric value with a decimal (maybe negative)
+ * example Input : 0 +0.005 -1.110, +1.040
+ * captured values from above line: 0.005, -1.110, 1.04
+ */
+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();
+ QVariantList 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(QStringLiteral("value")).toDouble());
+ }
+ d->bedData.push_back(coreList);
+ coreList.clear();
+ }
+ }
+ emit dataChanged(d->bedData);
+}
+
+QVariantList BedDeform::bedDeformationGrid()
+{
+ return d->bedData;
+}
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
--- a/unittests/CMakeLists.txt
+++ b/unittests/CMakeLists.txt
@@ -31,3 +31,5 @@
TEST(AtCoreTests atcoretests.cpp)
TEST(GcodeTests gcodetests.cpp)
TEST(TemperatureTests temperaturetests.cpp)
+TEST(BedDeformTests beddeformtests.cpp)
+
diff --git a/unittests/beddeformtests.h b/unittests/beddeformtests.h
new file mode 100644
--- /dev/null
+++ b/unittests/beddeformtests.h
@@ -0,0 +1,31 @@
+/*
+ This file is part of the KDE project
+
+ Copyright (C) 2019 Chris Rizzitello
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+#include
+
+#include "../src/core/beddeform.h"
+
+class BedDeformTests: public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void testDecode();
+private:
+ BedDeform *bedDeform;
+};
diff --git a/unittests/beddeformtests.cpp b/unittests/beddeformtests.cpp
new file mode 100644
--- /dev/null
+++ b/unittests/beddeformtests.cpp
@@ -0,0 +1,63 @@
+/*
+ This file is part of the KDE project
+
+ Copyright (C) 2019 Chris Rizzitello
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#include
+#include "beddeformtests.h"
+
+void BedDeformTests::initTestCase()
+{
+ bedDeform = new BedDeform(this);
+}
+
+void BedDeformTests::testDecode()
+{
+ QStringList temp = {
+ QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("echo:busy: processing")
+ , QStringLiteral("Bilinear Leveling Grid:")
+ , QStringLiteral("0 1 2")
+ , QStringLiteral("0 +0.255 +0.225 -0.038")
+ , QStringLiteral("1 +0.060 +0.008 -0.255")
+ , QStringLiteral("2 -0.153 -0.245 -0.528")
+ , QString()
+ , QStringLiteral("X:155.00 Y:185.00 Z:12.23 E:0.00 Count X:12400 Y:14800 Z:4720")
+ , QStringLiteral("ok")
+ };
+ bedDeform->decodeDeform(temp);
+ QVERIFY(bedDeform->bedDeformationGrid().at(0).toList().at(0).toDouble() == 0.255);
+ QVERIFY(bedDeform->bedDeformationGrid().at(0).toList().at(1).toDouble() == 0.225);
+ QVERIFY(bedDeform->bedDeformationGrid().at(0).toList().at(2).toDouble() == -0.038);
+ QVERIFY(bedDeform->bedDeformationGrid().at(1).toList().at(0).toDouble() == 0.060);
+ QVERIFY(bedDeform->bedDeformationGrid().at(1).toList().at(1).toDouble() == 0.008);
+ QVERIFY(bedDeform->bedDeformationGrid().at(1).toList().at(2).toDouble() == -0.255);
+ QVERIFY(bedDeform->bedDeformationGrid().at(2).toList().at(0).toDouble() == -0.153);
+ QVERIFY(bedDeform->bedDeformationGrid().at(2).toList().at(1).toDouble() == -0.245);
+ QVERIFY(bedDeform->bedDeformationGrid().at(2).toList().at(2).toDouble() == -0.528);
+}
+
+QTEST_MAIN(BedDeformTests)