Skip to content

Commit

Permalink
Print abort improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Jun 3, 2023
1 parent 0384c77 commit 7f9bc7d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 44 deletions.
50 changes: 18 additions & 32 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,13 @@ void resumeAndContinue(void)
sendEmergencyCmd("M876 S1\n");
}

void abortAndTerminate(void)
static void sendPrintAbortCmd(void)
{
clearQueueAndMore();

if (infoMachineSettings.firmwareType != FW_REPRAPFW)
{
// clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message.
// Otherwise, store the gcode on command queue to send it waiting for its related ACK message
//
if (isPendingCmd())
sendEmergencyCmd("M524\n");
else
mustStoreCmd("M524\n");
sendEmergencyCmd("M524\n");
}
else // if RepRap
{
Expand All @@ -98,14 +92,23 @@ void abortAndTerminate(void)
}
}

void loopBreakToCondition(CONDITION_CALLBACK condCallback)
void clearPendingGcodesAndAbortPrint(void)
{
if (infoFile.source == FS_REMOTE_HOST)
// - forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print
// - the host handling the print should respond to this notification with "M118 P0 A1 action:cancel" that will
// trigger setPrintAbort() in parseACK() once the following loop does its job (stopping all blocking operations)
mustStoreCmd("M118 P0 A1 action:notification remote cancel\n");
else
// triggers setPrintAbort() in parseACK() once the following loop does its job (stopping all blocking operations)
mustStoreCmd("M118 P0 A1 action:cancel\n");

// M108 is sent to Marlin because consecutive blocking operations such as heating bed, extruder may defer processing of other gcodes.
// If there's any ongoing blocking command, "M108" will take that out from the closed loop and a response will be received
// from that command. Than another "M108" will be sent to unlock a next possible blocking command.
// This way enough "M108" will be sent to unlock all possible blocking command(s) (ongoing or enqueued) but not too much and
// not too fast one after another to overload/overrun the serial communication
TASK_LOOP_WHILE(condCallback(), if (infoHost.rx_ok[SERIAL_PORT] == true) sendEmergencyCmd("M108\n"))
// not too fast one after another to overload/overrun the serial communication.
TASK_LOOP_WHILE(isPrinting(), if (infoHost.rx_ok[SERIAL_PORT] == true) sendEmergencyCmd("M108\n"))

// remove any enqueued command that could come from a supplementary serial port or TFT media
// (if printing from remote host or TFT media) during the loop above
Expand Down Expand Up @@ -567,36 +570,19 @@ void abortPrint(void)
{
case FS_TFT_SD:
case FS_TFT_USB:
loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any
setPrintAbort(); // finalize the print abort
clearPendingGcodesAndAbortPrint();
break;

case FS_ONBOARD_MEDIA:
case FS_ONBOARD_MEDIA_REMOTE:
popupSplash(DIALOG_TYPE_INFO, LABEL_SCREEN_INFO, LABEL_BUSY);
loopPopup(); // trigger the immediate draw of the above popup

// clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message.
// Otherwise, store the gcode on command queue to send it waiting for its related ACK message.
// Furthermore, forward the print cancel action to all hosts (also TFT) to notify the print cancelation
//
// NOTE: the print cancel action received by the TFT always guarantees the invokation of setPrintAbort() in parseAck.c
// to finalize the print (e.g. stats) in case the ACK messages "Not SD printing" and/or "//action:cancel"
// are not received from Marlin
//
abortAndTerminate();
mustStoreCmd("M118 P0 A1 action:cancel\n");

// loop on break until infoHost.status is set to "HOST_STATUS_IDLE" by setPrintAbort() in parseAck.c
loopBreakToCondition(&isPrintingFromOnboard);
sendPrintAbortCmd();
clearPendingGcodesAndAbortPrint();
break;

case FS_REMOTE_HOST:
loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any

// forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print
mustStoreCmd("M118 P0 A1 action:notification remote cancel\n");

clearPendingGcodesAndAbortPrint();
loopDetected = false; // finally, remove lock and exit
return;
}
Expand Down
6 changes: 0 additions & 6 deletions TFT/src/User/API/Printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ void breakAndContinue(void);
void resumeAndPurge(void);
void resumeAndContinue(void);

//
// commented because NOT externally invoked
//
//void abortAndTerminate(void);
//void loopBreakToCondition(CONDITION_CALLBACK condCallback);

void setPrintExpectedTime(uint32_t expectedTime);
uint32_t getPrintExpectedTime(void);

Expand Down
5 changes: 0 additions & 5 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ uint8_t cmd_index;
WRITING_MODE writing_mode = NO_WRITING;
FIL file;

bool isPendingCmd(void)
{
return infoHost.wait;
}

bool isFullCmdQueue(void)
{
return (cmdQueue.count >= CMD_QUEUE_SIZE);
Expand Down
1 change: 0 additions & 1 deletion TFT/src/User/API/interfaceCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern "C" {

typedef char CMD[CMD_MAX_SIZE];

bool isPendingCmd(void); // also usable as condition callback for loopProcessToCondition()
bool isFullCmdQueue(void); // also usable as condition callback for loopProcessToCondition()
bool isNotEmptyCmdQueue(void); // also usable as condition callback for loopProcessToCondition()
bool isEnqueued(const CMD cmd);
Expand Down

0 comments on commit 7f9bc7d

Please sign in to comment.