diff --git a/TFT/src/User/API/Gcode/gcode.c b/TFT/src/User/API/Gcode/gcode.c index 6694d5cc8f..21bc4a7057 100644 --- a/TFT/src/User/API/Gcode/gcode.c +++ b/TFT/src/User/API/Gcode/gcode.c @@ -3,11 +3,6 @@ REQUEST_COMMAND_INFO requestCommandInfo = {0}; -bool isWaitingResponse(void) -{ - return (!requestCommandInfo.done); -} - bool requestCommandInfoIsRunning(void) { return (requestCommandInfo.inWaitResponse || requestCommandInfo.inResponse); @@ -22,6 +17,11 @@ void clearRequestCommandInfo(void) } } +static void waitForResponse(void) +{ + TASK_LOOP_WHILE(!requestCommandInfo.done) +} + static void resetRequestCommandInfo( const char * string_start, // The magic to identify the start const char * string_stop, // The magic to identify the stop @@ -51,7 +51,7 @@ static void resetRequestCommandInfo( if (string_error2) requestCommandInfo.error_num = 3; - loopProcessToCondition(&isNotEmptyCmdQueue); // wait for the communication to be clean before requestCommand + TASK_LOOP_WHILE(isNotEmptyCmdQueue()) // wait for the communication to be clean requestCommandInfo.stream_handler = NULL; requestCommandInfo.inWaitResponse = true; @@ -81,7 +81,7 @@ void detectAdvancedOk(void) mustStoreCmd("M220\n"); // Wait for response - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); while (requestCommandInfo.cmd_rev_buf[cmd_index] != '\0') { @@ -117,9 +117,7 @@ bool request_M21(void) mustStoreCmd((infoMachineSettings.multiVolume == ENABLED) ? ((infoFile.onboardSource == BOARD_SD) ? "M21 S\n" : "M21 U\n") : "M21\n"); - // Wait for response - loopProcessToCondition(&isWaitingResponse); - + waitForResponse(); clearRequestCommandInfo(); // Check reponse @@ -139,9 +137,7 @@ char * request_M20(void) else mustStoreCmd("M20\n"); - // Wait for response - loopProcessToCondition(&isWaitingResponse); - + waitForResponse(); //clearRequestCommandInfo(); // shall be call after copying the buffer ... return requestCommandInfo.cmd_rev_buf; } @@ -165,9 +161,7 @@ char * request_M33(const char * filename) else mustStoreCmd("M33 %s\n", filename); - // Wait for response - loopProcessToCondition(&isWaitingResponse); - + waitForResponse(); //clearRequestCommandInfo(); // shall be call after copying the buffer return requestCommandInfo.cmd_rev_buf; } @@ -217,9 +211,7 @@ long request_M23_M36(const char * filename) sizeTag = "size\":"; // reprap firmware reports size JSON } - // Wait for response - loopProcessToCondition(&isWaitingResponse); - + waitForResponse(); if (requestCommandInfo.inError) { clearRequestCommandInfo(); @@ -305,7 +297,7 @@ void request_M98(const char * filename) rrfStatusQueryFast(); // Wait for macro to complete - loopProcessToCondition(&rrfStatusIsBusy); + TASK_LOOP_WHILE(rrfStatusIsBusy()) rrfStatusQueryNormal(); } @@ -318,5 +310,5 @@ void request_M20_rrf(const char * nextdir, bool with_ts, FP_STREAM_HANDLER handl mustStoreCmd("M20 S%d P\"/%s\"\n", with_ts ? 3 : 2, nextdir); - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); } diff --git a/TFT/src/User/API/Gcode/gcode.h b/TFT/src/User/API/Gcode/gcode.h index 14ff436895..10d5955e9a 100644 --- a/TFT/src/User/API/Gcode/gcode.h +++ b/TFT/src/User/API/Gcode/gcode.h @@ -32,7 +32,6 @@ typedef struct extern REQUEST_COMMAND_INFO requestCommandInfo; -bool isWaitingResponse(void); // condition callback for loopProcessToCondition() bool requestCommandInfoIsRunning(void); void clearRequestCommandInfo(void); diff --git a/TFT/src/User/API/Printing.c b/TFT/src/User/API/Printing.c index e7506ec2f7..8dbf16e6d7 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -81,13 +81,7 @@ void abortAndTerminate(void) 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 { @@ -632,7 +626,9 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType) case FS_TFT_SD: case FS_TFT_USB: if (isPause == true && pauseType == PAUSE_M0) - loopProcessToCondition(&isNotEmptyCmdQueue); // wait for the communication to be clean + { + TASK_LOOP_WHILE(isNotEmptyCmdQueue()) // wait for the communication to be clean + } static COORDINATE tmp; bool isCoorRelative = coorGetRelative(); diff --git a/TFT/src/User/API/interfaceCmd.c b/TFT/src/User/API/interfaceCmd.c index 8173857671..a525252158 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -113,7 +113,7 @@ void mustStoreCmd(const char * format, ...) if (cmdQueue.count >= CMD_QUEUE_SIZE) { setReminderMsg(LABEL_BUSY, SYS_STATUS_BUSY); - loopProcessToCondition(&isFullCmdQueue); // wait for a free slot in the queue in case the queue is currently full + TASK_LOOP_WHILE(cmdQueue.count >= CMD_QUEUE_SIZE); // wait for a free slot in the command queue in case it is currently full } va_list va; @@ -183,7 +183,7 @@ void mustStoreCacheCmd(const char * format, ...) if (cmdCache.count >= CMD_QUEUE_SIZE) { setReminderMsg(LABEL_BUSY, SYS_STATUS_BUSY); - loopProcessToCondition(&isFullCmdQueue); // wait for a free slot in the queue in case the queue is currently full + TASK_LOOP_WHILE(cmdCache.count >= CMD_QUEUE_SIZE); // wait for a free slot in the cache queue in case it is currently full } va_list va; diff --git a/TFT/src/User/API/interfaceCmd.h b/TFT/src/User/API/interfaceCmd.h index d905e32f5f..76d3f5b96e 100644 --- a/TFT/src/User/API/interfaceCmd.h +++ b/TFT/src/User/API/interfaceCmd.h @@ -22,9 +22,9 @@ typedef char CMD[CMD_MAX_SIZE]; // if DEBUG_MONITORING is enabled in Configuration.h uint8_t getQueueCount(void); -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 isPendingCmd(void); +bool isFullCmdQueue(void); +bool isNotEmptyCmdQueue(void); bool isEnqueued(const CMD cmd); bool isWritingMode(void); diff --git a/TFT/src/User/API/menu.c b/TFT/src/User/API/menu.c index acfdadf89b..64fdbbb2f1 100644 --- a/TFT/src/User/API/menu.c +++ b/TFT/src/User/API/menu.c @@ -1330,23 +1330,3 @@ void menuDummy(void) { CLOSE_MENU(); } - -void loopProcessToCondition(CONDITION_CALLBACK condCallback) -{ - uint8_t curMenu = infoMenu.cur; - bool invokedUI = false; - - while (condCallback()) // loop until the condition is no more satisfied - { - loopProcess(); - - if (infoMenu.cur > curMenu) // if a user interaction is needed (e.g. dialog box UI), handle it - { - invokedUI = true; - (*infoMenu.menu[infoMenu.cur])(); - } - } - - if (invokedUI) // if a UI was invoked, load a dummy menu just to force the caller also to refresh its menu - OPEN_MENU(menuDummy); -} diff --git a/TFT/src/User/API/menu.h b/TFT/src/User/API/menu.h index cb344b78ca..91f70fb666 100644 --- a/TFT/src/User/API/menu.h +++ b/TFT/src/User/API/menu.h @@ -216,7 +216,6 @@ void menuDummy(void); void loopBackEnd(void); void loopFrontEnd(void); void loopProcess(void); -void loopProcessToCondition(CONDITION_CALLBACK condCallback); #ifdef __cplusplus } diff --git a/TFT/src/User/Menu/Extrude.c b/TFT/src/User/Menu/Extrude.c index 89f95c0d9a..3f8cf3d5da 100644 --- a/TFT/src/User/Menu/Extrude.c +++ b/TFT/src/User/Menu/Extrude.c @@ -40,7 +40,7 @@ void menuExtrude(void) if (eAxisBackup.handled == false) { - loopProcessToCondition(&isNotEmptyCmdQueue); // wait for the communication to be clean + TASK_LOOP_WHILE(isNotEmptyCmdQueue()) // wait for the communication to be clean eAxisBackup.coordinate = coordinateGetAxis(E_AXIS); eAxisBackup.feedrate = coordinateGetFeedRate(); diff --git a/TFT/src/User/Menu/LoadUnload.c b/TFT/src/User/Menu/LoadUnload.c index 24ce73092d..5b5ab12774 100644 --- a/TFT/src/User/Menu/LoadUnload.c +++ b/TFT/src/User/Menu/LoadUnload.c @@ -35,7 +35,7 @@ void menuLoadUnload(void) if (eAxisBackup.handled == false) { - loopProcessToCondition(&isNotEmptyCmdQueue); // wait for the communication to be clean + TASK_LOOP_WHILE(isNotEmptyCmdQueue()) // wait for the communication to be clean eAxisBackup.coordinate = coordinateGetAxis(E_AXIS); eAxisBackup.handled = true; diff --git a/TFT/src/User/Menu/Popup.c b/TFT/src/User/Menu/Popup.c index ca07b9ad17..c9dfaa1a96 100644 --- a/TFT/src/User/Menu/Popup.c +++ b/TFT/src/User/Menu/Popup.c @@ -228,7 +228,13 @@ void loopPopup(void) // avoid to nest menuDialog popup type (while a menuNotification popup type can be overridden) if (MENU_IS_NOT(menuDialog)) - { // handle the user interaction, then reload the previous menu - OPEN_MENU(menuDialog); + { // handle user interaction then prepare to reload the previous menu + if (MENU_IS(menuDummy)) + REPLACE_MENU(menuDialog); + else + OPEN_MENU(menuDialog); + + menuDialog(); // activate the popup dialog handler + OPEN_MENU(menuDummy); // trigger the redraw of the menu where the popup appeared } } diff --git a/TFT/src/User/my_misc.h b/TFT/src/User/my_misc.h index 56d3c929ef..a9e62ea19e 100644 --- a/TFT/src/User/my_misc.h +++ b/TFT/src/User/my_misc.h @@ -70,11 +70,11 @@ extern "C" { // call processes from the argument and than loopProcess() while condition is true // tasks from argument must be separated by ";" ("TASK_LOOP_WHILE(condition, task1(); task2(); ...)) #define TASK_LOOP_WHILE(condition, ...) \ - while (condition) \ - { \ - __VA_ARGS__; \ - loopProcess(); \ - } + while (condition) \ + { \ + __VA_ARGS__; \ + loopProcess(); \ + } uint8_t inRange(int cur, int tag , int range); long map(long x, long in_min, long in_max, long out_min, long out_max);