The code above got a bit messy in terms of formatting, so here it is again.
void Commands::commandLoop() {
TriggerState = digitalRead(28);
delay (5);
// while(true) {
#ifdef DEBUG_PRINT
debugWaitLoop = 1;
#endif
Printer::breakLongCommand = false; // block is now finished
if (!Printer::isBlockingReceive()) {
#if SDSUPPORT
if (sd.sdmode == 20) {
if (PrintLine::linesCount == 0) {
sd.pausePrintPart2();
}
}
if (sd.sdmode == 21) {
if (PrintLine::linesCount == 0) {
sd.stopPrintPart2();
}
}
#endif
GCode::readFromSerial();
GCode* code = GCode::peekCurrentCommand();
// UI_SLOW; // do longer timed user interface action
UI_MEDIUM; // do check encoder
if (code) {
#if SDSUPPORT
if (sd.savetosd) {
if (!(code->hasM() && code->M == 29)) // still writing to file
sd.writeCommand(code);
else
sd.finishWrite();
#if ECHO_ON_EXECUTE
code->echoCommand();
#endif
} else
#endif
if (TriggerState = !lastTriggerState) {
Commands::executeGCode(code);
code->popCurrentCommand();
lastCommandReceived = HAL::timeInMilliseconds();
lastTriggerState = TriggerState;
}
} else {
if (PrintLine::hasLines()) { // if printing no need to reset
lastCommandReceived = HAL::timeInMilliseconds();
}
if (HAL::timeInMilliseconds() - lastCommandReceived > 2000) {
lastCommandReceived = HAL::timeInMilliseconds();
Printer::parkSafety(false); // will handle allowed conditions it self
}
}
}
else {
GCode::keepAlive(Paused); //Warum paused?, weil erste if Bedingung nur true ist, wenn keine user interaktionen stattfinden
UI_MEDIUM;
}
Printer::defaultLoopActions();
//}
}