diff --git a/doc/mainpage.md b/doc/mainpage.md --- a/doc/mainpage.md +++ b/doc/mainpage.md @@ -8,7 +8,7 @@ - Chris Rizzitello - Patrick José Pereira - - Lays Rodrigues
+ - Lays Rodrigues
- Tomaz Canabrava ## Supported Firmwares diff --git a/src/atcore.h b/src/atcore.h --- a/src/atcore.h +++ b/src/atcore.h @@ -45,7 +45,7 @@ * * #### General Workflow * - Connect to a serial port with initSerial() - * - Auto detect the firmware with detectFirmware() + * - Firmware will be auto detected. Use loadFirmwarePLugin() to force load a firmware. * - Send commands to the device (pushCommand(),print(),...) * - AtCore::close() when you are all done. @@ -168,29 +168,23 @@ /** * @brief Main access to the loaded firmware plugin * @return IFirmware * to currently loaded plugin - * @sa availableFirmwarePlugins(),loadFirmwarePlugin(),detectFirmware() + * @sa availableFirmwarePlugins(),loadFirmwarePlugin() */ Q_INVOKABLE IFirmware *firmwarePlugin() const; /** * @brief List of available firmware plugins - * @sa loadFirmwarePlugin(),firmwarePlugin(),detectFirmware() + * @sa loadFirmwarePlugin(),firmwarePlugin() */ QStringList availableFirmwarePlugins() const; /** * @brief Load A firmware plugin * @param fwName : name of the firmware - * @sa firmwarePlugin(),availableFirmwarePlugins(),detectFirmware() + * @sa firmwarePlugin(),availableFirmwarePlugins() */ 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 @@ -399,6 +393,7 @@ /** * @brief Disables idle hold of motors after a delay + * Motors will be disabled after the delay * @param delay: Seconds until idle hold is released. 0= No delay */ void setIdleHold(uint delay = 0); @@ -470,7 +465,7 @@ /** * @brief Search for firmware string in message. - * A Helper function for detectFirmware() + * A Helper function for Firmware detection * @param message */ void findFirmware(const QByteArray &message); diff --git a/src/atcore.cpp b/src/atcore.cpp --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -43,6 +43,7 @@ Q_LOGGING_CATEGORY(ATCORE_CORE, "org.kde.atelier.core") /** * @brief The AtCorePrivate struct + * Provides a private data set for atcore. */ struct AtCorePrivate { IFirmware *firmwarePlugin = nullptr;//!< @param firmwarePlugin: pointer to firmware plugin @@ -72,9 +73,11 @@ QObject(parent), d(new AtCorePrivate) { +//Resigter MetaTypes qRegisterMetaType("AtCore::STATES"); setState(AtCore::DISCONNECTED); +//Create and start the timer that checks for temperature. d->tempTimer = new QTimer(this); d->tempTimer->setInterval(5000); d->tempTimer->setSingleShot(false); @@ -140,6 +143,7 @@ } if (state() == AtCore::CONNECTING) { + //Most Firmware will return start when it comes up,some return their name. if (message.contains("start")) { qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; QTimer::singleShot(500, this, &AtCore::requestFirmware); @@ -152,7 +156,6 @@ return; } } - qCDebug(ATCORE_CORE) << "Find Firmware Called" << message; if (!message.contains("FIRMWARE_NAME:")) { qCDebug(ATCORE_CORE) << "No firmware yet."; @@ -188,6 +191,7 @@ void AtCore::loadFirmwarePlugin(const QString &fwName) { + //Check if we have a plugin named fwName then attempt to load it. if (d->plugins.contains(fwName)) { d->pluginLoader.setFileName(d->plugins[fwName]); if (!d->pluginLoader.load()) { @@ -198,10 +202,12 @@ d->firmwarePlugin = qobject_cast(d->pluginLoader.instance()); if (!firmwarePluginLoaded()) { + //Something when wrong loading the plugin. qCDebug(ATCORE_PLUGIN) << "No plugin loaded."; qCDebug(ATCORE_PLUGIN) << "Looking plugin in folder:" << d->pluginsDir; setState(AtCore::CONNECTING); } else { + //Plugin was loaded successfully. qCDebug(ATCORE_PLUGIN) << "Connected to" << firmwarePlugin()->name(); firmwarePlugin()->init(this); disconnect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); @@ -252,16 +258,16 @@ 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 + //Mac OS has callout serial ports starting with cu these devices are read only. + //It is necessary to filter them out to help prevent user error. if (!serialPortInfo.portName().startsWith(QStringLiteral("cu."), Qt::CaseInsensitive)) { ports.append(serialPortInfo.portName()); } #else ports.append(serialPortInfo.portName()); #endif } } - return ports; } @@ -285,22 +291,27 @@ void AtCore::setSerialTimerInterval(const quint16 &newTime) { if (newTime == 0) { + //The newTime is 0. Destroy the timer. if (d->serialTimer) { disconnect(d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); delete d->serialTimer; } return; } if (!d->serialTimer) { + //There is no timer. We need to create one. d->serialTimer = new QTimer(); connect(d->serialTimer, &QTimer::timeout, this, &AtCore::locateSerialPort); } + //Start over with the new time. d->serialTimer->start(newTime); } void AtCore::newMessage(const QByteArray &message) { + //Evaluate the messages coming from the printer. d->lastMessage = message; + //Check if the message has heads current location. if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { d->posString = message; d->posString.resize(d->posString.indexOf('E')); @@ -335,17 +346,19 @@ qCDebug(ATCORE_CORE) << "Load a firmware plugin to print."; return; } + //Start a print job. setState(AtCore::STARTPRINT); if (sdPrint) { + //Printing from the sd card requires us to send some codes. 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 + //Process the gcode with a printThread. QThread *thread = new QThread(); PrintThread *printThread = new PrintThread(this, fileName); printThread->moveToThread(thread); @@ -361,18 +374,20 @@ void AtCore::pushCommand(const QString &comm) { + //Push a command on to the queue d->commandQueue.append(comm); if (d->ready) { + //The printer is ready for a command now so push one. processQueue(); } } void AtCore::closeConnection() { if (serialInitialized()) { 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. + //We have to clean print if printing from the host. + //However disconnecting while printing from sd card should not affect the print job. setState(AtCore::STOP); } if (firmwarePluginLoaded()) { @@ -382,11 +397,13 @@ disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::checkTemperature); d->tempTimer->stop(); } + //Attempt to unload the firmware plugin. + 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); } - 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(); + //Clear our copy of the sdcard filelist clearSdCardFileList(); setState(AtCore::DISCONNECTED); } @@ -404,6 +421,7 @@ << d->printerState << "] to [" << state << "]"; d->printerState = state; if (state == AtCore::FINISHEDPRINT && d->sdCardPrinting) { + //Clean up the sd card print d->sdCardPrinting = false; disconnect(d->tempTimer, &QTimer::timeout, this, &AtCore::sdCardPrintStatus); } @@ -413,6 +431,7 @@ void AtCore::stop() { + //Stop a print job setState(AtCore::STOP); d->commandQueue.clear(); if (d->sdCardPrinting) { @@ -425,18 +444,24 @@ void AtCore::emergencyStop() { + //Emergency Stop. Stops the machine + //Clear the queue, and any print job + //Before sending the command to ensure + //Less chance of movement after the restart. d->commandQueue.clear(); if (AtCore::state() == AtCore::BUSY) { if (!d->sdCardPrinting) { //Stop our running print thread setState(AtCore::STOP); } } + //push command thru serial to bypass atcore's queue. serial()->pushCommand(GCode::toCommand(GCode::M112).toLocal8Bit()); } void AtCore::stopSdPrint() { + //Stop an SdCard Print. pushCommand(GCode::toCommand(GCode::M25)); d->sdCardFileName = QString(); pushCommand(GCode::toCommand(GCode::M23, d->sdCardFileName)); @@ -462,6 +487,7 @@ return false; } } + void AtCore::findFirmwarePlugins() { d->plugins.clear(); @@ -494,21 +520,18 @@ 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)); } + //push command to get head location pushCommand(GCode::toCommand(GCode::M114)); if (!pauseActions.isEmpty()) { QStringList temp = pauseActions.split(QChar::fromLatin1(',')); @@ -646,6 +669,7 @@ void AtCore::checkTemperature() { + //One request for the temperature in the queue at a time. if (d->commandQueue.contains(GCode::toCommand(GCode::M105))) { return; } @@ -670,20 +694,22 @@ break; } } + QStringList AtCore::portSpeeds() const { return serial()->validBaudRates(); } void AtCore::setIdleHold(uint delay) { + //Disables motors if (delay) { pushCommand(GCode::toCommand(GCode::M84, QString::number(delay))); } else { pushCommand(GCode::toCommand(GCode::M84)); } } - +//Most firmwares will not report if an sdcard is mounted on boot bool AtCore::isSdMounted() const { return d->sdCardMounted; diff --git a/src/atcore_default_folders.h.in b/src/atcore_default_folders.h.in --- a/src/atcore_default_folders.h.in +++ b/src/atcore_default_folders.h.in @@ -23,6 +23,16 @@ #include namespace AtCoreDirectories { + /** + * @brief pluginDir + * List of directories that AtCore will look for plugins. + * + * In Order: + * 1 Build Dir/plugins (buildtime) + * 2 ECM set KDE PLUGIN DIR (buildtime) + * 3 Qt Plugin path/AtCore (runtime) + * 4 Plugins/ (runtime) + */ const QStringList pluginDir = \ QStringList(QStringLiteral("@CMAKE_CURRENT_BINARY_DIR@/plugins")) \ << QStringList(QStringLiteral("@KDE_INSTALL_PLUGINDIR@/AtCore")) \ diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -306,7 +306,6 @@ if (ui->pluginCB->currentText().contains(tr("Autodetect"))) { addLog(tr("No plugin loaded !")); addLog(tr("Requesting Firmware...")); - core->detectFirmware(); } else { core->loadFirmwarePlugin(ui->pluginCB->currentText()); } @@ -442,8 +441,6 @@ if (core->state() != AtCore::DISCONNECTED) { if (!currentText.contains(tr("Autodetect"))) { core->loadFirmwarePlugin(currentText); - } else { - core->detectFirmware(); } } }