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 8473fab289..a65a818709 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 f7e573edc7..02d2777ff9 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -609,10 +609,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 22562d776f..3ce681c625 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -166,10 +166,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; @@ -239,10 +236,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; diff --git a/TFT/src/User/Menu/Extrude.c b/TFT/src/User/Menu/Extrude.c index 138c732f53..5707f779ce 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 16c3fcfdae..65358e5648 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"); infoParameters.StepsPerMM[E_AXIS] = 0; // reset E-steps value - while (infoParameters.StepsPerMM[E_AXIS] == 0) // 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 9128153d5a..ef315e5921 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 strxcpy(), strwcpy() or strscpy().\""); \ } 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);