Skip to content

Commit

Permalink
Stage 2 - Back to "elegant"
Browse files Browse the repository at this point in the history
Stage 2 - back to "elegant"
  • Loading branch information
kisslorand committed Apr 17, 2023
1 parent fe23558 commit 7b39b4f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 50 deletions.
21 changes: 5 additions & 16 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ void clearRequestCommandInfo(void)

static void waitForResponse(void)
{
while (!requestCommandInfo.done)
{
loopProcess();
}
CONDITIONED_STANDBY(!requestCommandInfo.done)
}

static void resetRequestCommandInfo(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 1 addition & 4 deletions TFT/src/User/API/ModeSwitching.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 4 additions & 14 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions TFT/src/User/Menu/Extrude.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions TFT/src/User/Menu/LoadUnload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions TFT/src/User/Menu/TuneExtruder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions TFT/src/User/my_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7b39b4f

Please sign in to comment.