Skip to content

Commit

Permalink
loopProcessToCondition() removal
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Jun 5, 2023
1 parent 8a08dce commit 578a0f2
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 59 deletions.
32 changes: 12 additions & 20 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

REQUEST_COMMAND_INFO requestCommandInfo = {0};

bool isWaitingResponse(void)
{
return (!requestCommandInfo.done);
}

bool requestCommandInfoIsRunning(void)
{
return (requestCommandInfo.inWaitResponse || requestCommandInfo.inResponse);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -265,7 +257,7 @@ void request_M98(const char * filename)
rrfStatusQueryFast();

// Wait for macro to complete
loopProcessToCondition(&rrfStatusIsBusy);
TASK_LOOP_WHILE(rrfStatusIsBusy())

rrfStatusQueryNormal();
}
Expand All @@ -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();
}
1 change: 0 additions & 1 deletion TFT/src/User/API/Gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ typedef struct

extern REQUEST_COMMAND_INFO requestCommandInfo;

bool isWaitingResponse(void); // condition callback for loopProcessToCondition()
bool requestCommandInfoIsRunning(void);
void clearRequestCommandInfo(void);

Expand Down
6 changes: 4 additions & 2 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

}

Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/API/interfaceCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 0 additions & 20 deletions TFT/src/User/API/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion TFT/src/User/API/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ void menuDummy(void);
void loopBackEnd(void);
void loopFrontEnd(void);
void loopProcess(void);
void loopProcessToCondition(CONDITION_CALLBACK condCallback);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Menu/Extrude.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Menu/LoadUnload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions TFT/src/User/Menu/Popup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
10 changes: 5 additions & 5 deletions TFT/src/User/my_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 578a0f2

Please sign in to comment.