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 Mar 23, 2023
1 parent 0063461 commit c72bd01
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 44 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 @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ void mustStoreCmd(const char * format, ...)
if (cmdQueue.count >= CMD_QUEUE_SIZE)
{
reminderMessage(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 @@ -239,10 +236,7 @@ void mustStoreCacheCmd(const char * format, ...)
if (cmdCache.count >= CMD_QUEUE_SIZE)
{
reminderMessage(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
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");
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");
Expand Down
7 changes: 7 additions & 0 deletions TFT/src/User/my_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ extern "C" {

#define strtod stringToDouble // enable light weight string to double function without exponential support

#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 c72bd01

Please sign in to comment.