[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [atcore] /: allow non reset on connect
From: Chris Rizzitello <null () kde ! org>
Date: 2018-08-29 20:35:15
Message-ID: E1fv7BL-0002T0-3A () code ! kde ! org
[Download RAW message or body]
Git commit f34a32147fbeff171de8165a8e791f938a4c7696 by Chris Rizzitello.
Committed on 21/08/2018 at 20:35.
Pushed by rizzitello into branch 'master'.
allow non reset on connect
Signed-off-by: Chris Rizzitello <rizzitello@kde.org>
M +25 -1 src/core/atcore.cpp
M +8 -1 src/core/atcore.h
M +14 -1 testclient/mainwindow.cpp
M +1 -0 testclient/mainwindow.h
https://commits.kde.org/atcore/f34a32147fbeff171de8165a8e791f938a4c7696
diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp
index 59d0263..5cf2138 100644
--- a/src/core/atcore.cpp
+++ b/src/core/atcore.cpp
@@ -32,6 +32,7 @@
#include <QTimer>
#include <QThread>
#include <QMetaEnum>
+#include <QProcess>
#include "atcore.h"
#include "atcore_version.h"
@@ -215,8 +216,12 @@ void AtCore::loadFirmwarePlugin(const QString &fwName)
}
}
-bool AtCore::initSerial(const QString &port, int baud)
+bool AtCore::initSerial(const QString &port, int baud, bool disableROC)
{
+ if (disableROC) {
+ disableResetOnConnect(port);
+ }
+
d->serial = new SerialLayer(port, baud);
if (serialInitialized() && d->serial->isWritable()) {
setState(AtCore::CONNECTING);
@@ -395,6 +400,7 @@ void AtCore::closeConnection()
QString msg = d->pluginLoader.unload() ? QStringLiteral("closed.") : QStringLiteral("Failed to close.");
qCDebug(ATCORE_CORE) << QStringLiteral("Firmware plugin %1 %2").arg(name, msg);
}
+ //Do not reset the connect on disconnect when closing this will cause a reset on connect for the next connection.
serial()->close();
//Clear our copy of the sdcard filelist
clearSdCardFileList();
@@ -770,3 +776,21 @@ void AtCore::sdCardPrintStatus()
}
pushCommand(GCode::toCommand(GCode::M27));
}
+
+void AtCore::disableResetOnConnect(const QString &port)
+{
+#ifdef Q_OS_UNIX
+//should work on all unix'
+ QProcess process;
+ QStringList args({QStringLiteral("-F/dev/%1").arg(port), QStringLiteral("-hupcl")});
+ process.start(QStringLiteral("stty"), args);
+ process.waitForFinished(500);
+
+ connect(&process, &QProcess::errorOccurred, this, [this, &process] {
+ qCDebug(ATCORE_CORE) << "Stty Error:" << process.errorString();
+ });
+
+#elif Q_OS_WIN
+ //TODO: Disable hangup on windows.
+#endif
+}
diff --git a/src/core/atcore.h b/src/core/atcore.h
index 45f6816..f32e19b 100644
--- a/src/core/atcore.h
+++ b/src/core/atcore.h
@@ -143,10 +143,11 @@ public:
* @brief Initialize a connection to \p port at a speed of \p baud <br />
* @param port: the port to initialize
* @param baud: the baud of the port
+ * @param disableROC: atcore will attempt to disable reset on connect for this device.
* @return True is connection was successful
* @sa serialPorts(),serial(),closeConnection()
*/
- Q_INVOKABLE bool initSerial(const QString &port, int baud);
+ Q_INVOKABLE bool initSerial(const QString &port, int baud, bool disableROC = false);
/**
* @brief Returns a list of valid baud speeds
@@ -499,6 +500,12 @@ private slots:
*/
void locateSerialPort();
+ /**
+ * @brief Attempts to disableResetOnConnect for the selected port.
+ * @param port: the port.
+ */
+ void disableResetOnConnect(const QString &port);
+
/**
* @brief Send request to the printer for the sd card file list.
*/
diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp
index 589d7e8..620c549 100644
--- a/testclient/mainwindow.cpp
+++ b/testclient/mainwindow.cpp
@@ -24,6 +24,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QTextStream>
+#include <QTimer>
#include <QLoggingCategory>
#include "mainwindow.h"
@@ -245,6 +246,14 @@ void MainWindow::makeConnectDock()
hBoxLayout->addWidget(comboPlugin, 75);
mainLayout->addLayout(hBoxLayout);
+ cbReset = new QCheckBox(tr("Attempt to stop Reset on connect"));
+ cbReset->setHidden(true);
+ mainLayout->addWidget(cbReset);
+
+ connect(comboPlugin, &QComboBox::currentTextChanged, this, [this](const QString & currentText) {
+ cbReset->setHidden(currentText == tr("Autodetect"));
+ });
+
buttonConnect = new QPushButton(tr("Connect"));
connect(buttonConnect, &QPushButton::clicked, this, &MainWindow::connectPBClicked);
mainLayout->addWidget(buttonConnect);
@@ -413,13 +422,17 @@ void MainWindow::locateSerialPort(const QStringList &ports)
void MainWindow::connectPBClicked()
{
if (core->state() == AtCore::DISCONNECTED) {
- if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt())) {
+ if (core->initSerial(comboPort->currentText(), comboBAUD->currentText().toInt(), cbReset->isChecked())) {
connect(core, &AtCore::receivedMessage, logWidget, &LogWidget::appendRLog);
connect(core->serial(), &SerialLayer::pushedCommand, logWidget, &LogWidget::appendSLog);
buttonConnect->setText(tr("Disconnect"));
logWidget->appendLog(tr("Serial connected"));
if (!comboPlugin->currentText().contains(tr("Autodetect"))) {
core->loadFirmwarePlugin(comboPlugin->currentText());
+ if (cbReset->isChecked()) {
+ //Wait a few seconds after connect to avoid the normal errors
+ QTimer::singleShot(5000, core, &AtCore::sdCardPrintStatus);
+ }
}
}
} else {
diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h
index f23ef9b..da4d4b5 100644
--- a/testclient/mainwindow.h
+++ b/testclient/mainwindow.h
@@ -164,6 +164,7 @@ private:
QComboBox *comboBAUD = nullptr;
QComboBox *comboPlugin = nullptr;
QPushButton *buttonConnect = nullptr;
+ QCheckBox *cbReset = nullptr;
void makeMoveDock();
QDockWidget *moveDock = nullptr;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic