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 @@ -22,6 +22,8 @@ */ #include #include +#include +#include #include "printthread.h" @@ -40,6 +42,16 @@ QString cline; //!<@param cline: current line AtCore::STATES state = AtCore::IDLE;//!<@param state: printer state QFile *file = nullptr; //!<@param file: gcode File to stream from + QList options = { + {QCommandLineOption(QStringLiteral("pause"))}, + {QCommandLineOption(QStringLiteral("extruder temperature"))}, + {QCommandLineOption(QStringLiteral("bed temperature"))}, + {QCommandLineOption(QStringLiteral("print speed"))}, + {QCommandLineOption(QStringLiteral("fan speed"))}, + {QCommandLineOption(QStringLiteral("flow rate"))}, + {QCommandLineOption(QStringLiteral("message"))}, + {QCommandLineOption(QStringLiteral("command"))} + }; //!<@param options: injectable commands. }; PrintThread::PrintThread(AtCore *parent, QString fileName) : d(new PrintThreadPrivate) @@ -80,7 +92,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 +108,9 @@ } case AtCore::PAUSE: + if (d->cline.startsWith(QStringLiteral(";-"))) { + nextLine(); + } break; default: @@ -126,6 +141,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 +168,44 @@ connect(d->core, &AtCore::stateChanged, this, &PrintThread::setState, Qt::QueuedConnection); } } + +void PrintThread::injectCommand(QString command) +{ + //remove the ; + command.remove(0, 1); + command.prepend(QStringLiteral("0:")); + QStringList cmd = command.split(QLatin1Char(':')); + cmd.replace(1, cmd.at(1).simplified().toLower()); + cmd.replace(2, cmd.at(2).simplified()); + + QCommandLineParser parser; + parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); + parser.addOptions(d->options); + + qCDebug(PRINT_THREAD) << "attempting to inject " << cmd; + parser.process(cmd); + + if (parser.isSet(QStringLiteral("pause"))) { + d->core->pause(parser.positionalArguments().at(0)); + } else if (parser.isSet(QStringLiteral("extruder temperature"))) { + QStringList args = parser.positionalArguments().at(0).split(QLatin1Char(',')); + bool wait = QString::compare(args.at(2).simplified(), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setExtruderTemp(args.at(0).toInt(), args.at(1).toInt(), wait); + } else if (parser.isSet(QStringLiteral("bed temperature"))) { + QStringList args = parser.positionalArguments().at(0).split(QLatin1Char(',')); + bool wait = QString::compare(args.at(1).simplified(), QStringLiteral("true"), Qt::CaseInsensitive) == 0; + d->core->setBedTemp(args.at(0).toInt(), wait); + } else if (parser.isSet(QStringLiteral("print speed"))) { + d->core->setPrinterSpeed(parser.positionalArguments().at(0).toInt()); + } else if (parser.isSet(QStringLiteral("fan speed"))) { + d->core->setFanSpeed(parser.positionalArguments().at(0).toInt(), parser.positionalArguments().at(1).toInt()); + } else if (parser.isSet(QStringLiteral("flow rate"))) { + d->core->setFlowRate(parser.positionalArguments().at(0).toInt()); + } else if (parser.isSet(QStringLiteral("message"))) { + d->core->showMessage(parser.positionalArguments().at(0)); + } else if (parser.isSet(QStringLiteral("command"))) { + d->core->pushCommand(parser.positionalArguments().at(0)); + } else { + qCDebug(PRINT_THREAD) << "Attempted to inject unknown command: " << parser.positionalArguments(); + } +}