diff --git a/src/atcore.cpp b/src/atcore.cpp index 416370d..f78cc7d 100644 --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -1,644 +1,759 @@ /* AtCore Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira Lays Rodrigues 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 #include #include #include #include #include #include #include "atcore.h" #include "atcore_version.h" #include "seriallayer.h" #include "gcodecommands.h" #include "printthread.h" #include "atcore_default_folders.h" Q_LOGGING_CATEGORY(ATCORE_PLUGIN, "org.kde.atelier.core.plugin") Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") /** * @brief The AtCorePrivate struct */ struct AtCorePrivate { IFirmware *firmwarePlugin = nullptr;//!< @param firmwarePlugin: pointer to firmware plugin SerialLayer *serial = nullptr; //!< @param serial: pointer to the serial layer QPluginLoader pluginLoader; //!< @param pluginLoader: QPluginLoader QDir pluginsDir; //!< @param pluginsDir: Directory where plugins were found QMap plugins; //!< @param plugins: Map of plugins name / path QByteArray lastMessage; //!< @param lastMessage: lastMessage from the printer int extruderCount = 1; //!< @param extruderCount: extruder count Temperature temperature; //!< @param temperature: Temperature object QStringList commandQueue; //!< @param commandQueue: the list of commands to send to the printer bool ready = false; //!< @param ready: True if printer is ready for a command QTimer *tempTimer = nullptr; //!< @param tempTimer: timer connected to the checkTemperature function float percentage; //!< @param percentage: print job percent QByteArray posString; //!< @param posString: stored string from last M114 return AtCore::STATES printerState; //!< @param printerState: State of the Printer QStringList serialPorts; //!< @param seralPorts: Detected serial Ports QTimer *serialTimer = nullptr; //!< @param serialTimer: Timer connected to locateSerialPorts + bool sdCardMounted = false; //!< @param sdCardMounted: True if Sd Card is mounted. + bool sdCardReadingFileList = false; //!< @param sdCardReadingFileList: True while getting file names from sd card + bool sdCardPrinting = false; //!< @param sdCardPrinting: True if currently printing from sd card. + QString sdCardFileName; //!< @param sdCardFileName: name of file being used from sd card. + QStringList sdCardFileList; //!< @param sdCardFileList: List of files on sd card. }; AtCore::AtCore(QObject *parent) : QObject(parent), d(new AtCorePrivate) { qRegisterMetaType("AtCore::STATES"); setState(AtCore::DISCONNECTED); d->tempTimer = new QTimer(this); d->tempTimer->setInterval(5000); d->tempTimer->setSingleShot(false); QStringList pathList = AtCoreDirectories::pluginDir; pathList.append(QLibraryInfo::location(QLibraryInfo::PluginsPath) + QStringLiteral("/AtCore")); for (const auto &path : pathList) { qCDebug(ATCORE_PLUGIN) << "Lookin for plugins in " << path; if (QDir(path).exists()) { d->pluginsDir = QDir(path); qCDebug(ATCORE_PLUGIN) << "Valid path for plugins found !"; break; } } if (!d->pluginsDir.exists()) { qCritical() << "No valid path for plugin !"; } #if defined(Q_OS_WIN) || defined(Q_OS_MAC) d->pluginsDir = qApp->applicationDirPath() + QStringLiteral("/plugins"); #endif qCDebug(ATCORE_PLUGIN) << d->pluginsDir; findFirmwarePlugins(); setState(AtCore::DISCONNECTED); } QString AtCore::version() const { QString versionString = QString::fromLatin1(ATCORE_VERSION_STRING); #if defined GIT_REVISION if (!QStringLiteral(GIT_REVISION).isEmpty()) { versionString.append(QString::fromLatin1("-%1").arg(QStringLiteral(GIT_REVISION))); } #endif return versionString; } SerialLayer *AtCore::serial() const { return d->serial; } IFirmware *AtCore::firmwarePlugin() const { return d->firmwarePlugin; } void AtCore::close() { exit(0); } Temperature &AtCore::temperature() const { return d->temperature; } void AtCore::findFirmware(const QByteArray &message) { if (state() == AtCore::DISCONNECTED) { qWarning() << "Cant find firwmware, serial not connected !"; return; } if (state() == AtCore::CONNECTING) { if (message.contains("start")) { qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; QTimer::singleShot(500, this, &AtCore::requestFirmware); return; } else if (message.contains("Grbl")) { loadFirmwarePlugin(QString::fromLatin1("grbl")); return; } else if (message.contains("Smoothie")) { loadFirmwarePlugin(QString::fromLatin1("smoothie")); return; } } qCDebug(ATCORE_CORE) << "Find Firmware Called" << message; if (!message.contains("FIRMWARE_NAME:")) { qCDebug(ATCORE_CORE) << "No firmware yet."; return; } qCDebug(ATCORE_CORE) << "Found firmware string, Looking for Firmware Name."; QString fwName = QString::fromLocal8Bit(message); fwName = fwName.split(QChar::fromLatin1(':')).at(1); if (fwName.indexOf(QChar::fromLatin1(' ')) == 0) { //remove leading space fwName.remove(0, 1); } if (fwName.contains(QChar::fromLatin1(' '))) { //check there is a space or dont' resize fwName.resize(fwName.indexOf(QChar::fromLatin1(' '))); } fwName = fwName.toLower().simplified(); if (fwName.contains(QChar::fromLatin1('_'))) { fwName.resize(fwName.indexOf(QChar::fromLatin1('_'))); } qCDebug(ATCORE_CORE) << "Firmware Name:" << fwName; if (message.contains("EXTRUDER_COUNT:")) { //this code is broken if more then 9 extruders are detected. since only one char is returned d->extruderCount = message.at(message.indexOf("EXTRUDER_COUNT:") + 15) - '0'; } qCDebug(ATCORE_CORE) << "Extruder Count:" << QString::number(extruderCount()); loadFirmwarePlugin(fwName); } void AtCore::loadFirmwarePlugin(const QString &fwName) { if (d->plugins.contains(fwName)) { d->pluginLoader.setFileName(d->plugins[fwName]); if (!d->pluginLoader.load()) { qCDebug(ATCORE_PLUGIN) << d->pluginLoader.errorString(); } else { qCDebug(ATCORE_PLUGIN) << "Loading plugin."; } d->firmwarePlugin = qobject_cast(d->pluginLoader.instance()); if (!firmwarePluginLoaded()) { qCDebug(ATCORE_PLUGIN) << "No plugin loaded."; qCDebug(ATCORE_PLUGIN) << "Looking plugin in folder:" << d->pluginsDir; setState(AtCore::CONNECTING); } else { qCDebug(ATCORE_PLUGIN) << "Connected to" << firmwarePlugin()->name(); firmwarePlugin()->init(this); disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::newMessage); connect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); d->ready = true; // ready on new firmware load if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { connect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); d->tempTimer->start(); } setState(IDLE); } } else { qCDebug(ATCORE_CORE) << "No Firmware Loaded"; } } bool AtCore::initSerial(const QString &port, int baud) { d->serial = new SerialLayer(port, baud); if (serialInitialized() && d->serial->isWritable()) { setState(AtCore::CONNECTING); connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); return true; } else { qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; return false; } } bool AtCore::serialInitialized() const { if (!d->serial) { return false; } return d->serial->isOpen(); } QString AtCore::connectedPort() const { return serial()->portName(); } QStringList AtCore::serialPorts() const { QStringList ports; QList serialPortInfoList = QSerialPortInfo::availablePorts(); if (!serialPortInfoList.isEmpty()) { foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) { #ifdef Q_OS_MAC //Mac OS has callout serial ports starting with cu. They can only receive data and it's necessary to filter them out if (!serialPortInfo.portName().startsWith(QStringLiteral("cu."), Qt::CaseInsensitive)) { ports.append(serialPortInfo.portName()); } #else ports.append(serialPortInfo.portName()); #endif } } return ports; } void AtCore::locateSerialPort() { QStringList ports = serialPorts(); if (d->serialPorts != ports) { d->serialPorts = ports; emit portsChanged(d->serialPorts); } } quint16 AtCore::serialTimerInterval() const { if (d->serialTimer != nullptr) { return d->serialTimer->interval(); } return 0; } void AtCore::setSerialTimerInterval(const quint16 &newTime) { if (newTime == 0) { if (d->serialTimer) { disconnect(d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); delete d->serialTimer; } return; } if (!d->serialTimer) { d->serialTimer = new QTimer(); connect(d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); } d->serialTimer->start(newTime); } void AtCore::newMessage(const QByteArray &message) { d->lastMessage = message; if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { d->posString = message; d->posString.resize(d->posString.indexOf('E')); d->posString.replace(':', ""); } //Check if have temperature info and decode it if (d->lastMessage.contains("T:") || d->lastMessage.contains("B:")) { temperature().decodeTemp(message); } emit(receivedMessage(d->lastMessage)); } void AtCore::setRelativePosition() { pushCommand(GCode::toCommand(GCode::G91)); } void AtCore::setAbsolutePosition() { pushCommand(GCode::toCommand(GCode::G90)); } float AtCore::percentagePrinted() const { return d->percentage; } -void AtCore::print(const QString &fileName) +void AtCore::print(const QString &fileName, bool sdPrint) { if (state() == AtCore::CONNECTING) { qCDebug(ATCORE_CORE) << "Load a firmware plugin to print."; return; } - //START A THREAD AND CONNECT TO IT setState(AtCore::STARTPRINT); + if (sdPrint) { + pushCommand(GCode::toCommand(GCode::M23, fileName)); + d->sdCardFileName = fileName; + pushCommand(GCode::toCommand(GCode::M24)); + setState(AtCore::BUSY); + d->sdCardPrinting = true; + connect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + return; + } + //START A THREAD AND CONNECT TO IT QThread *thread = new QThread(); PrintThread *printThread = new PrintThread(this, fileName); printThread->moveToThread(thread); connect(printThread, &PrintThread::printProgressChanged, this, &AtCore::printProgressChanged, Qt::QueuedConnection); connect(thread, &QThread::started, printThread, &PrintThread::start); connect(printThread, &PrintThread::finished, thread, &QThread::quit); connect(thread, &QThread::finished, printThread, &PrintThread::deleteLater); if (!thread->isRunning()) { thread->start(); } } void AtCore::pushCommand(const QString &comm) { d->commandQueue.append(comm); if (d->ready) { processQueue(); } } void AtCore::closeConnection() { if (serialInitialized()) { - if (state() == AtCore::BUSY) { - //we have to clean print if printing. + if (AtCore::state() == AtCore::BUSY && !d->sdCardPrinting) { + //we have to clean print if printing from the host. + //disconnecting from a printer printing via sd card should not affect its print. setState(AtCore::STOP); } if (firmwarePluginLoaded()) { disconnect(firmwarePlugin(), &IFirmware::readyForCommand, this, &AtCore::processQueue); disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::newMessage); if (firmwarePlugin()->name() != QStringLiteral("Grbl")) { disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); d->tempTimer->stop(); } } QString name = firmwarePlugin()->name(); QString msg = d->pluginLoader.unload() ? QStringLiteral("success") : QStringLiteral("FAIL"); qCDebug(ATCORE_PLUGIN) << QStringLiteral("Firmware plugin %1 unload: %2").arg(name, msg); serial()->close(); + clearSdCardFileList(); setState(AtCore::DISCONNECTED); } } AtCore::STATES AtCore::state(void) { return d->printerState; } void AtCore::setState(AtCore::STATES state) { if (state != d->printerState) { qCDebug(ATCORE_CORE) << "Atcore state changed from [" \ << d->printerState << "] to [" << state << "]"; d->printerState = state; + if (state == AtCore::FINISHEDPRINT && d->sdCardPrinting) { + d->sdCardPrinting = false; + disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); + } emit(stateChanged(d->printerState)); } } void AtCore::stop() { setState(AtCore::STOP); d->commandQueue.clear(); + if (d->sdCardPrinting) { + stopSdPrint(); + } setExtruderTemp(0, 0); setBedTemp(0); home(AtCore::X); } void AtCore::emergencyStop() { - if (state() == AtCore::BUSY) { - setState(AtCore::STOP); - } d->commandQueue.clear(); + if (AtCore::state() == AtCore::BUSY) { + if (!d->sdCardPrinting) { + //Stop our running print thread + setState(AtCore::STOP); + } + } serial()->pushCommand(GCode::toCommand(GCode::M112).toLocal8Bit()); } +void AtCore::stopSdPrint() +{ + pushCommand(GCode::toCommand(GCode::M25)); + d->sdCardFileName = QString(); + pushCommand(GCode::toCommand(GCode::M23, d->sdCardFileName)); + AtCore::setState(AtCore::FINISHEDPRINT); + AtCore::setState(AtCore::IDLE); +} + void AtCore::requestFirmware() { if (serialInitialized()) { qCDebug(ATCORE_CORE) << "Sending " << GCode::description(GCode::M115); serial()->pushCommand(GCode::toCommand(GCode::M115).toLocal8Bit()); } else { qCDebug(ATCORE_CORE) << "There is no open device to send commands"; } } bool AtCore::firmwarePluginLoaded() const { if (firmwarePlugin()) { return true; } else { return false; } } void AtCore::findFirmwarePlugins() { d->plugins.clear(); qCDebug(ATCORE_PLUGIN) << "plugin dir:" << d->pluginsDir; QStringList files = d->pluginsDir.entryList(QDir::Files); foreach (const QString &f, files) { QString file = f; #if defined(Q_OS_WIN) if (file.endsWith(QStringLiteral(".dll"))) #elif defined(Q_OS_MAC) if (file.endsWith(QStringLiteral(".dylib"))) #else if (file.endsWith(QStringLiteral(".so"))) #endif file = file.split(QChar::fromLatin1('.')).at(0); else { qCDebug(ATCORE_PLUGIN) << "File" << file << "not plugin."; continue; } qCDebug(ATCORE_CORE) << "Found plugin file" << f; if (file.startsWith(QStringLiteral("lib"))) { file = file.remove(QStringLiteral("lib")); } file = file.toLower().simplified(); QString pluginString; pluginString.append(d->pluginsDir.path()); pluginString.append(QChar::fromLatin1('/')); pluginString.append(f); d->plugins[file] = pluginString; qCDebug(ATCORE_CORE) << tr("plugins[%1]=%2").arg(file, pluginString); } } QStringList AtCore::availableFirmwarePlugins() const { return d->plugins.keys(); } void AtCore::detectFirmware() { connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); } void AtCore::pause(const QString &pauseActions) { + if (d->sdCardPrinting) { + pushCommand(GCode::toCommand(GCode::M25)); + } pushCommand(GCode::toCommand(GCode::M114)); - setState(AtCore::PAUSE); if (!pauseActions.isEmpty()) { QStringList temp = pauseActions.split(QChar::fromLatin1(',')); for (int i = 0; i < temp.length(); i++) { pushCommand(temp.at(i)); } } + setState(AtCore::PAUSE); } void AtCore::resume() { - pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->posString))); + if (d->sdCardPrinting) { + pushCommand(GCode::toCommand(GCode::M24)); + } else { + pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->posString))); + } setState(AtCore::BUSY); } /*~~~~~Control Slots ~~~~~~~~*/ void AtCore::home() { pushCommand(GCode::toCommand(GCode::G28)); } void AtCore::home(uchar axis) { QString args; if (axis & AtCore::X) { args.append(QStringLiteral("X0 ")); } if (axis & AtCore::Y) { args.append(QStringLiteral("Y0 ")); } if (axis & AtCore::Z) { args.append(QStringLiteral("Z0")); } pushCommand(GCode::toCommand(GCode::G28, args)); } void AtCore::setExtruderTemp(uint temp, uint extruder, bool andWait) { if (andWait) { pushCommand(GCode::toCommand(GCode::M109, QString::number(temp), QString::number(extruder))); } else { pushCommand(GCode::toCommand(GCode::M104, QString::number(extruder), QString::number(temp))); } temperature().setExtruderTargetTemperature(temp); } void AtCore::setBedTemp(uint temp, bool andWait) { if (andWait) { pushCommand(GCode::toCommand(GCode::M190, QString::number(temp))); } else { pushCommand(GCode::toCommand(GCode::M140, QString::number(temp))); } temperature().setBedTargetTemperature(temp); } void AtCore::setFanSpeed(uint speed, uint fanNumber) { pushCommand(GCode::toCommand(GCode::M106, QString::number(fanNumber), QString::number(speed))); } void AtCore::setPrinterSpeed(uint speed) { pushCommand(GCode::toCommand(GCode::M220, QString::number(speed))); } void AtCore::setFlowRate(uint speed) { pushCommand(GCode::toCommand(GCode::M221, QString::number(speed))); } void AtCore::move(AtCore::AXES axis, int arg) { static QLatin1Char a('?'); switch (axis) { case AtCore::X: a = QLatin1Char('X'); break; case AtCore::Y: a = QLatin1Char('Y'); break; case AtCore::Z: a = QLatin1Char('Z'); break; case AtCore::E: a = QLatin1Char('E'); break; default: break; }; move(a, arg); } void AtCore::move(QLatin1Char axis, int arg) { pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1 %2").arg(axis).arg(QString::number(arg)))); } int AtCore::extruderCount() const { return d->extruderCount; } void AtCore::processQueue() { d->ready = true; if (d->commandQueue.isEmpty()) { return; } if (!serialInitialized()) { qCDebug(ATCORE_PLUGIN) << "Can't process queue ! Serial not initialized."; return; } QString text = d->commandQueue.takeAt(0); if (firmwarePluginLoaded()) { serial()->pushCommand(firmwarePlugin()->translate(text)); } else { serial()->pushCommand(text.toLocal8Bit()); } d->ready = false; } void AtCore::checkTemperature() { if (d->commandQueue.contains(GCode::toCommand(GCode::M105))) { return; } pushCommand(GCode::toCommand(GCode::M105)); } void AtCore::showMessage(const QString &message) { if (!message.isEmpty()) { pushCommand(GCode::toCommand((GCode::M117), message)); } } void AtCore::setUnits(AtCore::UNITS units) { switch (units) { case AtCore::METRIC: pushCommand(GCode::toCommand(GCode::G21)); break; case AtCore::IMPERIAL: pushCommand(GCode::toCommand(GCode::G20)); break; } } QStringList AtCore::portSpeeds() const { return serial()->validBaudRates(); } void AtCore::setIdleHold(uint delay) { - if (delay != 0) { + if (delay) { pushCommand(GCode::toCommand(GCode::M84, QString::number(delay))); } else { pushCommand(GCode::toCommand(GCode::M84)); } } + +bool AtCore::isSdMounted() const +{ + return d->sdCardMounted; +} + +void AtCore::setSdMounted(bool mounted) +{ + if (mounted != isSdMounted()) { + d->sdCardMounted = mounted; + emit(sdMountChanged(d->sdCardMounted)); + } +} + +void AtCore::getSDFileList() +{ + pushCommand(GCode::toCommand(GCode::M20)); +} + +QStringList AtCore::sdFileList() +{ + if (!d->sdCardReadingFileList) { + getSDFileList(); + } + return d->sdCardFileList; +} + +void AtCore::appendSdCardFileList(const QString &fileName) +{ + d->sdCardFileList.append(fileName); + emit(sdCardFileListChanged(d->sdCardFileList)); +} + +void AtCore::clearSdCardFileList() +{ + d->sdCardFileList.clear(); + emit(sdCardFileListChanged(d->sdCardFileList)); +} + +void AtCore::sdDelete(const QString &fileName) +{ + if (d->sdCardFileList.contains(fileName)) { + pushCommand(GCode::toCommand(GCode::M30, fileName)); + getSDFileList(); + } else { + qCDebug(ATCORE_CORE) << "Delete failed file not found:" << fileName; + } +} + +void AtCore::mountSd(uint slot) +{ + pushCommand(GCode::toCommand(GCode::M21, QString::number(slot))); +} + +void AtCore::umountSd(uint slot) +{ + pushCommand(GCode::toCommand(GCode::M22, QString::number(slot))); +} + +bool AtCore::isReadingSdCardList() const +{ + return d->sdCardReadingFileList; +} + +void AtCore::setReadingSdCardList(bool readingList) +{ + d->sdCardReadingFileList = readingList; +} + +void AtCore::sdCardPrintStatus() +{ + pushCommand(GCode::toCommand(GCode::M27)); +} diff --git a/src/atcore.h b/src/atcore.h index a0ca0c4..d190d81 100644 --- a/src/atcore.h +++ b/src/atcore.h @@ -1,443 +1,540 @@ /* AtCore Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira Lays Rodrigues 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 #include "ifirmware.h" #include "temperature.h" #include "atcore_export.h" class SerialLayer; class IFirmware; class QTime; struct AtCorePrivate; /** * @brief The AtCore class * aims to provides a high level interface for serial based gcode devices
* * General Workflow * - Connect to a serial port with initSerial() * - Auto detect the firmware with detectFirmware() * - Send commands to the device (pushCommand(),print(),...) * - AtCore::close() when you are all done. */ class ATCORE_EXPORT AtCore : public QObject { Q_OBJECT Q_PROPERTY(QString version READ version) Q_PROPERTY(QStringList availableFirmwarePlugins READ availableFirmwarePlugins) Q_PROPERTY(quint16 serialTimerInterval READ serialTimerInterval WRITE setSerialTimerInterval) Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY portsChanged) Q_PROPERTY(QStringList portSpeeds READ portSpeeds) Q_PROPERTY(QString connectedPort READ connectedPort) Q_PROPERTY(AtCore::STATES state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(bool sdMount READ isSdMounted WRITE setSdMounted NOTIFY sdMountChanged) + Q_PROPERTY(QStringList sdFileList READ sdFileList NOTIFY sdCardFileListChanged) + + //Add friends as Sd Card support is extended to more plugins. + friend class RepetierPlugin; + friend class MarlinPlugin; + //friend class SmoothiePlugin; + //friend class TeacupPlugin; + //friend class AprinterPlugin; + //friend class SprinterPlugin; + public: /** * @brief STATES enum Possible states the printer can be in */ enum STATES { DISCONNECTED, //!< Not Connected to a printer, initial state CONNECTING, //! * @param port: the port to initialize * @param baud: the baud of the port * @return True is connection was successful * @sa serialPorts(),serial(),closeConnection() */ Q_INVOKABLE bool initSerial(const QString &port, int baud); /** * @brief Returns a list of valid baud speeds */ QStringList portSpeeds() const; /** * @brief Main access to the serialLayer * @return Current serialLayer * @sa initSerial(),serialPorts(),closeConnection() */ SerialLayer *serial() const; /** * @brief Close the current serial connection * @sa initSerial(),serial(),serialPorts(),AtCore::close() */ Q_INVOKABLE void closeConnection(); /** * @brief Main access to the loaded firmware plugin * @return IFirmware * to currently loaded plugin * @sa availableFirmwarePlugins(),loadFirmwarePlugin(),detectFirmware() */ Q_INVOKABLE IFirmware *firmwarePlugin() const; /** * @brief List of available firmware plugins * @sa loadFirmwarePlugin(),firmwarePlugin(),detectFirmware() */ QStringList availableFirmwarePlugins() const; /** * @brief Load A firmware plugin * @param fwName : name of the firmware * @sa firmwarePlugin(),availableFirmwarePlugins(),detectFirmware() */ Q_INVOKABLE void loadFirmwarePlugin(const QString &fwName); /** * @brief Attempt to autodetect the firmware of connect serial device * @sa loadFirmwarePlugin(),availableFirmwarePlugins(),firmwarePlugin() */ Q_INVOKABLE void detectFirmware(); /** * @brief Get Printer state * @return State of the printer * @sa setState(),stateChanged(),AtCore::STATES */ AtCore::STATES state(void); /** * @brief extruderCount * @return The number of detected Extruders Default is 1 */ int extruderCount() const; /** * @brief Return printed percentage * @sa printProgressChanged() */ float percentagePrinted() const; /** * @brief The temperature of the current hotend as told by the Firmware. */ Temperature &temperature() const; /** * @brief Return the amount of miliseconds the serialTimer is set to. 0 = Disabled */ quint16 serialTimerInterval() const; + /** + * @brief Attempt to Mount an sd card + * @param slot: Sd card Slot on machine (0 is default) + */ + void mountSd(uint slot = 0); + + /** + * @brief Attempt to Unmount an sd card + * @param slot: Sd card Slot on machine (0 is default) + */ + void umountSd(uint slot = 0); + + /** + * @brief sdFileList + * @return List of files on the sd card. + */ + QStringList sdFileList(); + + /** + * @brief Check if an sd card is mounted on the printer + * @return True if card mounted + */ + bool isSdMounted() const; + signals: /** * @brief Print job's precentage changed. * @param newProgress : Message * @sa percentagePrinted() */ void printProgressChanged(const float &newProgress); /** * @brief New message was received from the printer * @param message: Message that was received */ void receivedMessage(const QByteArray &message); /** * @brief The Printer's State Changed * @param newState : the new state of the printer * @sa setState(),state(),AtCore::STATES */ void stateChanged(AtCore::STATES newState); /** * @brief Available serialports Changed */ - void portsChanged(QStringList); + void portsChanged(const QStringList &portList); + + /** + * @brief Sd Card Mount Changed + */ + void sdMountChanged(bool newState); + + /** + * @brief The files on the sd card have changed. + */ + void sdCardFileListChanged(const QStringList &fileList); public slots: /** * @brief Set the printers state * @param state : printer state. * @sa state(),stateChanged(),AtCore::STATES */ void setState(AtCore::STATES state); /** * @brief Push a command into the command queue * * @param comm : Command */ void pushCommand(const QString &comm); /** * @brief Public Interface for printing a file * @param fileName: the gcode file to print. + * @param sdPrint: set true to print fileName from Sd card */ - void print(const QString &fileName); + void print(const QString &fileName, bool sdPrint); /** * @brief Stop the Printer by empting the queue and aborting the print job (if running) * @sa emergencyStop(),pause(),resume() */ void stop(); /** * @brief stop the printer via the emergency stop Command (M112) * @sa stop(),pause(),resume() */ void emergencyStop(); /** * @brief pause an in process print job * * Sends M114 on pause to store the location where the head stoped. * This is known to cause problems on fake printers * @param pauseActions: Gcode to run after pausing commands are ',' separated * @sa resume(),stop(),emergencyStop() */ void pause(const QString &pauseActions); /** * @brief resume a paused print job. * After returning to location pause was triggered. * @sa pause(),stop(),emergencyStop() */ void resume(); /** * @brief Send home \p axis command * @param axis: the axis(es) to home (use X Y Z or any combo of) * @sa home(), move() */ void home(uchar axis); /** * @brief Send home all command * @sa home(uchar axis), move() */ void home(); /** * @brief Set extruder temperature * @param temp : new temperature * @param extruder : extruder number * @param andWait: True for heat and ignore commands until temperature is reached */ void setExtruderTemp(uint temp = 0, uint extruder = 0, bool andWait = false); /** * @brief move an axis of the printer * @param axis the axis to move AXES (X Y Z E ) * @param arg the distance to move the axis or the place to move to depending on printer mode * @sa home(), home(uchar axis), move(QLatin1Char axis, int arg) */ void move(AtCore::AXES axis, int arg); /** * @brief move an axis of the printer * @param axis the axis to move AXES (X Y Z E ) * @param arg the distance to move the axis or the place to move to depending on printer mode * @sa home(), home(uchar axis), move(AtCore::AXES, int arg) */ void move(QLatin1Char axis, int arg); /** * @brief Set the bed temperature * @param temp : new temperature * @param andWait: True for heat and ignore commands until temperature is reached * @sa setExtruderTemp() */ void setBedTemp(uint temp = 0, bool andWait = false); /** * @brief setFanSpeed set the fan speed * @param fanNumber: fan number * @param speed: new speed of the fan 0-100 */ void setFanSpeed(uint speed = 0, uint fanNumber = 0); /** * @brief Set printer to absolute position mode * @sa setRelativePosition() */ void setAbsolutePosition(); /** * @brief Set printer to relative position mode * @sa setAbsolutePosition() */ void setRelativePosition(); /** * @brief Disables idle hold of motors after a delay * @param delay: Seconds until idle hold is released. 0= No delay */ void setIdleHold(uint delay = 0); /** * @brief set the Printers speed * @param speed: speed in % (default is 100); */ void setPrinterSpeed(uint speed = 100); /** * @brief set extruder Flow rate * @param rate: flow rate in % (default is 100) */ void setFlowRate(uint rate = 100); /** * @brief close any open items. * You should call this on close events to force any stuck jobs to close * @sa closeConnection() */ void close(); /** * @brief showMessage push a message to the printers LCD * @param message: message to show on the LCD */ void showMessage(const QString &message); /** * @brief setUnits sets the measurement units do be used * @param units : the measurement units to use(METRIC / IMPERIAL) * @sa AtCore::UNITS */ void setUnits(AtCore::UNITS units); /** * @brief Set the time between checks for new serialPorts (0 is default) * @param newTime: Milliseconds between checks. 0 will Disable Checks. */ void setSerialTimerInterval(const quint16 &newTime); + /** + * @brief delete file from sd card + */ + void sdDelete(const QString &fileName); + + /** + * @brief Queue the Printer for status of sd card print + */ + void sdCardPrintStatus(); + private slots: /** * @brief processQueue send commands from the queue. */ void processQueue(); /** * @brief Send M105 to the printer if one is not in the Queue */ void checkTemperature(); /** * @brief Connect to SerialLayer::receivedCommand * @param message: new message. */ void newMessage(const QByteArray &message); /** * @brief Search for firmware string in message. * A Helper function for detectFirmware() * @param message */ void findFirmware(const QByteArray &message); /** * @brief Search for new serial ports */ void locateSerialPort(); + /** + * @brief Send request to the printer for the sd card file list. + */ + void getSDFileList(); + private: /** * @brief True if a firmware plugin is loaded */ bool firmwarePluginLoaded() const; /** * @brief True if a serial port is initialized */ bool serialInitialized() const; /** * @brief send firmware request to the printer */ void requestFirmware(); /** * @brief Search for atcore firmware plugins */ void findFirmwarePlugins(); + /** + * @brief returns AtCorePrivate::sdCardReadingFileList + * @return True if printer is returning sd card file list + */ + bool isReadingSdCardList() const; + + /** + * @brief stops print just for sd prints used internally + * @sa stop(),emergencyStop() + */ + void stopSdPrint(); + /** * @brief Hold private data of AtCore. */ AtCorePrivate *d; + +protected: + /** + * @brief Append a file to AtCorePrivate::sdCardFileList. + * @param fileName: new FileName + */ + void appendSdCardFileList(const QString &fileName); + + /** + * @brief Clear AtCorePrivate::sdCardFileList. + */ + void clearSdCardFileList(); + + /** + * @brief Set if the sd card is mounted by the printer + * @param mounted: True is mounted + */ + void setSdMounted(const bool mounted); + + /** + * @brief set AtCorePrivate::sdCardReadingFileList + * @param readingList set true if reading file list + */ + void setReadingSdCardList(bool readingList); }; diff --git a/src/gcodecommands.cpp b/src/gcodecommands.cpp index 52be0eb..1a9cd78 100644 --- a/src/gcodecommands.cpp +++ b/src/gcodecommands.cpp @@ -1,529 +1,564 @@ /* AtCore Copyright (C) <2016> Authors: Lays Rodrigues Tomaz Canabrava Patrick José Pereira 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 #include "gcodecommands.h" const QString GCode::commandRequiresArgument = QObject::tr("%1%2: requires an argument"); const QString GCode::commandNotSupported = QObject::tr("Not implemented or not supported!"); QString GCode::description(GCommands gcode) { switch (gcode) { case G0://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G0: Rapid linear move"); case G1://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("G1: Linear move"); case G2://Sprinter - Marlin - Repetier - Smoothie return QObject::tr("G2: Controlled Arc Move clockwise"); case G3://Sprinter - Marlin - Repetier - Smoothie return QObject::tr("G3: Controlled Arc Move counterclockwise"); case G4://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G4: Dwell"); case G10://Marlin - Repetier > 0.92 - Smoothie return QObject::tr("G10: Retract"); case G11://Marlin - Repetier > 0.92 - Smoothie return QObject::tr("G11: Unretract"); case G20://Teacup - Sprinter - Repetier - Smoothie - RepRap Firmware return QObject::tr("G20: Set units to inches"); case G21://Teacup - Sprinter - Repetier - Smoothie - RepRap Firmware return QObject::tr("G21: Set units to millimeters"); case G28://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G28: Move to Origin Home"); case G29://Marlin - Repetier 0.91.7 return QObject::tr("G29: Detailed Z-Probe"); case G30:// Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("G30: Single Z-Probe"); case G31://Repetier 0.91.7 - Smoothie - RepRap Firmware - Marlin return QObject::tr("G31: Set or report current probe status / Dock Z Probe sled for Marlin"); case G32://Repetier 0.92.8 - Smoothie - RepRap Firmware - Marlin return QObject::tr("G32: Probe Z and calculate Z plane(Bed Leveling)/ UnDoc Z Probe sled for Marlin"); case G33://Repetier 0.92.8 return QObject::tr("G33: Measure/List/Adjust Distortion Matrix"); case G90://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G90: Set to absolute positioning"); case G91://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G91: Set to relative positioning"); case G92://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("G92: Set position"); case G100://Repetier 0.92 return QObject::tr("G100: Calibrate floor or rod radius"); case G130://MakerBot return QObject::tr("G130: Set digital potentiometer value"); case G131://Repetier 0.91 return QObject::tr("G131: Recase Move offset"); case G132://Repetier 0.91 return QObject::tr("G132: Calibrate endstops offsets"); case G133://Repetier 0.91 return QObject::tr("G133: Measure steps to top"); case G161://Teacup - MakerBot return QObject::tr("G161: Home axis to minimum"); case G162://Teacup - MakerBot return QObject::tr("G162: Home axis to maximum"); default: return commandNotSupported; } } QString GCode::toCommand(GCommands gcode, const QString &value1) { QString code = QStringLiteral("G%1").arg(QString::number(gcode)); switch (gcode) { case G90: case G91: return code; + case G32: return code.append(QStringLiteral(" S1")); case G0: case G1: case G28: code = value1.isEmpty() ? code : code.append(QStringLiteral(" %1").arg(value1.toUpper())); return code; + default: return commandNotSupported; } } QString GCode::description(MCommands gcode) { switch (gcode) { case M0://Marlin - Teacup - RepRap Firmware return QObject::tr("M0: Stop or unconditional stop"); case M1://Marlin - RepRap Firmware return QObject::tr("M1: Sleep or unconditional stop"); case M2://Teacup - Maker Bot return QObject::tr("M2: Program End"); case M6://Teacup return QObject::tr("M6: Tool Change"); case M17://Teacup - Marlin - Smoothie return QObject::tr("M17: Enable/power all steppers motors"); case M18://Teacup - Marlin(M84) - Smoothie -RepRap Firmware return QObject::tr("M18: Disable all steppers motors"); case M20://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M20: List SDCard"); case M21://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M21: Initialize SDCard"); case M22://Teacup - Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M22: Release SDCard"); - case M23:////Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware + case M23://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M23: Select SD file"); case M24://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M24: Start/resume SD print"); case M25://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M25: Pause SD print"); case M26://Sprinter - Marlin - Repetier - Smoothie(abort) - RepRap Firmware return QObject::tr("M26: Set SD position"); case M27://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M27: Report SD print status"); case M28://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M28: Begin write to SD card"); case M29:// Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M29: Stop writing to SD card"); case M30://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M30: Delete a file on the SD card"); case M31://Marlin return QObject::tr("M31: Output time since last M109 or SD card start to serial"); case M32://Marlin - Smoothie - RepRap Firmware return QObject::tr("M32: Select file and start SD print"); case M33://Marlin return QObject::tr("M33: Get the long name for an SD card file or folder"); case M34://Marlin return QObject::tr("M34: Set SD file sorting options"); case M36://RepRap Firmware return QObject::tr("M36: Return file information"); case M42://Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M42: Switch I/O pin"); case M48://Marlin return QObject::tr("M48: Measure Z-Probe repeatability"); case M70://MakerBot return QObject::tr("M70: Display message"); case M72://MakerBot return QObject::tr("M72: Play a tone or song"); case M73://MakerBot return QObject::tr("M73: Set build percentage"); case M80://Teacup(automatic) - Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M80: ATX Power On"); case M81://Teacup(automatic) - Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M81: ATX Power Off"); case M82://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M82: Set extruder to absolute mode"); case M83://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M83: Set extruder to relative mode"); case M84://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M84: Stop idle hold"); case M85://Sprinter - Marlin - Repetier return QObject::tr("M85: Set Inactivity shutdown timer"); case M92:// Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M92: Set axis steps per unit"); case M93:// Sprinter return QObject::tr("M93: Send axis steps per unit"); case M98: //RepRap Firmware return QObject::tr("M98: Call Macro/Subprogram"); case M99://RepRap Firmware return QObject::tr("M99: Return from Macro/Subprogram"); case M101://Teacup return QObject::tr("M101: Turn extruder 1 on Forward, Undo Retraction"); case M103://Teacup return QObject::tr("M103: Turn all extruders off - Extruder Retraction"); case M104://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("M104: Set Extruder Temperature"); case M105://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("M105: Get Extruder Temperature"); case M106://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M106: Fan On"); case M107:// Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M107: Fan Off"); case M108://Marlin return QObject::tr("M108: Cancel Heating"); case M109:// Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("M109: Set Extruder Temperature and Wait"); case M110:// Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M110: Set Current Line Number"); case M111://Teacup - Marlin - Repetier - RepRap Firmware return QObject::tr("M111: Set Debug Level"); case M112://Teacup - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M112: Emergency Stop"); case M114://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("M114: Get Current Position"); case M115://Teacup - Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M115: Get Firmware Version and Capabilities"); case M116://Teacup - Repetier - RepRap Firmware - MakerBot return QObject::tr("M116: Wait"); case M117:// Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M117: Display Message"); case M119://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M119: Get Endstop Status"); case M120://Marlin - Smoothie - RepRap Firmware return QObject::tr("M120: Push for Smoothie and RepRap Firmware / Enable Endstop detection for Marlin"); case M121://Marlin - Smoothie - RepRap Firmware return QObject::tr("M121: Pop for Smoothie and RepRap Firmware / Disable Endstop detection for Marlin"); case M122://RepRap Firmware return QObject::tr("M122: Diagnose"); case M126://Marlin - MakerBot return QObject::tr("M126: Open valve"); case M127://Marlin - MakerBot return QObject::tr("M127: Close valve"); case M130://Teacup return QObject::tr("M130: Set PID P value"); case M131://Teacup return QObject::tr("M131: Set PID I value"); case M132://Teacup - MakerBot return QObject::tr("M132: Set PID D value"); case M133://Teacup - MakerBot return QObject::tr("M133: Set PID I limit value"); case M134://Teacup - MakerBot return QObject::tr("M134: Write PID values to EEPROM"); case M135://RepRap Firmware - MakerBot return QObject::tr("M135: Set PID sample interval"); case M140://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware - MakerBot return QObject::tr("M140: Set Bed Temperature - Fast"); case M141://RepRap Firmware return QObject::tr("M141: Set Chamber Temperature - Fast"); case M143://RepRap Firmware return QObject::tr("M143: Maximum hot-end temperature"); case M144://RepRap Firmware return QObject::tr("M144: Stand by your bed"); case M150://Marlin return QObject::tr("M150: Set display color"); case M163://Repetier > 0.92 return QObject::tr("M163: Set weight of mixed material"); case M164://Repetier > 0.92 return QObject::tr("M164: Store weights"); case M190://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M190: Wait for bed temperature to reach target temp"); case M200://Marlin - Repetier - Smoothie return QObject::tr("M200: Set filament diameter"); case M201://Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M201: Set max printing acceleration"); case M202://Marlin - Repetier return QObject::tr("M202: Set max travel acceleration"); case M203://Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M203: Set maximum feedrate"); case M204://Sprinter - Marlin - Repetier - Smoothie return QObject::tr("M204: Set default acceleration"); case M205://Sprinter - Marlin - Repetier - Smoothie return QObject::tr("M205: Advanced settings"); case M206://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M206: Offset axes for Sprinter, Marlin, Smoothie, RepRap Firmware / Set eeprom value for Repetier"); case M207://Marlin - Smoothie return QObject::tr("M207: Set retract length"); case M208://Marlin - Smoothie return QObject::tr("M208: Set unretract length"); case M209://Marlin - Repetier return QObject::tr("M209: Enable automatic retract"); case M212://Marlin return QObject::tr("M212: Set Bed Level Sensor Offset"); case M218://Marlin return QObject::tr("M218: Set Hotend Offset"); case M220://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M220: Set speed factor override percentage"); case M221://Teacup - Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M221: Set extrude factor override percentage"); case M226://Marlin - Repetier return QObject::tr("M226: Wait for pin state"); case M231://Repetier return QObject::tr("M231: Set OPS parameter"); case M232://Repetier return QObject::tr("M232: Read and reset max. advance values"); - case M240: //Marlin + case M240://Marlin return QObject::tr("M240: Trigger camera"); case M250://Marlin return QObject::tr("M250: Set LCD contrast"); case M251://Repetier return QObject::tr("M251: Measure Z steps from homing stop (Delta printers)"); case M280://Marlin return QObject::tr("M280: Set servo position"); case M300://Marlin - Repetier - RepRap Firmware - MakerBot return QObject::tr("M300: Play beep sound"); case M301://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M301: Set PID parameters"); case M302://Marlin - Repetier > 0.92 - RepRap Firmware return QObject::tr("M302: Allow cold extrudes "); case M303://Sprinter - Marlin - Repetier - Smoothie return QObject::tr("M303: Run PID tuning"); case M304://Marlin - RepRap Firmware return QObject::tr("M304: Set PID parameters - Bed"); case M305:// Smoothie - RepRap Firmware return QObject::tr("M305: Set thermistor and ADC parameters"); case M306:// Smoothie return QObject::tr("M306: set home offset calculated from toolhead position"); case M320://Repeier return QObject::tr("M320: Activate autolevel (Repetier)"); case M321://Repetier return QObject::tr("M321: Deactivate autolevel (Repetier)"); case M322://Repetier return QObject::tr("M322: Reset autolevel matrix (Repetier)"); case M323://Repetier return QObject::tr("M323: Distortion correction on/off (Repetier)"); case M340://Repetier return QObject::tr("M340: Control the servos"); case M350://Marlin - Repetier - RepRap Firmware return QObject::tr("M350: Set microstepping mode"); case M351://Marlin return QObject::tr("M351: Toggle MS1 MS2 pins directly"); case M355://Repetier > 0.92.2 return QObject::tr("M355: Turn case lights on/off"); case M360://Repetier > 9.92.2 return QObject::tr("M360: Report firmware configuration"); case M361://Smoothie return QObject::tr("M361: Move to Theta 90 degree position"); case M362://Smoothie return QObject::tr("M362: Move to Psi 0 degree position"); case M363://Smoothie return QObject::tr("M363: Move to Psi 90 degree position"); case M364://Smoothie return QObject::tr("M364: Move to Psi + Theta 90 degree position"); case M365://Smoothie return QObject::tr("M365: SCARA scaling factor"); case M366://Smoothie return QObject::tr("M366: SCARA convert trim"); case M370://Smoothie return QObject::tr("M370: Morgan manual bed level - clear map"); case M371://Smoothie return QObject::tr("M371: Move to next calibration position"); case M372://Smoothie return QObject::tr("M372: Record calibration value, and move to next position"); case M373://Smoothie return QObject::tr("M373: End bed level calibration mode"); case M374://Smoothie return QObject::tr("M374: Save calibration grid"); case M375://Smoothie return QObject::tr("M375: Display matrix / Load Matrix"); case M380://Marlin return QObject::tr("M380: Activate solenoid"); case M381://Marlin return QObject::tr("M381: Disable all solenoids"); case M400://Sprinter - Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M400: Wait for current moves to finish"); case M401://Marlin return QObject::tr("M401: Lower z-probe"); case M402://Marlin return QObject::tr("M402: Raise z-probe"); case M404://Marlin - RepRap Firmware return QObject::tr("M404: Filament width and nozzle diameter"); case M405://Marlin return QObject::tr("M405: Filament Sensor on"); case M406://Marlin return QObject::tr("M406: Filament Sensor off"); case M407://Marlin - RepRap Firmware return QObject::tr("M407: Display filament diameter"); case M408://RepRap Firmware return QObject::tr("M408: Report JSON-style response"); case M420: return QObject::tr("M420: Enable/Disable Mesh Leveling (Marlin)"); case M450://Repetier return QObject::tr("M450: Report Printer Mode"); case M451://Repetier return QObject::tr("M451: Select FFF Printer Mode"); case M452://Repetier return QObject::tr("M452: Select Laser Printer Mode"); case M453://Repetier return QObject::tr("M453: Select CNC Printer Mode"); case M460://Repetier return QObject::tr("M460: Define temperature range for thermistor controlled fan"); case M500://Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M500: Store parameters in EEPROM"); case M501://Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M501: Read parameters from EEPROM"); case M502://Sprinter - Marlin - Repetier - RepRap Firmware return QObject::tr("M502: Revert to the default 'factory settings'."); case M503://Sprinter - Marlin - RepRap Firmware return QObject::tr("M503: Print settings "); case M540://Marlin return QObject::tr("M540: Enable/Disable 'Stop SD Print on Endstop Hit'"); case M550://RepRap Firmware return QObject::tr("M550: Set Name"); case M551://RepRap Firmware return QObject::tr("M551: Set Password"); case M552://RepRap Firmware return QObject::tr("M552: Set IP address"); case M553://RepRap Firmware return QObject::tr("M553: Set Netmask"); case M554://RepRap Firmware return QObject::tr("M554: Set Gateway"); case M555://RepRap Firmware return QObject::tr("M555: Set compatibility"); case M556://RepRap Firmware return QObject::tr("M556: Axis compensation"); case M557://Smoothie - RepRap Firmware return QObject::tr("M557: Set Z probe point"); case M558://RepRap Firmware return QObject::tr("M558: Set Z probe type"); case M559://RepRap Firmware return QObject::tr("M559: Upload configuration file"); case M560://RepRap Firmware return QObject::tr("M560: Upload web page file"); case M561://Smoothie - RepRap Firmware return QObject::tr("M561: Set Identity Transform"); case M562://RepRap Firmware return QObject::tr("M562: Reset temperature fault"); case M563://RepRap Firmware return QObject::tr("M563: Define or remove a tool"); case M564://RepRap Firmware return QObject::tr("M564: Limit axes"); case M565://Smoothie return QObject::tr("M565: Set Z probe offset"); case M566://RepRap Firmware return QObject::tr("M566: Set allowable instantaneous speed change"); case M567://RepRap Firmware return QObject::tr("M567: Set tool mix ratio"); case M568://RepRap Firmware return QObject::tr("M568: Turn off/on tool mix ratio"); case M569://RepRap Firmware return QObject::tr("M569: Set axis direction and enable values"); case M570://RepRap Firmware return QObject::tr("M570: Set heater timeout"); case M571://RepRap Firmware return QObject::tr("M571: Set output on extrude"); case M573://RepRap Firmware return QObject::tr("M573: Report heater PWM"); case M574://RepRap Firmware return QObject::tr("M574: Set endstop configuration"); case M575://RepRap Firmware return QObject::tr("M575: Set serial comms parameters"); case M577://RepRap Firmware return QObject::tr("M577: Wait until endstop is triggered"); case M578://RepRap Firmware return QObject::tr("M578: Fire inkjet bits"); case M579://RepRap Firmware return QObject::tr("M579: Scale Cartesian axes"); case M580://RepRap Firmware return QObject::tr("M580: Select Roland"); case M600://Marlin return QObject::tr("M600: Filament change pause"); case M605://Marlin return QObject::tr("M605: Set dual x-carriage movement mode"); case M665://Marlin - Smoothie - RepRap Firmware return QObject::tr("M665: Set delta configuration"); case M666://Marlin - Repetier - Smoothie - RepRap Firmware return QObject::tr("M666: Set delta endstop adjustment"); case M667://RepRap Firmware return QObject::tr("M667: Select CoreXY mode"); case M851://Marlin return QObject::tr("M851: Set Z-Probe Offset"); case M906://RepRap Firmware return QObject::tr("M906: Set motor currents"); case M907://Marlin - Repetier - Smoothie return QObject::tr("M907: Set digital trimpot motor"); case M908://Marlin - Repetier > 0.92 return QObject::tr("M908: Control digital trimpot directly"); case M911://RepRap Firmware return QObject::tr("M911: Set power monitor threshold voltages"); case M912://RepRap Firmware return QObject::tr("M912: Set electronics temperature monitor adjustment"); case M913://RepRap Firmware return QObject::tr("M913: Set motor percentage of normal current"); case M928://Marlin return QObject::tr("M928: Start SD logging"); case M997://RepRap Firmware return QObject::tr("M997: Perform in-application firmware update"); case M998://RepRap Firmware return QObject::tr("M998: Request resend of line"); case M999://Marlin - Smoothie - RepRap Firmware return QObject::tr("M999: Restart after being stopped by error"); default: return commandNotSupported; } } QString GCode::toCommand(MCommands gcode, const QString &value1, const QString &value2) { QString code = QStringLiteral("M%1").arg(QString::number(gcode)); switch (gcode) { + case M20: + case M24: + case M25: + case M27: case M105: case M107: case M112: case M114: case M115: case M116: case M119: return code; + + case M21: + case M22: + code = value1.isEmpty() ? code : code.append(QStringLiteral(" P%1").arg(value1)); + return code; + + case M23: + case M28: + case M29: + case M30: case M117: - code = value1.isEmpty() ? GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)) : QStringLiteral("M117 %1").arg(value1); + code = value1.isEmpty() ? GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)) : code.append(QStringLiteral(" %1").arg(value1)); return code; + case M109: case M140: case M190: case M220: case M221: code = value1.isEmpty() ? GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)) : code.append(QStringLiteral(" S%1").arg(value1)); return code; + case M84: code = value1.isEmpty() ? code : code.append(QStringLiteral(" S%1").arg(value1)); return code; + case M104: code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1).arg(value2)); code = value1.isEmpty() ? GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)) : code ; return code; + case M106: code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1).arg(value2)); code = value1.isEmpty() ? QStringLiteral("M106") : code ; return code; + + /// For M26 values that end with %. AtCore will send the percentage verison of the command (optional in firmwares) + /// For all values not ending in % it will start on that byte. This is the standard Sd resume supported by all reprap based firmware. + case M26: { + if (!value1.isEmpty()) { + if (value1.endsWith(QStringLiteral("%"))) { + QString temp = value1; + temp.replace(QStringLiteral("%"), QStringLiteral("")); + return code.append(QStringLiteral(" P%1").arg(temp.toDouble() / 100)); + } + return code.append(QStringLiteral(" S%1").arg(value1)); + } + return GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)); + } + default: return commandNotSupported; } } diff --git a/src/plugins/marlinplugin.cpp b/src/plugins/marlinplugin.cpp index b699bf9..09ce7f8 100644 --- a/src/plugins/marlinplugin.cpp +++ b/src/plugins/marlinplugin.cpp @@ -1,41 +1,85 @@ /* AtCore KDE Libary for 3D Printers Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira 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 #include "marlinplugin.h" #include "atcore.h" Q_LOGGING_CATEGORY(MARLIN_PLUGIN, "org.kde.atelier.core.firmware.marlin") QString MarlinPlugin::name() const { return QStringLiteral("Marlin"); } MarlinPlugin::MarlinPlugin() { qCDebug(MARLIN_PLUGIN) << name() << " plugin loaded!"; } + +void MarlinPlugin::validateCommand(const QString &lastMessage) +{ + if (lastMessage.contains(QStringLiteral("End file list"))) { + core()->setReadingSdCardList(false); + } else if (core()->isReadingSdCardList()) { + // Below is to not add directories + if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { + QString fileName = lastMessage; + fileName.chop(fileName.length() - fileName.lastIndexOf(QChar::fromLatin1(' '))); + core()->appendSdCardFileList(fileName); + } + } else { + if (lastMessage.contains(QStringLiteral("SD card ok"))) { + core()->setSdMounted(true); + } else if (lastMessage.contains(QStringLiteral("SD init fail"))) { + core()->setSdMounted(false); + } else if (lastMessage.contains(QStringLiteral("Begin file list"))) { + core()->setSdMounted(true); + core()->clearSdCardFileList(); + core()->setReadingSdCardList(true); + } else if (lastMessage.contains(QStringLiteral("SD printing byte"))) { + QString temp = lastMessage; + temp.replace(QStringLiteral("SD printing byte"), QString()); + qlonglong total = temp.mid(temp.lastIndexOf(QChar::fromLatin1('/')) + 1, temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))).toLongLong(); + if (total) { + temp.chop(temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))); + qlonglong remaining = total - temp.toLongLong(); + float progress = float(total - remaining) * 100 / float(total); + core()->printProgressChanged(progress); + if (progress >= 100) { + core()->setState(AtCore::FINISHEDPRINT); + core()->setState(AtCore::IDLE); + } + } else { + core()->setState(AtCore::FINISHEDPRINT); + core()->setState(AtCore::IDLE); + } + } + if (lastMessage.contains(QStringLiteral("ok"))) { + emit readyForCommand(); + } + } +} diff --git a/src/plugins/marlinplugin.h b/src/plugins/marlinplugin.h index efcc5b2..053b3bc 100644 --- a/src/plugins/marlinplugin.h +++ b/src/plugins/marlinplugin.h @@ -1,51 +1,57 @@ /* AtCore KDE Libary for 3D Printers Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira 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 "ifirmware.h" /** * @brief The MarlinPlugin class * Plugin for Marlin */ class MarlinPlugin : public IFirmware { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.atelier.core.firmware") Q_INTERFACES(IFirmware) public: /** * @brief Create new MarlinPlugin */ MarlinPlugin(); /** * @brief Return Plugin name * @return Marlin */ QString name() const override; + + /** + * @brief validateCommand to filter commands from messages + * @param lastMessage: last Message from printer + */ + void validateCommand(const QString &lastMessage) override; }; diff --git a/src/plugins/repetierplugin.cpp b/src/plugins/repetierplugin.cpp index e417458..5d1be27 100644 --- a/src/plugins/repetierplugin.cpp +++ b/src/plugins/repetierplugin.cpp @@ -1,41 +1,87 @@ /* AtCore KDE Libary for 3D Printers Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira 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 #include "repetierplugin.h" #include "atcore.h" Q_LOGGING_CATEGORY(REPETIER_PLUGIN, "org.kde.atelier.core.firmware.repetier") QString RepetierPlugin::name() const { return QStringLiteral("Repetier"); } RepetierPlugin::RepetierPlugin() { qCDebug(REPETIER_PLUGIN) << name() << " plugin loaded!"; } + +void RepetierPlugin::validateCommand(const QString &lastMessage) +{ + if (lastMessage.contains(QStringLiteral("End file list"))) { + core()->setReadingSdCardList(false); + } else if (core()->isReadingSdCardList()) { + // Below is to not add directories + if (!lastMessage.endsWith(QChar::fromLatin1('/'))) { + QString fileName = lastMessage; + fileName.chop(fileName.length() - fileName.lastIndexOf(QChar::fromLatin1(' '))); + core()->appendSdCardFileList(fileName); + } + } else { + if (lastMessage.contains(QStringLiteral("SD card"))) { + if (lastMessage.contains(QStringLiteral("inserted"))) { + core()->setSdMounted(true); + } else if (lastMessage.contains(QStringLiteral("removed"))) { + core()->setSdMounted(false); + } + } else if (lastMessage.contains(QStringLiteral("Begin file list"))) { + core()->setSdMounted(true); + core()->setReadingSdCardList(true); + core()->clearSdCardFileList(); + } else if (lastMessage.contains(QStringLiteral("SD printing byte"))) { + QString temp = lastMessage; + temp.replace(QStringLiteral("SD printing byte"), QString()); + qlonglong total = temp.mid(temp.lastIndexOf(QChar::fromLatin1('/')) + 1, temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))).toLongLong(); + if (total) { + temp.chop(temp.length() - temp.lastIndexOf(QChar::fromLatin1('/'))); + qlonglong remaining = total - temp.toLongLong(); + float progress = float(total - remaining) * 100 / float(total); + core()->printProgressChanged(progress); + if (progress >= 100) { + core()->setState(AtCore::FINISHEDPRINT); + core()->setState(AtCore::IDLE); + } + } else { + core()->setState(AtCore::FINISHEDPRINT); + core()->setState(AtCore::IDLE); + } + } + if (lastMessage.contains(QStringLiteral("ok"))) { + emit readyForCommand(); + } + } +} diff --git a/src/plugins/repetierplugin.h b/src/plugins/repetierplugin.h index b827be3..8778a3c 100644 --- a/src/plugins/repetierplugin.h +++ b/src/plugins/repetierplugin.h @@ -1,51 +1,57 @@ /* AtCore KDE Libary for 3D Printers Copyright (C) <2016> Authors: Tomaz Canabrava Chris Rizzitello Patrick José Pereira 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 "ifirmware.h" /** * @brief The RepetierPlugin class * Plugin for Repetier */ class RepetierPlugin : public IFirmware { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.atelier.core.firmware") Q_INTERFACES(IFirmware) public: /** * @brief Create new RepetierPlugin */ RepetierPlugin(); /** * @brief Return Plugin name * @return Repetier */ QString name() const override; + + /** + * @brief validateCommand to filter commands from messages + * @param lastMessage: last Message from printer + */ + void validateCommand(const QString &lastMessage) override; }; diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp index 2cf6ea5..6ab7788 100644 --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -1,583 +1,628 @@ /* AtCore Test Client Copyright (C) <2016> Authors: Patrick José Pereira Lays Rodrigues Chris Rizzitello Tomaz Canabrava 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 #include #include #include #include #include "mainwindow.h" #include "seriallayer.h" #include "gcodecommands.h" #include "widgets/axiscontrol.h" #include "widgets/about.h" Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core") int MainWindow::fanCount = 4; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), core(new AtCore(this)), logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/AtCore_"))) { ui->setupUi(this); setWindowIcon(QIcon(QStringLiteral(":/icon/windowIcon"))); QCoreApplication::setApplicationVersion(core->version()); ui->serialPortCB->setEditable(true); QValidator *validator = new QIntValidator(); ui->baudRateLE->setValidator(validator); ui->baudRateLE->addItems(core->portSpeeds()); ui->baudRateLE->setCurrentIndex(9); ui->pluginCB->addItem(tr("Autodetect")); ui->pluginCB->addItems(core->availableFirmwarePlugins()); AxisControl *axisControl = new AxisControl; ui->moveDockContents->layout()->addWidget(axisControl); addLog(tr("Attempting to locate Serial Ports")); core->setSerialTimerInterval(1000); populateCBs(); //Icon for actionQuit #ifndef Q_OS_MAC ui->actionQuit->setIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); #endif //hide the printing progress bar. ui->printLayout->setVisible(false); ui->statusBar->addWidget(ui->statusBarWidget); printTime = new QTime(); printTimer = new QTimer(); printTimer->setInterval(1000); printTimer->setSingleShot(false); connect(printTimer, &QTimer::timeout, this, &MainWindow::updatePrintTime); connect(ui->connectPB, &QPushButton::clicked, this, &MainWindow::connectPBClicked); connect(ui->saveLogPB, &QPushButton::clicked, this, &MainWindow::saveLogPBClicked); connect(ui->sendPB, &QPushButton::clicked, this, &MainWindow::sendPBClicked); connect(ui->commandLE, &QLineEdit::returnPressed, this, &MainWindow::sendPBClicked); connect(ui->homeAllPB, &QPushButton::clicked, this, &MainWindow::homeAllPBClicked); connect(ui->homeXPB, &QPushButton::clicked, this, &MainWindow::homeXPBClicked); connect(ui->homeYPB, &QPushButton::clicked, this, &MainWindow::homeYPBClicked); connect(ui->homeZPB, &QPushButton::clicked, this, &MainWindow::homeZPBClicked); connect(ui->bedTempPB, &QPushButton::clicked, this, &MainWindow::bedTempPBClicked); connect(ui->extTempPB, &QPushButton::clicked, this, &MainWindow::extTempPBClicked); connect(ui->mvAxisPB, &QPushButton::clicked, this, &MainWindow::mvAxisPBClicked); connect(ui->fanSpeedPB, &QPushButton::clicked, this, &MainWindow::fanSpeedPBClicked); connect(ui->printPB, &QPushButton::clicked, this, &MainWindow::printPBClicked); + connect(ui->sdPrintPB, &QPushButton::clicked, this, &MainWindow::sdPrintPBClicked); + connect(ui->sdDelPB, &QPushButton::clicked, this, &MainWindow::sdDelPBClicked); connect(ui->printerSpeedPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked); connect(ui->flowRatePB, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked); connect(ui->showMessagePB, &QPushButton::clicked, this, &MainWindow::showMessage); connect(ui->pluginCB, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged); connect(ui->disableMotorsPB, &QPushButton::clicked, this, &MainWindow::disableMotorsPBClicked); + connect(ui->sdListPB, &QPushButton::clicked, this, &MainWindow::getSdList); connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); connect(this, &MainWindow::printFile, core, &AtCore::print); connect(ui->stopPB, &QPushButton::clicked, core, &AtCore::stop); connect(ui->emergencyStopPB, &QPushButton::clicked, core, &AtCore::emergencyStop); connect(axisControl, &AxisControl::clicked, this, &MainWindow::axisControlClicked); connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); connect(core, &AtCore::printProgressChanged, this, &MainWindow::printProgressChanged); + connect(core, &AtCore::sdMountChanged, this, &MainWindow::sdChanged); + + connect(core, &AtCore::sdCardFileListChanged, [ & ](QStringList fileList) { + ui->sdFileListView->clear(); + ui->sdFileListView->addItems(fileList); + }); connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { checkTemperature(0x00, 0, temp); ui->plotWidget->appendPoint(tr("Actual Bed"), temp); ui->plotWidget->update(); }); connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x01, 0, temp); ui->plotWidget->appendPoint(tr("Target Bed"), temp); ui->plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { checkTemperature(0x02, 0, temp); ui->plotWidget->appendPoint(tr("Actual Ext.1"), temp); ui->plotWidget->update(); }); connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { checkTemperature(0x03, 0, temp); ui->plotWidget->appendPoint(tr("Target Ext.1"), temp); ui->plotWidget->update(); }); connect(ui->actionQuit, &QAction::triggered, this, &MainWindow::close); connect(ui->actionShowDockTitles, &QAction::toggled, this, &MainWindow::toggleDockTitles); connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::about); ui->menuView->insertAction(nullptr, ui->connectDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->tempControlsDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->commandDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->printDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->moveDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->tempTimelineDock->toggleViewAction()); ui->menuView->insertAction(nullptr, ui->logDock->toggleViewAction()); + ui->menuView->insertAction(nullptr, ui->sdDock->toggleViewAction()); //more dock stuff. setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); tabifyDockWidget(ui->moveDock, ui->tempControlsDock); + tabifyDockWidget(ui->moveDock, ui->sdDock); ui->moveDock->raise(); tabifyDockWidget(ui->connectDock, ui->printDock); tabifyDockWidget(ui->connectDock, ui->commandDock); ui->connectDock->raise(); setCentralWidget(nullptr); } void MainWindow::closeEvent(QCloseEvent *event) { core->close(); event->accept(); } MainWindow::~MainWindow() { delete logFile; delete ui; } QString MainWindow::getTime() { return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); } QString MainWindow::logHeader() { return QStringLiteral("[%1] ").arg(getTime()); } QString MainWindow::rLogHeader() { return QStringLiteral("[%1]< ").arg(getTime()); } QString MainWindow::sLogHeader() { return QStringLiteral("[%1]> ").arg(getTime()); } void MainWindow::writeTempFile(QString text) { /* A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the data in the file. This function will return true upon success and will set the fileName() to the unique filename used. */ logFile->open(); logFile->seek(logFile->size()); logFile->write(text.toLatin1()); logFile->putChar('\n'); logFile->close(); } void MainWindow::addLog(QString msg) { QString message(logHeader() + msg); ui->logTE->appendPlainText(message); writeTempFile(message); } void MainWindow::addRLog(QString msg) { QString message(rLogHeader() + msg); ui->logTE->appendPlainText(message); writeTempFile(message); } void MainWindow::addSLog(QString msg) { QString message(sLogHeader() + msg); ui->logTE->appendPlainText(message); writeTempFile(message); } void MainWindow::checkReceivedCommand(const QByteArray &message) { addRLog(QString::fromUtf8(message)); } void MainWindow::checkPushedCommands(QByteArray bmsg) { QString msg = QString::fromUtf8(bmsg); QRegExp _newLine(QChar::fromLatin1('\n')); QRegExp _return(QChar::fromLatin1('\r')); msg.replace(_newLine, QStringLiteral("\\n")); msg.replace(_return, QStringLiteral("\\r")); addSLog(msg); } void MainWindow::checkTemperature(uint sensorType, uint number, uint temp) { QString msg; switch (sensorType) { case 0x00: // bed msg = QString::fromLatin1("Bed Temperature "); break; case 0x01: // bed target msg = QString::fromLatin1("Bed Target Temperature "); break; case 0x02: // extruder msg = QString::fromLatin1("Extruder Temperature "); break; case 0x03: // extruder target msg = QString::fromLatin1("Extruder Target Temperature "); break; case 0x04: // enclosure msg = QString::fromLatin1("Enclosure Temperature "); break; case 0x05: // enclosure target msg = QString::fromLatin1("Enclosure Target Temperature "); break; } msg.append(QString::fromLatin1("[%1] : %2")); msg = msg.arg(QString::number(number)) .arg(QString::number(temp)); addRLog(msg); } /** * @brief MainWindow::locateSerialPort * Locate all active serial ports on the computer and add to the list * of serial ports */ void MainWindow::locateSerialPort(const QStringList &ports) { ui->serialPortCB->clear(); if (!ports.isEmpty()) { ui->serialPortCB->addItems(ports); addLog(tr("Found %1 Ports").arg(QString::number(ports.count()))); } else { QString portError(tr("No available ports! Please connect a serial device to continue!")); if (! ui->logTE->toPlainText().endsWith(portError)) { addLog(portError); } } } void MainWindow::connectPBClicked() { if (core->state() == AtCore::DISCONNECTED) { if (core->initSerial(ui->serialPortCB->currentText(), ui->baudRateLE->currentText().toInt())) { connect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); connect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); ui->connectPB->setText(tr("Disconnect")); addLog(tr("Serial connected")); if (ui->pluginCB->currentText().contains(tr("Autodetect"))) { addLog(tr("No plugin loaded !")); addLog(tr("Requesting Firmware...")); core->detectFirmware(); } else { core->loadFirmwarePlugin(ui->pluginCB->currentText()); } } else { addLog(tr("Failed to open serial in r/w mode")); } } else { disconnect(core, &AtCore::receivedMessage, this, &MainWindow::checkReceivedCommand); disconnect(core->serial(), &SerialLayer::pushedCommand, this, &MainWindow::checkPushedCommands); core->closeConnection(); core->setState(AtCore::DISCONNECTED); addLog(tr("Disconnected")); ui->connectPB->setText(tr("Connect")); } } void MainWindow::sendPBClicked() { QString comm = ui->commandLE->text().toUpper(); core->pushCommand(comm); ui->commandLE->clear(); } void MainWindow::homeAllPBClicked() { addSLog(tr("Home All")); core->home(); } void MainWindow::homeXPBClicked() { addSLog(tr("Home X")); core->home(AtCore::X); } void MainWindow::homeYPBClicked() { addSLog(tr("Home Y")); core->home(AtCore::Y); } void MainWindow::homeZPBClicked() { addSLog(tr("Home Z")); core->home(AtCore::Z); } void MainWindow::bedTempPBClicked() { if (ui->cb_andWait->isChecked()) { addSLog(GCode::description(GCode::M190)); } else { addSLog(GCode::description(GCode::M140)); } core->setBedTemp(ui->bedTempSB->value(), ui->cb_andWait->isChecked()); } void MainWindow::extTempPBClicked() { if (ui->cb_andWait->isChecked()) { addSLog(GCode::description(GCode::M109)); } else { addSLog(GCode::description(GCode::M104)); } core->setExtruderTemp(ui->extTempSB->value(), ui->extTempSelCB->currentIndex(), ui->cb_andWait->isChecked()); } void MainWindow::mvAxisPBClicked() { addSLog(GCode::description(GCode::G1)); if (ui->mvAxisCB->currentIndex() == 0) { core->move(AtCore::X, ui->mvAxisSB->value()); } else if (ui->mvAxisCB->currentIndex() == 1) { core->move(AtCore::Y, ui->mvAxisSB->value()); } else if (ui->mvAxisCB->currentIndex() == 2) { core->move(AtCore::Z, ui->mvAxisSB->value()); } } void MainWindow::fanSpeedPBClicked() { addSLog(GCode::description(GCode::M106)); core->setFanSpeed(ui->fanSpeedSB->value(), ui->fanSpeedSelCB->currentIndex()); } void MainWindow::printPBClicked() { QString fileName; switch (core->state()) { case AtCore::DISCONNECTED: QMessageBox::information(this, tr("Error"), tr("Not Connected To a Printer")); break; case AtCore::CONNECTING: QMessageBox::information(this, tr("Error"), tr(" A Firmware Plugin was not loaded!\n Please send the command M115 and let us know what your firmware returns, so we can improve our firmware detection. We have loaded the most common plugin \"repetier\" for you. You may try to print again after this message")); ui->pluginCB->setCurrentText(QStringLiteral("repetier")); break; case AtCore::IDLE: fileName = QFileDialog::getOpenFileName(this, tr("Select a file to print"), QDir::homePath(), QStringLiteral("*.gcode")); if (fileName.isNull()) { addLog(tr("No File Selected")); } else { addLog(tr("Print: %1").arg(fileName)); emit(printFile(fileName)); } break; case AtCore::BUSY: core->pause(ui->postPauseLE->text()); break; case AtCore::PAUSE: core->resume(); break; default: qCDebug(TESTCLIENT_MAINWINDOW) << "ERROR / STOP unhandled."; } } void MainWindow::saveLogPBClicked() { // Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it). QString fileName = QDir::homePath() + QChar::fromLatin1('/') + QFileInfo(logFile->fileName()).fileName() + QStringLiteral(".txt"); QString saveFileName = QFileDialog::getSaveFileName(this, tr("Save Log to file"), fileName); QFile::copy(logFile->fileName(), saveFileName); logFile->close(); } void MainWindow::pluginCBChanged(QString currentText) { if (core->state() != AtCore::DISCONNECTED) { if (!currentText.contains(tr("Autodetect"))) { core->loadFirmwarePlugin(currentText); } else { core->detectFirmware(); } } } void MainWindow::flowRatePBClicked() { core->setFlowRate(ui->flowRateSB->value()); } void MainWindow::printerSpeedPBClicked() { core->setPrinterSpeed(ui->printerSpeedSB->value()); } void MainWindow::printerStateChanged(AtCore::STATES state) { QString stateString; switch (state) { case AtCore::IDLE: ui->printPB->setText(tr("Print File")); stateString = QStringLiteral("Connected to ") + core->connectedPort(); break; case AtCore::STARTPRINT: stateString = QStringLiteral("START PRINT"); ui->printPB->setText(tr("Pause Print")); ui->printLayout->setVisible(true); printTime->start(); printTimer->start(); break; case AtCore::FINISHEDPRINT: stateString = QStringLiteral("Finished Print"); ui->printPB->setText(tr("Print File")); ui->printLayout->setVisible(false); printTimer->stop(); break; case AtCore::PAUSE: stateString = QStringLiteral("Paused"); ui->printPB->setText(tr("Resume Print")); break; case AtCore::BUSY: stateString = QStringLiteral("Printing"); ui->printPB->setText(tr("Pause Print")); break; case AtCore::DISCONNECTED: stateString = QStringLiteral("Not Connected"); ui->commandDock->setDisabled(true); ui->moveDock->setDisabled(true); ui->tempControlsDock->setDisabled(true); ui->printDock->setDisabled(true); + ui->sdDock->setDisabled(true); break; case AtCore::CONNECTING: stateString = QStringLiteral("Connecting"); ui->commandDock->setDisabled(false); ui->moveDock->setDisabled(false); ui->tempControlsDock->setDisabled(false); ui->printDock->setDisabled(false); + ui->sdDock->setDisabled(false); break; case AtCore::STOP: stateString = QStringLiteral("Stoping Print"); break; case AtCore::ERRORSTATE: stateString = QStringLiteral("Command ERROR"); break; } ui->lblState->setText(stateString); } void MainWindow::populateCBs() { // Extruders for (int count = 0; count < core->extruderCount(); count++) { ui->extTempSelCB->insertItem(count, tr("Extruder %1").arg(count)); } // Fan for (int count = 0; count < fanCount; count++) { ui->fanSpeedSelCB->insertItem(count, tr("Fan %1 speed").arg(count)); } } void MainWindow::showMessage() { core->showMessage(ui->messageLE->text()); } void MainWindow::updatePrintTime() { QTime temp(0, 0, 0); ui->time->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); } void MainWindow::printProgressChanged(int progress) { ui->printingProgress->setValue(progress); if (progress > 0) { QTime temp(0, 0, 0); ui->timeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); } else { ui->timeLeft->setText(QStringLiteral("??:??:??")); } } void MainWindow::toggleDockTitles() { if (ui->actionShowDockTitles->isChecked()) { delete ui->connectDock->titleBarWidget(); delete ui->logDock->titleBarWidget(); delete ui->tempTimelineDock->titleBarWidget(); delete ui->commandDock->titleBarWidget(); delete ui->moveDock->titleBarWidget(); delete ui->tempControlsDock->titleBarWidget(); delete ui->printDock->titleBarWidget(); + delete ui->sdDock->titleBarWidget(); } else { ui->connectDock->setTitleBarWidget(new QWidget()); ui->logDock->setTitleBarWidget(new QWidget()); ui->tempTimelineDock->setTitleBarWidget(new QWidget()); ui->commandDock->setTitleBarWidget(new QWidget()); ui->moveDock->setTitleBarWidget(new QWidget()); ui->tempControlsDock->setTitleBarWidget(new QWidget()); ui->printDock->setTitleBarWidget(new QWidget()); + ui->sdDock->setTitleBarWidget(new QWidget()); } } void MainWindow::about() { About *aboutDialog = new About(this); aboutDialog->exec(); } void MainWindow::axisControlClicked(QLatin1Char axis, int value) { core->setRelativePosition(); core->move(axis, value); core->setAbsolutePosition(); } void MainWindow::disableMotorsPBClicked() { core->setIdleHold(0); } + +void MainWindow::sdChanged(bool mounted) +{ + QString labelText = mounted ? QStringLiteral("SD") : QString(); + ui->lbl_sd->setText(labelText); +} + +void MainWindow::getSdList() +{ + core->sdFileList(); +} + +void MainWindow::sdPrintPBClicked() +{ + if (ui->sdFileListView->currentRow() < 0) { + QMessageBox::information(this, QStringLiteral("Print Error"), QStringLiteral("You must Select a file from the list")); + } else { + core->print(ui->sdFileListView->currentItem()->text(), true); + } +} + +void MainWindow::sdDelPBClicked() +{ + if (ui->sdFileListView->currentRow() < 0) { + QMessageBox::information(this, QStringLiteral("Delete Error"), QStringLiteral("You must Select a file from the list")); + } else { + core->sdDelete(ui->sdFileListView->currentItem()->text()); + ui->sdFileListView->setCurrentRow(-1); + } +} diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h index 5657736..f78b10f 100644 --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -1,272 +1,293 @@ /* AtCore Test Client Copyright (C) <2016> Authors: Patrick José Pereira Lays Rodrigues Chris Rizzitello Tomaz Canabrava 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 . */ #pragma once #include #include #include #include "ui_mainwindow.h" #include "atcore.h" class SerialLayer; class MainWindow: public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() override; public slots: /** * @brief Check received messages * */ void checkReceivedCommand(const QByteArray &message); /** * @brief Check pushed message * * @param bmsg : Message */ void checkPushedCommands(QByteArray); /** * @brief Check temperature * * @param sensorType : type of sensor * @param number : index of sensor * @param temp : temperature */ void checkTemperature(uint sensorType, uint number, uint temp); private slots: //ButtonEvents /** * @brief axisControlClicked Used to catch the axis control. * @param axis The Axis clicked on (X |Y |Z) * @param value Distance Value */ void axisControlClicked(QLatin1Char axis, int value); /** * @brief the printing progress has changed * @param progress: the new progress */ void printProgressChanged(int progress); /** * @brief Connect Button Clicked will connect or disconnect based on printer state */ void connectPBClicked(); /** * @brief Send Command Clicked */ void sendPBClicked(); /** * @brief Home All Clicked */ void homeAllPBClicked(); /** * @brief Home X Axis Clicked */ void homeXPBClicked(); /** * @brief Home Y Axis Clicked */ void homeYPBClicked(); /** * @brief Home Z Axis Clicked */ void homeZPBClicked(); /** * @brief Set Bed Temp Clicked */ void bedTempPBClicked(); /** * @brief Set Extruder Temp Clicked */ void extTempPBClicked(); /** * @brief Move Axis Clicked */ void mvAxisPBClicked(); /** * @brief Set Fan Speed Clicked */ void fanSpeedPBClicked(); /** * @brief Print Button Clicked, can also pause /resue print based on printer state */ void printPBClicked(); + /** + * @brief Print Button for Sd Prints clicked. + */ + void sdPrintPBClicked(); /** * @brief Save the log file. */ void saveLogPBClicked(); /** * @brief set printer speed clicked */ void printerSpeedPBClicked(); /** * @brief lowRatePB has been clicked */ void flowRatePBClicked(); /** * @brief disableMotorsPB has been clicked */ void disableMotorsPBClicked(); /** * @brief printerStateChanged Catch and proccess printer state commands * @param state: new printer state */ void printerStateChanged(AtCore::STATES state); /** * @brief showMessage show a message on the printers LCD */ void showMessage(); /** * @brief Update the print Time */ void updatePrintTime(); /** * @brief show/hide dock titlebars */ void toggleDockTitles(); /** * @brief Show the about dialog */ void about(); + + /** + * @brief List Files on the sd card. + */ + void getSdList(); + + /** + * @brief Sd Card Delete file clicked + */ + void sdDelPBClicked(); + signals: /** * @brief printFile emit ready to print a file to atcore * @param fileName : the file to print + * @param sdPrint : True if file is on printers Sd Card */ - void printFile(const QString &fileName); + void printFile(const QString &fileName, bool sdPrint = false); private: Ui::MainWindow *ui; AtCore *core; QTemporaryFile *logFile; QTime *printTime; QTimer *printTimer; // Define max number of fans static int fanCount; void closeEvent(QCloseEvent *event) override; /** * @brief Locate serial port * */ void locateSerialPort(const QStringList &ports); /** * @brief Return string with actual time * * @return QString */ QString getTime(); /** * @brief Append text in temporary file * * @param text */ void writeTempFile(QString text); /** * @brief Normal header * * @return QString */ QString logHeader(); /** * @brief Header of type received * * @return QString */ QString rLogHeader(); /** * @brief Header of type send * * @return QString */ QString sLogHeader(); /** * @brief Add in logger normal type message * * @param msg: Message */ void addLog(QString msg); /** * @brief Add in logger received type message * * @param msg: Message */ void addRLog(QString msg); /** * @brief Add in logger send type message * * @param msg: Message */ void addSLog(QString msg); /** * @brief pluginCB index changed */ void pluginCBChanged(QString currentText); /** * @brief setupActions for KXMLGui */ void setupActions(); /** * @brief Populate comboboxes */ void populateCBs(); + + /** + * @brief Gui Changes for when sd card mount status has changed. + */ + void sdChanged(bool mounted); }; diff --git a/testclient/mainwindow.ui b/testclient/mainwindow.ui index f82ac6b..3c53444 100644 --- a/testclient/mainwindow.ui +++ b/testclient/mainwindow.ui @@ -1,969 +1,1069 @@ MainWindow 0 0 0 0 AtCore - Test Client 6 418 801 46 100 0 0 0 0 0 AtCoreState: Not Connected + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + Qt::Horizontal QSizePolicy::Expanding 40 20 0 0 QFrame::StyledPanel QFrame::Raised 0 0 0 0 true 0 Stop Print Job .. <html><head/><body><p>Elapsed Time</p></body></html> 00:00:00 Qt::AlignCenter / <html><head/><body><p>Remaining Time</p></body></html> 00:00:00 Qt::AlignCenter false 10 0 473 243 0 0 &Print Print File 0 0 Emergency Stop On Pause: G91,G0 Z1,G90,G1 X0 Y195 0 0 Printer Speed % 300 100 0 0 Set 0 0 Flow Rate % 300 100 0 0 Set false 0 240 485 146 0 0 Comma&nds Send Command Send Show Message Send + + + false + + + + 0 + 42 + 515 + 317 + + + + S&d Card + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Get List + + + + + + + Print Selected + + + + + + + Delete Selected + + + + + + + + + + Files On Sd Card. + + + + + + + + + + + 0 0 Temperat&ure Timeline 2 0 0 0 0 0 0 &Connection Settings 1 0 0 0 0 0 0 0 0 Port: 0 0 Baud Rate: true Use Plugin 0 0 0 0 Connect 0 0 Session &Log 2 0 0 0 0 0 0 true 0 0 true 1000 Save Session Log .. Qt::NoContextMenu false false 0 0 &Movement 1 Home All Home X Home Y Home Z 0 0 0 0 Move X Axis to Move Y Axis to Move Z Axis to 0 0 0 0 Qt::AlignCenter 0 200.000000000000000 0 0 Go Disable Motors false 0 0 &Temperatures 1 Wait Untill Temperature Stablizes 0 0 Bed Temp Qt::AlignCenter °C 0 100.000000000000000 Set 0 0 Qt::AlignCenter °C 0 275.000000000000000 Set 0 0 Qt::AlignCenter % 100 0 0 Set 0 0 767 37 &File &View &Help &Quit true true &Show Dock Titles &About F1 PlotWidget QWidget
plotwidget.h
1
diff --git a/unittests/gcodetests.cpp b/unittests/gcodetests.cpp index 4cfd78a..3b9ca82 100644 --- a/unittests/gcodetests.cpp +++ b/unittests/gcodetests.cpp @@ -1,167 +1,231 @@ /* This file is part of the KDE project Copyright (C) 2017 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 "gcodetests.h" bool GCodeTests::testGCodeNeedsArg(GCode::GCommands code) { return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("G"), QString::number(code)); } void GCodeTests::command_G0() { QVERIFY(GCode::toCommand(GCode::G0) == QStringLiteral("G0")); QVERIFY(GCode::toCommand(GCode::G0, QStringLiteral("50")) == QStringLiteral("G0 50")); } void GCodeTests::command_G1() { QVERIFY(GCode::toCommand(GCode::G1) == QStringLiteral("G1")); QVERIFY(GCode::toCommand(GCode::G1, QStringLiteral("50")) == QStringLiteral("G1 50")); } void GCodeTests::command_G28() { QVERIFY(GCode::toCommand(GCode::G28) == QStringLiteral("G28")); QVERIFY(GCode::toCommand(GCode::G28, QStringLiteral("Y")) == QStringLiteral("G28 Y")); } void GCodeTests::command_G32() { QVERIFY(GCode::toCommand(GCode::G32) == QStringLiteral("G32 S1")); } void GCodeTests::command_G90() { QVERIFY(GCode::toCommand(GCode::G90) == QStringLiteral("G90")); } void GCodeTests::command_G91() { QVERIFY(GCode::toCommand(GCode::G91) == QStringLiteral("G91")); } void GCodeTests::command_unsupportedG() { QVERIFY(GCode::toCommand(GCode::G2) == GCode::commandNotSupported); } bool GCodeTests::testMCodeNeedsArg(GCode::MCommands code) { return GCode::toCommand(code) == GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(code)); } +void GCodeTests::command_M20() +{ + QVERIFY(GCode::toCommand(GCode::M20) == QStringLiteral("M20")); +} + +void GCodeTests::command_M21() +{ + QVERIFY(GCode::toCommand(GCode::M21) == QStringLiteral("M21")); + QVERIFY(GCode::toCommand(GCode::M21, QStringLiteral("2")) == QStringLiteral("M21 P2")); +} + +void GCodeTests::command_M22() +{ + QVERIFY(GCode::toCommand(GCode::M22) == QStringLiteral("M22")); + QVERIFY(GCode::toCommand(GCode::M22, QStringLiteral("5")) == QStringLiteral("M22 P5")); +} + +void GCodeTests::command_M23() +{ + QVERIFY(testMCodeNeedsArg(GCode::M23)); + QVERIFY(GCode::toCommand(GCode::M23, QStringLiteral("FileName")) == QStringLiteral("M23 FileName")); +} + +void GCodeTests::command_M24() +{ + QVERIFY(GCode::toCommand(GCode::M24) == QStringLiteral("M24")); +} + +void GCodeTests::command_M25() +{ + QVERIFY(GCode::toCommand(GCode::M25) == QStringLiteral("M25")); +} + +void GCodeTests::command_M26() +{ + QVERIFY(testMCodeNeedsArg(GCode::M26)); + QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15%")) == QStringLiteral("M26 P0.15")); + QVERIFY(GCode::toCommand(GCode::M26, QStringLiteral("15")) == QStringLiteral("M26 S15")); + +} + +void GCodeTests::command_M27() +{ + QVERIFY(GCode::toCommand(GCode::M27) == QStringLiteral("M27")); +} + +void GCodeTests::command_M28() +{ + QVERIFY(testMCodeNeedsArg(GCode::M28)); + QVERIFY(GCode::toCommand(GCode::M28, QStringLiteral("FileName")) == QStringLiteral("M28 FileName")); +} + +void GCodeTests::command_M29() +{ + QVERIFY(testMCodeNeedsArg(GCode::M29)); + QVERIFY(GCode::toCommand(GCode::M29, QStringLiteral("FileName")) == QStringLiteral("M29 FileName")); +} + +void GCodeTests::command_M30() +{ + QVERIFY(testMCodeNeedsArg(GCode::M30)); + QVERIFY(GCode::toCommand(GCode::M30, QStringLiteral("FileName")) == QStringLiteral("M30 FileName")); +} + void GCodeTests::command_M84() { QVERIFY(GCode::toCommand(GCode::M84) == QStringLiteral("M84")); QVERIFY(GCode::toCommand(GCode::M84, QStringLiteral("10")) == QStringLiteral("M84 S10")); } void GCodeTests::command_M104() { QVERIFY(testMCodeNeedsArg(GCode::M104)); QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("100")) == QStringLiteral("M104 S100")); QVERIFY(GCode::toCommand(GCode::M104, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M104 P3 S100")); } void GCodeTests::command_M105() { QVERIFY(GCode::toCommand(GCode::M105) == QStringLiteral("M105")); } void GCodeTests::command_M106() { QVERIFY(GCode::toCommand(GCode::M106) == QStringLiteral("M106")); QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("100")) == QStringLiteral("M106 S100")); QVERIFY(GCode::toCommand(GCode::M106, QStringLiteral("3"), QStringLiteral("100")) == QStringLiteral("M106 P3 S100")); } void GCodeTests::command_M107() { QVERIFY(GCode::toCommand(GCode::M107) == QStringLiteral("M107")); } void GCodeTests::command_M109() { QVERIFY(testMCodeNeedsArg(GCode::M109)); QVERIFY(GCode::toCommand(GCode::M109, QStringLiteral("100")) == QStringLiteral("M109 S100")); } void GCodeTests::command_M112() { QVERIFY(GCode::toCommand(GCode::M112) == QStringLiteral("M112")); } void GCodeTests::command_M114() { QVERIFY(GCode::toCommand(GCode::M114) == QStringLiteral("M114")); } void GCodeTests::command_M115() { QVERIFY(GCode::toCommand(GCode::M115) == QStringLiteral("M115")); } void GCodeTests::command_M116() { QVERIFY(GCode::toCommand(GCode::M116) == QStringLiteral("M116")); } void GCodeTests::command_M117() { QVERIFY(testMCodeNeedsArg(GCode::M117)); QVERIFY(GCode::toCommand(GCode::M117, QStringLiteral("100")) == QStringLiteral("M117 100")); } void GCodeTests::command_M119() { QVERIFY(GCode::toCommand(GCode::M119) == QStringLiteral("M119")); } void GCodeTests::command_M140() { QVERIFY(testMCodeNeedsArg(GCode::M140)); QVERIFY(GCode::toCommand(GCode::M140, QStringLiteral("100")) == QStringLiteral("M140 S100")); } void GCodeTests::command_M190() { QVERIFY(testMCodeNeedsArg(GCode::M190)); QVERIFY(GCode::toCommand(GCode::M190, QStringLiteral("100")) == QStringLiteral("M190 S100")); } void GCodeTests::command_M220() { QVERIFY(testMCodeNeedsArg(GCode::M220));; QVERIFY(GCode::toCommand(GCode::M220, QStringLiteral("100")) == QStringLiteral("M220 S100")); } void GCodeTests::command_M221() { QVERIFY(testMCodeNeedsArg(GCode::M221));; QVERIFY(GCode::toCommand(GCode::M221, QStringLiteral("100")) == QStringLiteral("M221 S100")); } void GCodeTests::command_unsupportedM() { QVERIFY(GCode::toCommand(GCode::M999) == GCode::commandNotSupported); } QTEST_MAIN(GCodeTests) diff --git a/unittests/gcodetests.h b/unittests/gcodetests.h index b71c301..e647840 100644 --- a/unittests/gcodetests.h +++ b/unittests/gcodetests.h @@ -1,55 +1,66 @@ /* This file is part of the KDE project Copyright (C) 2017 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 #include "../src/gcodecommands.h" class GCodeTests: public QObject { Q_OBJECT private slots: bool testGCodeNeedsArg(GCode::GCommands code); void command_G0(); void command_G1(); void command_G28(); void command_G32(); void command_G90(); void command_G91(); void command_unsupportedG(); bool testMCodeNeedsArg(GCode::MCommands code); + void command_M20(); + void command_M21(); + void command_M22(); + void command_M23(); + void command_M24(); + void command_M25(); + void command_M26(); + void command_M27(); + void command_M28(); + void command_M29(); + void command_M30(); void command_M84(); void command_M104(); void command_M105(); void command_M106(); void command_M107(); void command_M109(); void command_M112(); void command_M114(); void command_M115(); void command_M116(); void command_M117(); void command_M119(); void command_M140(); void command_M190(); void command_M220(); void command_M221(); void command_unsupportedM(); };