From 11f1c10c3551a120095d4422cba57ce6addc5152 Mon Sep 17 00:00:00 2001 From: kisslorand Date: Sun, 28 Aug 2022 01:33:42 +0300 Subject: [PATCH] loopProcessToCondition() removal --- TFT/src/User/API/Gcode/gcode.c | 32 ++++++++++++-------------------- TFT/src/User/API/Gcode/gcode.h | 1 - TFT/src/User/API/Printing.c | 6 ++++-- TFT/src/User/API/interfaceCmd.c | 6 +++--- TFT/src/User/API/interfaceCmd.h | 6 +++--- TFT/src/User/API/menu.c | 20 -------------------- TFT/src/User/API/menu.h | 1 - TFT/src/User/Menu/Extrude.c | 2 +- TFT/src/User/Menu/LoadUnload.c | 2 +- TFT/src/User/Menu/Popup.c | 10 ++++++++-- TFT/src/User/my_misc.h | 10 +++++----- 11 files changed, 37 insertions(+), 59 deletions(-) diff --git a/TFT/src/User/API/Gcode/gcode.c b/TFT/src/User/API/Gcode/gcode.c index e20c742a55..1aedd75095 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; @@ -77,9 +77,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 @@ -99,9 +97,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; } @@ -125,9 +121,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; } @@ -177,9 +171,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(); @@ -265,7 +257,7 @@ void request_M98(const char * filename) rrfStatusQueryFast(); // Wait for macro to complete - loopProcessToCondition(&rrfStatusIsBusy); + TASK_LOOP_WHILE(rrfStatusIsBusy()) rrfStatusQueryNormal(); } @@ -278,5 +270,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 5c9a27d1ef..ead9e49b02 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 0a33247bc2..b0e84c924c 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -84,7 +84,7 @@ void abortAndTerminate(void) // 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()) + if (infoHost.wait) sendEmergencyCmd("M524\n"); else mustStoreCmd("M524\n"); @@ -625,7 +625,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 9810d51210..737c20ffd4 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -108,7 +108,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; @@ -178,7 +178,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; @@ -537,7 +537,7 @@ void handleCmd(CMD cmd, const SERIAL_PORT_INDEX portIndex) // If not an empty gcode, we can loop on the following storeCmdFromUART() function to store the gcode on cmdQueue if (cmd[0] != '\0') - TASK_LOOP_WHILE(!storeCmdFromUART(cmd, portIndex)) + TASK_LOOP_WHILE(!storeCmdFromUART(cmd, portIndex)); } diff --git a/TFT/src/User/API/interfaceCmd.h b/TFT/src/User/API/interfaceCmd.h index 31ce525422..6bc441b054 100644 --- a/TFT/src/User/API/interfaceCmd.h +++ b/TFT/src/User/API/interfaceCmd.h @@ -18,9 +18,9 @@ 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 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 253a8dd06b..11684a42d0 100644 --- a/TFT/src/User/API/menu.c +++ b/TFT/src/User/API/menu.c @@ -1323,23 +1323,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 d27df4c1f7..aa5ec218c9 100644 --- a/TFT/src/User/API/menu.h +++ b/TFT/src/User/API/menu.h @@ -215,7 +215,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 978df8454c..e88b67bc0b 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 2ef8a2b2d2..5e17b16ca7 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);