File indexing completed on 2024-05-12 04:41:10
0001 /* AtCore KDE Libary for 3D Printers 0002 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 SPDX-FileCopyrightText: 2017-2018, 2020 Chris Rizzitello <rizzitello@kde.org> 0004 SPDX-FileCopyrightText: 2018 Tomaz Canabrava <tcanabrava@kde.org> 0005 SPDX-FileCopyrightText: 2018 Leandro Santiago <leandrosansilva@gmail.com> 0006 */ 0007 0008 #pragma once 0009 0010 #include <QFile> 0011 0012 #include "atcore.h" 0013 0014 /** 0015 * @brief The PrintThread class 0016 * A Thread for running a print job 0017 * 0018 * see AtCore::print() for example of how to create a print thread. 0019 * 0020 */ 0021 class ATCORE_EXPORT PrintThread : public QObject 0022 { 0023 Q_OBJECT 0024 public: 0025 /** 0026 * @brief Create a new Print Thread 0027 * @param parent: Parent of the tread 0028 * @param fileName: gcode File to print 0029 */ 0030 PrintThread(AtCore *parent, const QString &fileName); 0031 ~PrintThread(); 0032 signals: 0033 /** 0034 * @brief Print job has finished 0035 */ 0036 void finished(); 0037 0038 /** 0039 * @brief A command has caused an error 0040 * @param err: the offending command 0041 */ 0042 void error(QString err); 0043 0044 /** 0045 * @brief The print job's progress has changed 0046 */ 0047 void printProgressChanged(const float); 0048 0049 /** 0050 * @brief the next command of the job 0051 * @param comm: Command to be sent next 0052 */ 0053 void nextCommand(const QString &comm); 0054 0055 /** 0056 * @brief Printer state was changed 0057 * @param state: new state 0058 */ 0059 void stateChanged(const AtCore::STATES &state); 0060 0061 public slots: 0062 /** 0063 * @brief start the print thread 0064 */ 0065 void start(); 0066 private slots: 0067 /** 0068 * @brief process the current job 0069 */ 0070 void processJob(); 0071 0072 /** 0073 * @brief Set printer state 0074 * @param state: the new printer state 0075 */ 0076 void setState(const AtCore::STATES &state); 0077 0078 private: 0079 /** 0080 * @brief parse the next line 0081 */ 0082 void nextLine(); 0083 0084 /** 0085 * @brief end the print 0086 */ 0087 void endPrint(); 0088 0089 /** 0090 * @brief injectCommand Attempt to inject a Command from the currently printing file. 0091 * 0092 * One of the following on a line that starts with ';-' \n 0093 * example line ;-Message: Hello \n 0094 * 0095 * - Pause: ppc\n 0096 * Pause the print job and then run the comma-separated commands after pausing the job.\n 0097 * + ppc: A comma-separated list of Commands to send after pause. ex(G91, G0 Z1, G90, G1 X0 Y195)\n 0098 *\n 0099 * - Extruder %Temperature:newTemp,extnum,wait \n 0100 * Set extruder temperature. \n 0101 * + newTemp: new target temperature. \n 0102 * + extnum: Extruder number you want to Heat. Starting at 0. \n 0103 * + wait: ignore commands until the target is reached. [true | false] \n 0104 *\n 0105 * - Bed %Temperature: newTemp,wait \n 0106 * Set the bed temperature. \n 0107 * + newTemp: new target temperature \n 0108 * + wait: ignore commands until the target is reached. [true | false] \n 0109 *\n 0110 * - Fan Speed:newSpeed, fanNum \n 0111 * Set the Fan speed. \n 0112 * + newSpeed: new fan speed. \n 0113 * + fanNum: Fan number. Starting at 0.\n 0114 *\n 0115 * - Print Speed:newSpeed \n 0116 * Set the printer speed. \n 0117 * + newSpeed: the print speed. 100= movement speed defined in file. \n 0118 *\n 0119 * - Flow Rate:newRate \n 0120 * Set the flow rate \n 0121 * + newRate: the flow rate. 100 = flow rate defined in file. \n 0122 *\n 0123 * - Message:message \n 0124 * Show a message the printer's LCD \n 0125 * + message: the message to print. \n 0126 *\n 0127 * - Command:command \n 0128 * Inject your own command. Command are sent as is. Be sure your line is correct. \n 0129 * + command: Commands to inject \n 0130 */ 0131 void injectCommand(QString &command); 0132 0133 /** 0134 * @brief d: Private storage for the thread 0135 */ 0136 class PrintThreadPrivate; 0137 PrintThreadPrivate *d; 0138 };