Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal "popup freezing TFT" bug fix, loopProcessToCondition() removal #2591

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 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 Down Expand Up @@ -81,7 +81,7 @@ void detectAdvancedOk(void)
mustStoreCmd("M220\n");

// Wait for response
loopProcessToCondition(&isWaitingResponse);
waitForResponse();

while (requestCommandInfo.cmd_rev_buf[cmd_index] != '\0')
{
Expand Down Expand Up @@ -117,9 +117,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 @@ -139,9 +137,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 @@ -165,9 +161,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 @@ -217,9 +211,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 @@ -305,7 +297,7 @@ void request_M98(const char * filename)
rrfStatusQueryFast();

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

rrfStatusQueryNormal();
}
Expand All @@ -318,5 +310,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
12 changes: 4 additions & 8 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ void abortAndTerminate(void)

if (infoMachineSettings.firmwareType != FW_REPRAPFW)
{
// 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())
sendEmergencyCmd("M524\n");
else
mustStoreCmd("M524\n");
sendEmergencyCmd("M524\n");
}
else // if RepRap
{
Expand Down Expand Up @@ -632,7 +626,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
4 changes: 2 additions & 2 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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 @@ -183,7 +183,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
6 changes: 3 additions & 3 deletions TFT/src/User/API/interfaceCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ typedef char CMD[CMD_MAX_SIZE];
// if DEBUG_MONITORING is enabled in Configuration.h
uint8_t getQueueCount(void);

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 @@ -1330,23 +1330,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 @@ -216,7 +216,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
Loading