diff --git a/TFT/src/User/API/Gcode/gcode.c b/TFT/src/User/API/Gcode/gcode.c index 1ff0d6cc11..c5456a614c 100644 --- a/TFT/src/User/API/Gcode/gcode.c +++ b/TFT/src/User/API/Gcode/gcode.c @@ -19,10 +19,7 @@ void clearRequestCommandInfo(void) static void waitForResponse(void) { - while (!requestCommandInfo.done) - { - loopProcess(); - } + CONDITIONED_STANDBY(!requestCommandInfo.done) } static void resetRequestCommandInfo( @@ -54,10 +51,8 @@ static void resetRequestCommandInfo( if (string_error2) requestCommandInfo.error_num = 3; - while (isNotEmptyCmdQueue()) // wait for the communication to be clean - { - loopProcess(); - } + CONDITIONED_STANDBY(isNotEmptyCmdQueue()) // wait for the communication to be clean + requestCommandInfo.stream_handler = NULL; requestCommandInfo.inWaitResponse = true; requestCommandInfo.inResponse = false; @@ -257,18 +252,12 @@ void request_M98(const char * filename) mustStoreCmd(command); // prevent a race condition when rrfStatusQuery returns !busy before executing the macro - while (isEnqueued(command)) - { - loopProcess(); - } + CONDITIONED_STANDBY(isEnqueued(command)) rrfStatusQueryFast(); // Wait for macro to complete - while (rrfStatusIsBusy()) - { - loopProcess(); - } + CONDITIONED_STANDBY(rrfStatusIsBusy()) rrfStatusQueryNormal(); } diff --git a/TFT/src/User/API/ModeSwitching.c b/TFT/src/User/API/ModeSwitching.c index 02a6ef2c4e..a61f188f05 100644 --- a/TFT/src/User/API/ModeSwitching.c +++ b/TFT/src/User/API/ModeSwitching.c @@ -35,10 +35,7 @@ void Mode_Switch(void) LOGO_ReadDisplay(); updateNextHeatCheckTime(); // send "M105" after a delay, because of mega2560 will be hanged when received data at startup - while (OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME) // display logo BTT_BOOTSCREEN_TIME ms - { - loopProcess(); - } + CONDITIONED_STANDBY(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME) // display logo BTT_BOOTSCREEN_TIME ms heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS); modeFreshBoot = false; diff --git a/TFT/src/User/API/Printing.c b/TFT/src/User/API/Printing.c index 9b01d95b31..c34434b328 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -631,10 +631,7 @@ bool pausePrint(bool isPause, PAUSE_TYPE pauseType) case FS_TFT_USB: if (isPause == true && pauseType == PAUSE_M0) { - while (isNotEmptyCmdQueue()) // wait for the communication to be clean - { - loopProcess(); - } + CONDITIONED_STANDBY(isNotEmptyCmdQueue()) // wait for the communication to be clean } static COORDINATE tmp; diff --git a/TFT/src/User/API/interfaceCmd.c b/TFT/src/User/API/interfaceCmd.c index c55746aea8..aac93feb9a 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -108,10 +108,7 @@ void mustStoreCmd(const char * format, ...) if (cmdQueue.count >= CMD_QUEUE_SIZE) { setReminderMsg(LABEL_BUSY, SYS_STATUS_BUSY); - while (cmdQueue.count >= CMD_QUEUE_SIZE) // wait for a free slot in the queue in case the queue is currently full - { - loopProcess(); - } + CONDITIONED_STANDBY(cmdQueue.count >= CMD_QUEUE_SIZE) // wait for a free slot in the queue in case the queue is currently full } va_list va; @@ -181,10 +178,7 @@ void mustStoreCacheCmd(const char * format, ...) if (cmdCache.count >= CMD_QUEUE_SIZE) { setReminderMsg(LABEL_BUSY, SYS_STATUS_BUSY); - while (cmdQueue.count >= CMD_QUEUE_SIZE) // wait for a free slot in the queue in case the queue is currently full - { - loopProcess(); - } + CONDITIONED_STANDBY(cmdQueue.count >= CMD_QUEUE_SIZE) // wait for a free slot in the queue in case the queue is currently full } va_list va; @@ -545,12 +539,8 @@ 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') - { - while (!storeCmdFromUART(cmd, portIndex)) - { - loopProcess(); - } - } + CONDITIONED_STANDBY(!storeCmdFromUART(cmd, portIndex)); + } // Send emergency command now. diff --git a/TFT/src/User/Menu/Extrude.c b/TFT/src/User/Menu/Extrude.c index fc2e119a96..870ea35485 100644 --- a/TFT/src/User/Menu/Extrude.c +++ b/TFT/src/User/Menu/Extrude.c @@ -38,10 +38,8 @@ void menuExtrude(void) if (eAxisBackup.handled == false) { - while (isNotEmptyCmdQueue()) // wait for the communication to be clean - { - loopProcess(); - } + CONDITIONED_STANDBY(isNotEmptyCmdQueue()) // wait for the communication to be clean + eAxisBackup.coordinate = coordinateGetAxis(E_AXIS); eAxisBackup.feedrate = coordinateGetFeedRate(); eAxisBackup.relative = eGetRelative(); diff --git a/TFT/src/User/Menu/LoadUnload.c b/TFT/src/User/Menu/LoadUnload.c index 025b04cece..60f2132a15 100644 --- a/TFT/src/User/Menu/LoadUnload.c +++ b/TFT/src/User/Menu/LoadUnload.c @@ -35,10 +35,8 @@ void menuLoadUnload(void) if (eAxisBackup.handled == false) { - while (isNotEmptyCmdQueue()) // wait for the communication to be clean - { - loopProcess(); - } + CONDITIONED_STANDBY(isNotEmptyCmdQueue()) // wait for the communication to be clean + eAxisBackup.coordinate = coordinateGetAxis(E_AXIS); eAxisBackup.handled = true; } diff --git a/TFT/src/User/Menu/TuneExtruder.c b/TFT/src/User/Menu/TuneExtruder.c index 31eba02139..f075580da8 100644 --- a/TFT/src/User/Menu/TuneExtruder.c +++ b/TFT/src/User/Menu/TuneExtruder.c @@ -36,10 +36,7 @@ static inline void extrudeFilament(void) mustStoreCmd("M92\n"); setParameter(P_STEPS_PER_MM, E_AXIS, 0.0f); // reset E-steps value - while (getParameter(P_STEPS_PER_MM, E_AXIS) == 0.0f) // wait until E-steps is updated - { - loopProcess(); - } + CONDITIONED_STANDBY(infoParameters.StepsPerMM[E_AXIS] == 0) // wait until E-steps is updated // Home extruder and set absolute positioning mustStoreScript("G28\nG90\n"); diff --git a/TFT/src/User/my_misc.h b/TFT/src/User/my_misc.h index 2bc719c2aa..4e0044b6cf 100644 --- a/TFT/src/User/my_misc.h +++ b/TFT/src/User/my_misc.h @@ -67,6 +67,12 @@ extern "C" { _Pragma("GCC error \"Error: strncpy() is deprecated! Use the alternatives like strncpy_pad() or strncpy_no_pad()\""); \ } while (0) +#define CONDITIONED_STANDBY(condition) \ + while(condition) \ + { \ + 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);