Changeset View
Standalone View
src/printthread.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 69 | { | |||
---|---|---|---|---|---|
75 | case AtCore::STARTPRINT: | 75 | case AtCore::STARTPRINT: | ||
76 | case AtCore::IDLE: | 76 | case AtCore::IDLE: | ||
77 | case AtCore::BUSY: | 77 | case AtCore::BUSY: | ||
78 | setState(AtCore::BUSY); | 78 | setState(AtCore::BUSY); | ||
79 | nextLine(); | 79 | nextLine(); | ||
80 | while (d->cline.isEmpty() && !d->gcodestream->atEnd()) { | 80 | while (d->cline.isEmpty() && !d->gcodestream->atEnd()) { | ||
81 | nextLine(); | 81 | nextLine(); | ||
82 | } | 82 | } | ||
83 | if (!d->cline.isEmpty()) { | 83 | if (!d->cline.isEmpty() && d->core->state() != AtCore::PAUSE) { | ||
84 | qCDebug(PRINT_THREAD) << "cline:" << d->cline; | 84 | qCDebug(PRINT_THREAD) << "cline:" << d->cline; | ||
85 | emit nextCommand(d->cline); | 85 | emit nextCommand(d->cline); | ||
86 | } | 86 | } | ||
87 | break; | 87 | break; | ||
88 | 88 | | |||
89 | case AtCore::ERRORSTATE: | 89 | case AtCore::ERRORSTATE: | ||
90 | qCDebug(PRINT_THREAD) << "Error State"; | 90 | qCDebug(PRINT_THREAD) << "Error State"; | ||
91 | break; | 91 | break; | ||
92 | 92 | | |||
93 | case AtCore::STOP: { | 93 | case AtCore::STOP: { | ||
94 | endPrint(); | 94 | endPrint(); | ||
95 | break; | 95 | break; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | case AtCore::PAUSE: | 98 | case AtCore::PAUSE: | ||
99 | if (d->cline.startsWith(QStringLiteral(";-"))) { | ||||
laysrodrigues: This shouldn't be the same as the one below? | |||||
100 | nextLine(); | ||||
101 | } | ||||
99 | break; | 102 | break; | ||
This line will not occur, because of: 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(); The resize will happen after the injectCommand, the result will be a empty line. Please, correct me if I'm wrong. patrickelectric: This line will not occur, because of:
```
if (d->cline.contains(QChar::fromLatin1(';'))) {… | |||||
this only ensures that if we are paused (not busy then changed to pause by injected command thats all the ther check is for) we still can process ;- lines. rizzitello: this only ensures that if we are paused (not busy then changed to pause by injected command… | |||||
100 | 103 | | |||
101 | default: | 104 | default: | ||
102 | qCDebug(PRINT_THREAD) << "Unknown State"; | 105 | qCDebug(PRINT_THREAD) << "Unknown State"; | ||
103 | break; | 106 | break; | ||
104 | } | 107 | } | ||
105 | } | 108 | } | ||
106 | 109 | | |||
107 | void PrintThread::endPrint() | 110 | void PrintThread::endPrint() | ||
Show All 12 Lines | |||||
120 | void PrintThread::nextLine() | 123 | void PrintThread::nextLine() | ||
121 | { | 124 | { | ||
122 | d->cline = d->gcodestream->readLine(); | 125 | d->cline = d->gcodestream->readLine(); | ||
123 | qCDebug(PRINT_THREAD) << "Nextline:" << d->cline; | 126 | qCDebug(PRINT_THREAD) << "Nextline:" << d->cline; | ||
124 | d->stillSize -= d->cline.size() + 1; //remove read chars | 127 | d->stillSize -= d->cline.size() + 1; //remove read chars | ||
125 | d->printProgress = float(d->totalSize - d->stillSize) * 100.0 / float(d->totalSize); | 128 | d->printProgress = float(d->totalSize - d->stillSize) * 100.0 / float(d->totalSize); | ||
126 | qCDebug(PRINT_THREAD) << "progress:" << QString::number(d->printProgress); | 129 | qCDebug(PRINT_THREAD) << "progress:" << QString::number(d->printProgress); | ||
127 | emit(printProgressChanged(d->printProgress)); | 130 | emit(printProgressChanged(d->printProgress)); | ||
131 | | ||||
132 | if (d->cline.startsWith(QStringLiteral(";-"))) { | ||||
133 | injectCommand(d->cline); | ||||
134 | d->cline = QStringLiteral(""); | ||||
135 | return; | ||||
136 | } | ||||
137 | | ||||
128 | if (d->cline.contains(QChar::fromLatin1(';'))) { | 138 | if (d->cline.contains(QChar::fromLatin1(';'))) { | ||
why not if (d->cline.startsWith(QStringLiteral(";-"))) { in the first if ? patrickelectric: why not `if (d->cline.startsWith(QStringLiteral(";-"))) {` in the first if ? | |||||
All comments in gcode start with ; so those need to be handled and that case will be much more common. many slicers like have post command comments
rizzitello: All comments in gcode start with ; so those need to be handled and that case will be much more… | |||||
patrickelectric: The first one should be startswith | |||||
Every line that contains ; needs to be resized to remove comments many slicerswill do things like G28 ; home all so it make the contains if get hit alot more so i put it first then the other inside as it makes it more readable and the most common case is first.. The other way would be. if (d->cline.startsWith(QStringLiteral(";-"))) { injectCommand(d-cline); } if (d->cline.contains(QChar::fromLatin1(';'))) { d->cline.resize(d->cline.indexOf(QChar::fromLatin1(';'))); } rizzitello: Every line that contains ; needs to be resized to remove comments many slicerswill do things… | |||||
129 | d->cline.resize(d->cline.indexOf(QChar::fromLatin1(';'))); | 139 | d->cline.resize(d->cline.indexOf(QChar::fromLatin1(';'))); | ||
130 | } | 140 | } | ||
131 | d->cline = d->cline.simplified(); | 141 | d->cline = d->cline.simplified(); | ||
132 | } | 142 | } | ||
133 | 143 | | |||
134 | void PrintThread::setState(const AtCore::STATES &newState) | 144 | void PrintThread::setState(const AtCore::STATES &newState) | ||
135 | { | 145 | { | ||
136 | if (d->state == AtCore::STATES::DISCONNECTED && | 146 | if (d->state == AtCore::STATES::DISCONNECTED && | ||
137 | ( | 147 | ( | ||
138 | newState == AtCore::STATES::PAUSE || | 148 | newState == AtCore::STATES::PAUSE || | ||
139 | newState == AtCore::STATES::STOP | 149 | newState == AtCore::STATES::STOP | ||
140 | ) | 150 | ) | ||
141 | ) { | 151 | ) { | ||
142 | qCDebug(PRINT_THREAD) << "Serial not connected !"; | 152 | qCDebug(PRINT_THREAD) << "Serial not connected !"; | ||
143 | return; | 153 | return; | ||
144 | } | 154 | } | ||
145 | if (newState != d->state) { | 155 | if (newState != d->state) { | ||
146 | qCDebug(PRINT_THREAD) << "State Changed from [" << d->state << "] to [" << newState << ']'; | 156 | qCDebug(PRINT_THREAD) << "State Changed from [" << d->state << "] to [" << newState << ']'; | ||
147 | disconnect(d->core, &AtCore::stateChanged, this, &PrintThread::setState); | 157 | disconnect(d->core, &AtCore::stateChanged, this, &PrintThread::setState); | ||
148 | d->state = newState; | 158 | d->state = newState; | ||
149 | emit(stateChanged(d->state)); | 159 | emit(stateChanged(d->state)); | ||
150 | connect(d->core, &AtCore::stateChanged, this, &PrintThread::setState, Qt::QueuedConnection); | 160 | connect(d->core, &AtCore::stateChanged, this, &PrintThread::setState, Qt::QueuedConnection); | ||
151 | } | 161 | } | ||
152 | } | 162 | } | ||
163 | | ||||
164 | void PrintThread::injectCommand(QString &command) | ||||
patrickelectric: can be QString& ? | |||||
No because we do not want to change the sent command as its used in elsewhere as a full line rizzitello: No because we do not want to change the sent command as its used in elsewhere as a full line | |||||
165 | { | ||||
166 | //remove ;- | ||||
167 | command.remove(0, 2); | ||||
168 | command = command.simplified(); | ||||
patrickelectric: Qstring.simplify | |||||
169 | QStringList cmd = command.split(QLatin1Char(':')); | ||||
170 | cmd.replace(1, cmd.at(1).simplified()); | ||||
171 | | ||||
172 | qCDebug(PRINT_THREAD) << "attempting to inject " << command; | ||||
173 | | ||||
174 | if (cmd.at(0).startsWith(QStringLiteral("Pause"), Qt::CaseInsensitive)) { | ||||
175 | d->core->pause(cmd.at(1)); | ||||
patrickelectric: Why remove ? | |||||
If a command set the printer to pause state, it'll not be possible to inject more codes ? Right ? patrickelectric: If a command set the printer to pause state, it'll not be possible to inject more codes ? Right… | |||||
rizzitello: injected commands will be injected while the print job is paused. | |||||
How is that possible ? Because the state will be pause and print thread will stop. patrickelectric: How is that possible ? Because the state will be pause and print thread will stop. | |||||
Because it has been designed in such a way. If we are reading a gcode file (i.e printing) if we hit a line that starts with ;- we read it and send it to injectCommand this will push the command out to the printer. I have added in our pause state a check for ;- and if seen it will call nextLine() and send the injectedCommand to the printer. The print job is paused but the injectedCommands are still pushed. this lets you move the head out of the way and then do heat so you can change the filiment without resuming first or sending heat before pause. This also give the user more freedom to put the injected commands before or after an injected pause. Due to how this is made there is no much of a chance of the user triggering this by accident. Pressing pause on the gui will pause the job the only thing that changes is if they press pause on a line starting with ;- that will be send to the buffer while paused... rizzitello: Because it has been designed in such a way.
If we are reading a gcode file (i.e printing) if… | |||||
176 | } else if (cmd.at(0).startsWith(QStringLiteral("Extruder Temperature"), Qt::CaseInsensitive)) { | ||||
You should create a função do decode all this functions, the BCS is to create a class to handle this part of decode, validation, documentation, code functions and etc. patrickelectric: You should create a função do decode all this functions, the BCS is to create a class to handle… | |||||
This is the function to decode all the functions.. they are documented in the code for this function. rizzitello: This is the function to decode all the functions.. they are documented in the code for this… | |||||
rizzitello: Documented in the header for this function. | |||||
177 | QStringList arg = cmd.at(1).split(QStringLiteral(",")); | ||||
patrickelectric: We should support gcode in cases that the function is gcode available | |||||
178 | bool wait = !QString::compare(arg.at(2).simplified(), QStringLiteral("true"), Qt::CaseInsensitive); | ||||
179 | d->core->setExtruderTemp(arg.at(0).toInt(), arg.at(1).toInt(), wait); | ||||
180 | } else if (cmd.at(0).startsWith(QStringLiteral("Bed Temperature:"), Qt::CaseInsensitive)) { | ||||
181 | QStringList arg = cmd.at(1).split(QStringLiteral(",")); | ||||
182 | bool wait = !QString::compare(arg.at(1).simplified(), QStringLiteral("true"), Qt::CaseInsensitive); | ||||
183 | d->core->setBedTemp(arg.at(0).toInt(), wait); | ||||
184 | } else if (cmd.at(0).startsWith(QStringLiteral("Print Speed"), Qt::CaseInsensitive)) { | ||||
185 | d->core->setPrinterSpeed(cmd.at(1).toInt()); | ||||
186 | } else if (cmd.at(0).startsWith(QStringLiteral("Flow Rate"), Qt::CaseInsensitive)) { | ||||
187 | d->core->setFlowRate(cmd.at(1).toInt()); | ||||
188 | } else if (cmd.at(0).startsWith(QStringLiteral("Fan Speed"), Qt::CaseInsensitive)) { | ||||
189 | QStringList arg = cmd.at(1).split(QStringLiteral(",")); | ||||
190 | d->core->setFanSpeed(arg.at(0).toInt(), arg.at(1).toInt()); | ||||
191 | } else if (cmd.at(0).startsWith(QStringLiteral("Message"), Qt::CaseInsensitive)) { | ||||
192 | d->core->showMessage(cmd.at(1)); | ||||
193 | } else if (cmd.at(0).startsWith(QStringLiteral("Command"), Qt::CaseInsensitive)) { | ||||
194 | d->core->pushCommand(cmd.at(1).simplified()); | ||||
195 | } else { | ||||
196 | qCDebug(PRINT_THREAD) << "Attempted to inject unknown command: " << command; | ||||
197 | } | ||||
198 | } |
This shouldn't be the same as the one below?