diff --git a/src/atcore.cpp b/src/atcore.cpp --- a/src/atcore.cpp +++ b/src/atcore.cpp @@ -562,7 +562,6 @@ } else { pushCommand(GCode::toCommand(GCode::M104, QString::number(extruder), QString::number(temp))); } - temperature().setExtruderTargetTemperature(temp); } void AtCore::setBedTemp(uint temp, bool andWait) @@ -572,7 +571,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,53 @@ * @brief end the print */ void endPrint(); + + /** + * @brief injectCommand Attempt to inject a Command from the currently printing file. + * + * One of the following on a line that starts with ';-' \n + * example line ;-Message: Hello \n + * + * - Pause: ppc\n + * Pause the print job and then run the comma seperated commands after pausing the job.\n + * + ppc: A comma seperated list of Commands to send after pause. ex(G91, G0 Z1, G90, G1 X0 Y195)\n + *\n + * - Extruder %Temperature:newTemp,extnum,wait \n + * Set extruder temperature. \n + * + newTemp: new target temperature. \n + * + extnum: Extruder number you want to Heat. Starting at 0. \n + * + wait: ignore commands until the target is reached. [true | false] \n + *\n + * - Bed %Temperature: newTemp,wait \n + * Set the bed temperature. \n + * + newTemp: new target temperature \n + * + wait: ignore commands until the target is reached. [true | false] \n + *\n + * - Fan Speed:newSpeed, fanNum \n + * Set the Fan speed. \n + * + newSpeed: new fan speed. \n + * + fanNum: Fan number. Starting at 0.\n + *\n + * - Print Speed:newSpeed \n + * Set the printer speed. \n + * + newSpeed: the print speed. 100= movement speed defined in file. \n + *\n + * - Flow Rate:newRate \n + * Set the flow rate \n + * + newRate: the flow rate. 100 = flow rate defined in file. \n + *\n + * - Message:message \n + * Show a message the printer's LCD \n + * + message: the message to print. \n + *\n + * - Command:command \n + * Inject your own command. Command are sent as is. Be sure your line is correct. \n + * + command: Commands to inject \n + */ + 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("Extruder Temperature"), Qt::CaseInsensitive)) { + QStringList arg = cmd.at(1).split(QStringLiteral(",")); + bool wait = QString::compare(arg.at(2).simplified(), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setExtruderTemp(arg.at(0).toInt(), arg.at(1).toInt(), wait); + } else if (cmd.at(0).startsWith(QStringLiteral("Bed Temperature:"), Qt::CaseInsensitive)) { + QStringList arg = cmd.at(1).split(QStringLiteral(",")); + bool wait = QString::compare(arg.at(1).simplified(), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setBedTemp(arg.at(0).toInt(), wait); + } else if (cmd.at(0).startsWith(QStringLiteral("Print Speed"), Qt::CaseInsensitive)) { + d->core->setPrinterSpeed(cmd.at(1).toInt()); + } else if (cmd.at(0).startsWith(QStringLiteral("Flow Rate"), Qt::CaseInsensitive)) { + d->core->setFlowRate(cmd.at(1).toInt()); + } else if (cmd.at(0).startsWith(QStringLiteral("Fan Speed"), 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("Message"), Qt::CaseInsensitive)) { + d->core->showMessage(cmd.at(1)); + } else if (cmd.at(0).startsWith(QStringLiteral("Command"), Qt::CaseInsensitive)) { + d->core->pushCommand(cmd.at(1).simplified()); + } else { + qCDebug(PRINT_THREAD) << "Attempted to inject unknown command: " << command; + } +}