diff --git a/src/atcore.cpp b/src/atcore.cpp --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -473,13 +473,13 @@ void AtCore::pause(const QString &pauseActions) { 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++) { + for (int i = 0; i < temp.count(); i++) { pushCommand(temp.at(i)); } } + setState(AtCore::PAUSE); } void AtCore::resume() @@ -520,7 +520,6 @@ } else { pushCommand(GCode::toCommand(GCode::M104, QString::number(extruder), QString::number(temp))); } - temperature().setExtruderTargetTemperature(temp); } void AtCore::setBedTemp(uint temp, bool andWait) @@ -530,7 +529,6 @@ } else { pushCommand(GCode::toCommand(GCode::M140, QString::number(temp))); } - temperature().setBedTargetTemperature(temp); } void AtCore::setFanSpeed(uint speed, uint fanNumber) diff --git a/src/printthread.h b/src/printthread.h --- a/src/printthread.h +++ b/src/printthread.h @@ -101,5 +101,27 @@ * @brief end the print */ void endPrint(); + + /** + * @brief injectCommand Attempt to inject Command into the job from the currently printing file. + * + * + * Inject one of the following: line must start with ';#' + * example line ;# showMessage: Hello + * - pause:Comma seperated post pause commands - Pause the print job send comma seperated commands. + * - setExtTemp:Temp,extruder number,wait - set extruder Temperature. Use true or false for wait + * - setBedTemp:Temp,wait - Set the bed Temperature. Use true or false for wait + * - setFanSpeed:speed, Fan# - set fan#'s speed range: 0-255. + * - setPrintSpeed:speed - set print speed range: 0-100. + * - setFlowRate:rate - set FlowRate range: 0-100. + * - showMessage:message - Show message on printer's LCD + * - Command:command - inject your own command. Command is sent as is to be sure you line is correct. + * @param command a valid command Begins with ;# + */ + void injectCommand(QString command); + + /** + * @brief d: Private storage for the thread + */ PrintThreadPrivate *d; }; diff --git a/src/printthread.cpp b/src/printthread.cpp --- a/src/printthread.cpp +++ b/src/printthread.cpp @@ -80,7 +80,7 @@ while (d->cline.isEmpty() && !d->gcodestream->atEnd()) { nextLine(); } - if (!d->cline.isEmpty()) { + if (!d->cline.isEmpty() && d->core->state() != AtCore::PAUSE) { qCDebug(PRINT_THREAD) << "cline:" << d->cline; emit nextCommand(d->cline); } @@ -96,6 +96,9 @@ } case AtCore::PAUSE: + if (d->cline.startsWith(QStringLiteral(";#"))) { + nextLine(); + } break; default: @@ -126,6 +129,9 @@ qCDebug(PRINT_THREAD) << "progress:" << QString::number(d->printProgress); emit(printProgressChanged(d->printProgress)); if (d->cline.contains(QChar::fromLatin1(';'))) { + if (d->cline.startsWith(QStringLiteral(";#"))) { + injectCommand(d->cline); + } d->cline.resize(d->cline.indexOf(QChar::fromLatin1(';'))); } d->cline = d->cline.simplified(); @@ -150,3 +156,39 @@ connect(d->core, &AtCore::stateChanged, this, &PrintThread::setState, Qt::QueuedConnection); } } + +void PrintThread::injectCommand(QString command) +{ + //remove ;# + command.remove(0, 2); + command = command.simplified(); + QStringList cmd = command.split(QLatin1Char(':')); + cmd.replace(1, cmd.at(1).simplified()); + + qCDebug(PRINT_THREAD) << "attempting to inject " << command; + + if (cmd.at(0).startsWith(QStringLiteral("pause"), Qt::CaseInsensitive)) { + d->core->pause(cmd.at(1)); + } else if (cmd.at(0).startsWith(QStringLiteral("setExtTemp"), Qt::CaseInsensitive)) { + QStringList arg = cmd.at(1).split(QStringLiteral(",")); + bool wait = QString::compare(arg.at(2), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setExtruderTemp(arg.at(0).toInt(), arg.at(1).toInt(), wait); + } else if (cmd.at(0).startsWith(QStringLiteral("setBedTemp:"), Qt::CaseInsensitive)) { + QStringList arg = cmd.at(1).split(QStringLiteral(",")); + bool wait = QString::compare(arg.at(1), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setBedTemp(arg.at(0).toInt(), wait); + } else if (cmd.at(0).startsWith(QStringLiteral("setPrintSpeed"), Qt::CaseInsensitive)) { + d->core->setPrinterSpeed(cmd.at(1).toInt()); + } else if (cmd.at(0).startsWith(QStringLiteral("setFlowRate"), Qt::CaseInsensitive)) { + d->core->setFlowRate(cmd.at(1).toInt()); + } else if (cmd.at(0).startsWith(QStringLiteral("setFanSpeed"), Qt::CaseInsensitive)) { + QStringList arg = cmd.at(1).split(QStringLiteral(",")); + d->core->setFanSpeed(arg.at(0).toInt(), arg.at(1).toInt()); + } else if (cmd.at(0).startsWith(QStringLiteral("showMessage"), Qt::CaseInsensitive)) { + d->core->showMessage(cmd.at(1)); + } else if (cmd.at(0).startsWith(QStringLiteral("Command"), Qt::CaseInsensitive)) { + d->core->pushCommand(cmd.at(1)); + } else { + qCDebug(PRINT_THREAD) << "Attempted to inject unknown command: " << command; + } +}