From c59153abb396484f0cce3d7b994db0dfabce1d4c Mon Sep 17 00:00:00 2001 From: Antonino Di Guardo <64427768+digant73@users.noreply.github.com> Date: Tue, 31 Oct 2023 05:23:23 +0100 Subject: [PATCH] Removed unnecessary cache queue for managing PLR feature (#2820) --- TFT/src/User/API/Gcode/gcode.c | 27 ++-- TFT/src/User/API/Gcode/gcode.h | 1 - TFT/src/User/API/PowerFailed.c | 222 ++++++++++++++++++------------- TFT/src/User/API/PowerFailed.h | 13 +- TFT/src/User/API/Printing.c | 29 ++-- TFT/src/User/API/Vfs/vfs.c | 59 ++++---- TFT/src/User/API/Vfs/vfs.h | 15 ++- TFT/src/User/API/comment.c | 110 ++++++++------- TFT/src/User/API/comment.h | 1 - TFT/src/User/API/interfaceCmd.c | 33 +---- TFT/src/User/API/interfaceCmd.h | 8 +- TFT/src/User/API/menu.c | 19 +-- TFT/src/User/API/menu.h | 2 +- TFT/src/User/Menu/Extrude.c | 2 +- TFT/src/User/Menu/LoadUnload.c | 2 +- TFT/src/User/Menu/MeshEditor.c | 45 ++----- TFT/src/User/Menu/Print.c | 44 ++++-- TFT/src/User/Menu/PrintRestore.c | 1 - TFT/src/User/Menu/StatusScreen.h | 8 +- TFT/src/User/my_misc.h | 4 +- 20 files changed, 314 insertions(+), 331 deletions(-) diff --git a/TFT/src/User/API/Gcode/gcode.c b/TFT/src/User/API/Gcode/gcode.c index 6694d5cc8f..9dbf5e824e 100644 --- a/TFT/src/User/API/Gcode/gcode.c +++ b/TFT/src/User/API/Gcode/gcode.c @@ -3,9 +3,9 @@ REQUEST_COMMAND_INFO requestCommandInfo = {0}; -bool isWaitingResponse(void) +void waitForResponse(void) { - return (!requestCommandInfo.done); + TASK_LOOP_WHILE(!requestCommandInfo.done); } bool requestCommandInfoIsRunning(void) @@ -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; @@ -80,8 +80,7 @@ void detectAdvancedOk(void) // send any gcode replied by the mainboard with a regular OK response ("ok\n") or an ADVANCED_OK response (e.g. "ok N10 P15 B3\n") mustStoreCmd("M220\n"); - // Wait for response - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); // wait for response while (requestCommandInfo.cmd_rev_buf[cmd_index] != '\0') { @@ -117,8 +116,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(); // wait for response clearRequestCommandInfo(); @@ -139,8 +137,7 @@ char * request_M20(void) else mustStoreCmd("M20\n"); - // Wait for response - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); // wait for response //clearRequestCommandInfo(); // shall be call after copying the buffer ... return requestCommandInfo.cmd_rev_buf; @@ -165,8 +162,7 @@ char * request_M33(const char * filename) else mustStoreCmd("M33 %s\n", filename); - // Wait for response - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); // wait for response //clearRequestCommandInfo(); // shall be call after copying the buffer return requestCommandInfo.cmd_rev_buf; @@ -217,8 +213,7 @@ long request_M23_M36(const char * filename) sizeTag = "size\":"; // reprap firmware reports size JSON } - // Wait for response - loopProcessToCondition(&isWaitingResponse); + waitForResponse(); // wait for response if (requestCommandInfo.inError) { @@ -300,12 +295,12 @@ void request_M98(const char * filename) mustStoreCmd(command); // prevent a race condition when rrfStatusQuery returns !busy before executing the macro - TASK_LOOP_WHILE(isEnqueued(command)) + TASK_LOOP_WHILE(isEnqueued(command)); rrfStatusQueryFast(); // Wait for macro to complete - loopProcessToCondition(&rrfStatusIsBusy); + TASK_LOOP_WHILE(rrfStatusIsBusy()); rrfStatusQueryNormal(); } @@ -318,5 +313,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(); // wait for response } diff --git a/TFT/src/User/API/Gcode/gcode.h b/TFT/src/User/API/Gcode/gcode.h index 14ff436895..10d5955e9a 100644 --- a/TFT/src/User/API/Gcode/gcode.h +++ b/TFT/src/User/API/Gcode/gcode.h @@ -32,7 +32,6 @@ typedef struct extern REQUEST_COMMAND_INFO requestCommandInfo; -bool isWaitingResponse(void); // condition callback for loopProcessToCondition() bool requestCommandInfoIsRunning(void); void clearRequestCommandInfo(void); diff --git a/TFT/src/User/API/PowerFailed.c b/TFT/src/User/API/PowerFailed.c index 1e76400672..a8adca63f4 100644 --- a/TFT/src/User/API/PowerFailed.c +++ b/TFT/src/User/API/PowerFailed.c @@ -18,12 +18,14 @@ typedef struct bool pause; } BREAK_POINT; -BREAK_POINT infoBreakPoint; -char powerFailedFileName[256]; +BREAK_POINT infoBreakPoint; +char powerFailedFileName[sizeof(BREAK_POINT_FILE) + 20 + 1]; // extra 20 chars for concatenation with string returned by getFS() FIL fpPowerFailed; -static bool restore = false; // print restore flag disabled by default -static bool create_ok = false; +static bool restore = false; // print restore flag disabled by default +static bool restore_ok = false; // print restore initialization flag disabled by default +static bool load_ok = false; // PLR file loading flag disabled by default +static bool create_ok = false; // PLR file creation flag disabled by default void powerFailedSetRestore(bool allowed) { @@ -40,12 +42,14 @@ void powerFailedSetDriverSource(void) sprintf(powerFailedFileName, "%s%s", getFS(), BREAK_POINT_FILE); } -bool powerFailedInitData(void) +bool powerFailedLoad(FIL *print_fp) { - memset(&infoBreakPoint, 0, sizeof(BREAK_POINT)); + // set status flag status first + load_ok = false; + restore_ok = false; - if (!restore) // if print restore flag is disabled, nothing more to do - return true; + // if print restore flag is disabled, nothing to do + if (!restore) return false; // disable print restore flag (one shot flag) for the next print. // The flag must always be explicitly re-enabled (e.g by powerFailedSetRestore function) @@ -53,38 +57,65 @@ bool powerFailedInitData(void) // try to load PLR info from file in order to restore the print from the failed point - FIL fp; - UINT br; + FIL fp; + UINT br; uint8_t model_icon; powerFailedSetDriverSource(); - if (f_open(&fp, powerFailedFileName, FA_OPEN_EXISTING | FA_READ) != FR_OK) return false; - if (f_lseek(&fp, MAX_PATH_LEN) != FR_OK) return false; - if (f_read(&fp, &model_icon, 1, &br) != FR_OK) return false; - if (f_read(&fp, &infoBreakPoint, sizeof(infoBreakPoint), &br) != FR_OK) return false; + if (f_open(&fp, powerFailedFileName, FA_OPEN_EXISTING | FA_READ) != FR_OK) + return false; + + if (f_lseek(&fp, MAX_PATH_LEN) == FR_OK) + { + if (f_read(&fp, &model_icon, 1, &br) == FR_OK) + { + if (f_read(&fp, &infoBreakPoint, sizeof(infoBreakPoint), &br) == FR_OK) + { + // set offset on print file once infoBreakPoint was successfully read + if (f_lseek(print_fp, infoBreakPoint.offset) == FR_OK) + { + load_ok = true; + restore_ok = true; + } + } + } + } + + f_close(&fp); // always close the file once it was successfully open before + + if (load_ok) // if the file was successfully open, set icon model + setPrintModelIcon(model_icon); - setPrintModelIcon(model_icon); + return load_ok; +} + +bool powerFailedInitRestore(void) +{ + // if print restore initialization flag is disabled, nothing to do + if (!restore_ok) return false; + + // disable print restore initialization flag (one shot flag) for the next print + restore_ok = false; for (uint8_t i = 0; i < infoSettings.fan_count; i++) { if (infoBreakPoint.fan[i] != 0) - { - mustStoreCacheCmd(fanCmd[i], infoBreakPoint.fan[i]); - } + mustStoreCmd(fanCmd[i], infoBreakPoint.fan[i]); } - mustStoreCacheCmd("%s\n", toolChange[infoBreakPoint.tool]); + mustStoreCmd("%s\n", toolChange[infoBreakPoint.tool]); - for (uint8_t i = MAX_HEATER_COUNT - 1; i >= MAX_HOTEND_COUNT; i--) // Bed & Chamber infoCacheCmd.queue[0 - 1] + for (uint8_t i = MAX_HEATER_COUNT - 1; i >= MAX_HOTEND_COUNT; i--) // Bed & Chamber { if (infoBreakPoint.target[i] != 0) - mustStoreCacheCmd("%s S%d\n", heatWaitCmd[i], infoBreakPoint.target[i]); + mustStoreCmd("%s S%d\n", heatWaitCmd[i], infoBreakPoint.target[i]); } - for (int8_t i = infoSettings.hotend_count - 1; i >= 0; i--) // Tool nozzle infoCacheCmd.queue[2 - 7] + + for (int8_t i = infoSettings.hotend_count - 1; i >= 0; i--) // Tool nozzle { if (infoBreakPoint.target[i] != 0) - mustStoreCacheCmd("%s S%d\n", heatWaitCmd[i], infoBreakPoint.target[i]); + mustStoreCmd("%s S%d\n", heatWaitCmd[i], infoBreakPoint.target[i]); } if (infoBreakPoint.feedrate != 0) @@ -97,98 +128,110 @@ bool powerFailedInitData(void) if (infoBreakPoint.pause) z_raised += infoSettings.pause_z_raise; - mustStoreCacheCmd("G92 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + z_raised); // infoCacheCmd.queue[8 - 11] - mustStoreCacheCmd("G1 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + infoSettings.plr_z_raise); + mustStoreCmd("G92 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + z_raised); + mustStoreCmd("G1 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + infoSettings.plr_z_raise); + if (infoSettings.plr_home) { - mustStoreCacheCmd("G28\n"); - mustStoreCacheCmd("G1 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + infoSettings.plr_z_raise); + mustStoreCmd("G28\n"); + mustStoreCmd("G1 Z%.3f\n", infoBreakPoint.axis[Z_AXIS] + infoSettings.plr_z_raise); } else { - mustStoreCacheCmd("G28 R0 XY\n"); + mustStoreCmd("G28 R0 XY\n"); } - mustStoreCacheCmd("M83\n"); // infoCacheCmd.queue[12 - 17] - mustStoreCacheCmd("G1 E30 F300\n"); - mustStoreCacheCmd("G1 E-%.5f F4800\n", infoSettings.pause_retract_len); - mustStoreCacheCmd("G1 X%.3f Y%.3f Z%.3f F3000\n", - infoBreakPoint.axis[X_AXIS], - infoBreakPoint.axis[Y_AXIS], - infoBreakPoint.axis[Z_AXIS]); - mustStoreCacheCmd("G1 E%.5f F4800\n", infoSettings.resume_purge_len); - mustStoreCacheCmd("G92 E%.5f\nG1 F%d\n", infoBreakPoint.axis[E_AXIS], infoBreakPoint.feedrate); - - if (infoBreakPoint.relative_e == false) // infoCacheCmd.queue[18] - { - mustStoreCacheCmd("M82\n"); - } + mustStoreCmd("M83\n"); + mustStoreCmd("G1 E30 F300\n"); + mustStoreCmd("G1 E-%.5f F4800\n", infoSettings.pause_retract_len); + mustStoreCmd("G1 X%.3f Y%.3f Z%.3f F3000\n", infoBreakPoint.axis[X_AXIS], infoBreakPoint.axis[Y_AXIS], infoBreakPoint.axis[Z_AXIS]); + mustStoreCmd("G1 E%.5f F4800\n", infoSettings.resume_purge_len); + mustStoreCmd("G92 E%.5f\nG1 F%d\n", infoBreakPoint.axis[E_AXIS], infoBreakPoint.feedrate); + mustStoreCmd(infoBreakPoint.relative ? "G91\n" : "G90\n"); - // infoCacheCmd.queue[19] max length = 0 - 19. - if (infoBreakPoint.relative == true) - { - mustStoreCacheCmd("G91\n"); - } - // End of cache - // The length of the gcode stored in the cache should be less than max length = 20 - // Otherwise, if there are M109/M190/M191 blocking the queue, it will cause "Busy processing, please wait..." and bring bad user experience + if (infoBreakPoint.relative_e == false) + mustStoreCmd("M82\n"); } - f_close(&fp); return true; } bool powerFailedExist(void) { + bool access_ok = false; FIL fp; UINT br; powerFailedSetDriverSource(); - if (f_open(&fp, powerFailedFileName, FA_OPEN_EXISTING | FA_READ) != FR_OK) return false; - if (f_read(&fp, infoFile.path, MAX_PATH_LEN, &br) != FR_OK) return false; - if (f_close(&fp) != FR_OK) return false; + if (f_open(&fp, powerFailedFileName, FA_OPEN_EXISTING | FA_READ) != FR_OK) + return false; - create_ok = true; - return true; + if (f_read(&fp, infoFile.path, MAX_PATH_LEN, &br) == FR_OK) + access_ok = true; + + f_close(&fp); // always close the file once it was successfully open before + + return access_ok; } -bool powerFailedCreate(char *path) +void powerFailedCreate(char *path) { + powerFailedDelete(); // close and delete PLR file, if any, first + + if (!infoSettings.plr) return; // if PLR is disabled + if (infoFile.source >= FS_ONBOARD_MEDIA) return; // onboard media not supported now + UINT br; powerFailedSetDriverSource(); - create_ok = false; - if (!infoSettings.plr) return false; // if PLR is disabled - if (infoFile.source >= FS_ONBOARD_MEDIA) return false; // onboard media not supported now + if (f_open(&fpPowerFailed, powerFailedFileName, FA_OPEN_ALWAYS | FA_WRITE) != FR_OK) + return; - if (f_open(&fpPowerFailed, powerFailedFileName, FA_OPEN_ALWAYS | FA_WRITE) != FR_OK) return false; + if (f_write(&fpPowerFailed, path, MAX_PATH_LEN, &br) == FR_OK) + { + uint8_t model_icon = isPrintModelIcon(); - f_write(&fpPowerFailed, path, MAX_PATH_LEN, &br); - uint8_t model_icon = isPrintModelIcon(); - f_write(&fpPowerFailed, &model_icon, 1, &br); - f_write(&fpPowerFailed, &infoBreakPoint, sizeof(BREAK_POINT), &br); - f_sync(&fpPowerFailed); + if (f_write(&fpPowerFailed, &model_icon, 1, &br) == FR_OK) + { + // if PLR file not loaded, initilaize data. Otherwise use loaded data + // so also powerFailedInitRestore() function can be used + if (!load_ok) + memset(&infoBreakPoint, 0, sizeof(BREAK_POINT)); + + if (f_write(&fpPowerFailed, &infoBreakPoint, sizeof(infoBreakPoint), &br) == FR_OK) + { + if (f_sync(&fpPowerFailed) == FR_OK) + { + create_ok = true; + } + } + } + } - create_ok = true; - return true; + if (!create_ok) // if PLR file was not properly opened and written, close it + f_close(&fpPowerFailed); + + return; } void powerFailedCache(uint32_t offset) { - UINT br; + if (!create_ok) return; // if PLR file not created - if (create_ok == false) return; - if (infoBreakPoint.axis[Z_AXIS] == coordinateGetAxisTarget(Z_AXIS)) return; // Z axis not changed + if (infoBreakPoint.axis[Z_AXIS] == coordinateGetAxisTarget(Z_AXIS)) return; // if Z axis not changed if (isNotEmptyCmdQueue()) return; - if (!isPaused()) - { // not paused, update printing progress status. + + if (!isPaused()) // if not paused, update printing progress status + { infoBreakPoint.offset = offset; + for (AXIS i = X_AXIS; i < TOTAL_AXIS; i++) { infoBreakPoint.axis[i] = coordinateGetAxisTarget(i); } + infoBreakPoint.feedrate = coordinateGetFeedRate(); infoBreakPoint.speed = speedGetCurPercent(0); // Move speed percent infoBreakPoint.flow = speedGetCurPercent(1); // Flow percent @@ -197,45 +240,46 @@ void powerFailedCache(uint32_t offset) { infoBreakPoint.target[i] = heatGetTargetTemp(i); } + for (uint8_t i = MAX_HOTEND_COUNT; i < MAX_HEATER_COUNT; i++) // Bed & Chamber { infoBreakPoint.target[i] = heatGetTargetTemp(i); } + infoBreakPoint.tool = heatGetToolIndex(); for (uint8_t i = 0; i < infoSettings.fan_count; i++) { infoBreakPoint.fan[i] = fanGetCurSpeed(i); } + infoBreakPoint.relative = coorGetRelative(); infoBreakPoint.relative_e = eGetRelative(); } - else if (infoBreakPoint.pause) return; // paused and the pause state has been saved + else if (infoBreakPoint.pause) // if paused and the pause state has been saved, nothing to do + { + return; + } infoBreakPoint.pause = isPaused(); + UINT br; + f_lseek(&fpPowerFailed, MAX_PATH_LEN + 1); // infoFile.path + infoPrinting.model_icon - f_write(&fpPowerFailed, &infoBreakPoint, sizeof(BREAK_POINT), &br); + f_write(&fpPowerFailed, &infoBreakPoint, sizeof(infoBreakPoint), &br); f_sync(&fpPowerFailed); } -void powerFailedClose(void) -{ - if (create_ok == false) return; - - f_close(&fpPowerFailed); -} - void powerFailedDelete(void) { - if (create_ok == false) return; + if (create_ok) // if PLR file is currently open and used, close it first + { + f_close(&fpPowerFailed); - f_unlink(powerFailedFileName); -} + create_ok = false; + } -bool powerFailedlSeek(FIL *fp) -{ - if (f_lseek(fp, infoBreakPoint.offset) != FR_OK) return false; + powerFailedSetDriverSource(); - return true; + f_unlink(powerFailedFileName); // delete the file } diff --git a/TFT/src/User/API/PowerFailed.h b/TFT/src/User/API/PowerFailed.h index d1dcae85fd..01a31d33f1 100644 --- a/TFT/src/User/API/PowerFailed.h +++ b/TFT/src/User/API/PowerFailed.h @@ -15,21 +15,22 @@ bool powerFailedGetRestore(void); // get the value of current print res // called in Printing.c +bool powerFailedInitRestore(void); // initialize print restore, if any, if not already initialized (one shot flag) + /** - * initialize PLR info. + * load PLR info. * If print restore flag was enabled (e.g. by powerFailedSetRestore function called in PrintRestore.c), - * try to load PLR info from file in order to restore the print from the failed point. + * try to load PLR info from file in order to restore the print from the failed point (setting the offset + * on print file to the backed up layer). * It finally disables print restore flag (one shot flag) for the next print. * The flag must always be explicitly re-enabled (e.g by powerFailedSetRestore function) */ -bool powerFailedInitData(void); +bool powerFailedLoad(FIL *print_fp); bool powerFailedExist(void); -bool powerFailedCreate(char *path) ; +void powerFailedCreate(char *path); void powerFailedCache(uint32_t offset); -void powerFailedClose(void); void powerFailedDelete(void); -bool powerFailedlSeek(FIL *fp); #ifdef __cplusplus } diff --git a/TFT/src/User/API/Printing.c b/TFT/src/User/API/Printing.c index 78b6906ef5..b4360cf7f4 100644 --- a/TFT/src/User/API/Printing.c +++ b/TFT/src/User/API/Printing.c @@ -385,8 +385,7 @@ void completePrint(void) case FS_TFT_SD: case FS_TFT_USB: f_close(&infoPrinting.file); - powerFailedClose(); // close PLR file - powerFailedDelete(); // delete PLR file + powerFailedDelete(); // close and delete PLR file, if any break; case FS_ONBOARD_MEDIA: @@ -474,18 +473,16 @@ bool startPrint(void) infoPrinting.cur = infoPrinting.file.fptr; setExtrusionDuringPause(false); - // initialize PLR info. + // load PLR info. // If print restore flag was enabled (e.g. by powerFailedSetRestore function called in PrintRestore.c), - // try to load PLR info from file in order to restore the print from the failed point. + // try to load PLR info from file in order to restore the print from the failed point (setting the offset + // on print file to the backed up layer). // It finally disables print restore flag (one shot flag) for the next print. // The flag must always be explicitly re-enabled (e.g by powerFailedSetRestore function) - powerFailedInitData(); + // + printRestore = powerFailedLoad(&infoPrinting.file); - if (powerFailedCreate(infoFile.path)) // if PLR feature is enabled, open a new PLR file - { - printRestore = true; - powerFailedlSeek(&infoPrinting.file); // seek on PLR file - } + powerFailedCreate(infoFile.path); // if PLR feature is enabled, open a new PLR file } break; @@ -632,7 +629,7 @@ 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(); @@ -815,8 +812,14 @@ void loopPrintFromTFT(void) { if (!infoPrinting.printing) return; if (infoFile.source >= FS_ONBOARD_MEDIA) return; // if not printing from TFT media - if (heatHasWaiting() || isNotEmptyCmdQueue() || infoPrinting.paused) return; - if (moveCacheToCmd() == true) return; + if (infoPrinting.paused || heatHasWaiting() || isNotEmptyCmdQueue()) return; + + // if here, the command queue is also empty and we proceed with only one of the following scenarios, in the provided order: + // - initialize print restore, if any, storing a set of commands on command queue + // - retrieve next command from print file and store it on command queue + + if (powerFailedInitRestore()) // initialize print restore, if any, if not already initialized (one shot flag) + return; powerFailedCache(infoPrinting.file.fptr); // update Power-loss Recovery file diff --git a/TFT/src/User/API/Vfs/vfs.c b/TFT/src/User/API/Vfs/vfs.c index ca84e07391..6df3ec9076 100644 --- a/TFT/src/User/API/Vfs/vfs.c +++ b/TFT/src/User/API/Vfs/vfs.c @@ -179,10 +179,7 @@ char * isSupportedFile(const char * filename) { char * extPos = strrchr(filename, '.'); // check last "." in the name where extension is supposed to start - if (extPos != NULL && extPos[1] != 'g' && extPos[1] != 'G') - extPos = NULL; - - return extPos; + return (extPos != NULL && (extPos[1] == 'g' || extPos[1] == 'G')) ? extPos : NULL; } // add a file name or folder name to file list @@ -261,7 +258,7 @@ bool addFile(bool isFile, const char * shortName, const char * longName) } // return the long folder name if exists, otherwise the short one -char * getFoldername(uint8_t index) +const char * getFoldername(uint8_t index) { if (infoFile.longFolder[index] != NULL) return infoFile.longFolder[index]; @@ -270,7 +267,7 @@ char * getFoldername(uint8_t index) } // return the long file name if exists, otherwise the short one -char * getFilename(uint8_t index) +const char * getFilename(uint8_t index) { if (infoFile.longFile[index] != NULL) return infoFile.longFile[index]; @@ -278,60 +275,50 @@ char * getFilename(uint8_t index) return infoFile.file[index]; } -char * hideExtension(char * filename) +const char * hideExtension(const char * filename) { - if (infoSettings.filename_extension == 0) // if filename extension is disabled + // if filename extension feature is disabled and extension is not already hidden + if (infoSettings.filename_extension == 0 && strchr(filename, '\0')[1] == '\0') { char * extPos = isSupportedFile(filename); - // if filename provides a supported filename extension then - // check extra byte for filename extension check. If 0, no filename extension was previously hidden - if (extPos != NULL && filename[strlen(filename) + 1] == '\0') - filename[extPos - filename] = 0; // temporary hide filename extension + // if filename provides a supported filename extension + if (extPos != NULL) + *extPos = '\0'; // temporary hide filename extension } return filename; } -char * restoreExtension(char * filename) +const char * restoreExtension(const char * filename) { - if (infoSettings.filename_extension == 0) // if filename extension is disabled + if (infoSettings.filename_extension == 0) // if filename extension feature is disabled { + char * extPos = strchr(filename, '\0'); + // check extra byte for filename extension check. If 0, no filename extension was previously hidden - if (filename[strlen(filename) + 1] != '\0') - filename[strlen(filename)] = '.'; // restore filename extension + if (extPos[1] != '\0') + *extPos = '.'; // restore filename extension } return filename; } -// hide the extension of the file name and return a pointer to that file name -// (the long one if exists, otherwise the short one). +// hide the extension of the file name and return a pointer to that file name (the long one if exists, otherwise the short one). // The hide of the extension is not temporary so do not forget to restore it afterwards! -char * hideFilenameExtension(uint8_t index) +const char * hideFilenameExtension(uint8_t index) { - char * filename = hideExtension(infoFile.file[index]); - - if (infoFile.longFile[index] != NULL) - filename = hideExtension(infoFile.longFile[index]); - - return filename; + return hideExtension(infoFile.longFile[index] != NULL ? infoFile.longFile[index] : infoFile.file[index]); } -// restore the extension of the file name and return a pointer to that file name -// (the long one if exists, otherwise the short one) -char * restoreFilenameExtension(uint8_t index) +// restore the extension of the file name and return a pointer to that file name (the long one if exists, otherwise the short one) +const char * restoreFilenameExtension(uint8_t index) { - char * filename = restoreExtension(infoFile.file[index]); - - if (infoFile.longFile[index] != NULL) - filename = restoreExtension(infoFile.longFile[index]); - - return filename; + return restoreExtension(infoFile.longFile[index] != NULL ? infoFile.longFile[index] : infoFile.file[index]); } // get print filename according to print originator (remote or local to TFT) -char * getPrintFilename(void) +const char * getPrintFilename(void) { // if restoring a print after a power failure or printing from remote host, remote onboard media or remote TFT media (with M23 - M24), // no filename is available in infoFile. Only infoFile.source and infoFile.path have been set @@ -347,7 +334,7 @@ bool getPrintTitle(char * buf, uint8_t len) { // example: "SD:/test/cap2.gcode" -> "SD:cap2.gcode" - char * strPtr = getPrintFilename(); + const char * strPtr = getPrintFilename(); // "+ 2": space for terminating null character and the flag for filename extension check if (strlen(getFS()) + strlen(strPtr) + 2 > len) diff --git a/TFT/src/User/API/Vfs/vfs.h b/TFT/src/User/API/Vfs/vfs.h index 4a4d45e014..7670ebfdac 100644 --- a/TFT/src/User/API/Vfs/vfs.h +++ b/TFT/src/User/API/Vfs/vfs.h @@ -64,13 +64,18 @@ bool isRootFolder(void); // ch bool addFile(bool isFile, const char * shortName, const char * longName); // add a file name or folder name to file list // called in Print.c -char * getFoldername(uint8_t index); // return the long folder name if exists, otherwise the short one -char * getFilename(uint8_t index); // return the long file name if exists, otherwise the short one -char * hideFilenameExtension(uint8_t index); // hide the extension of the file name and return a pointer to that file name -char * restoreFilenameExtension(uint8_t index); // restore the extension of the file name and return a pointer to that file name +const char * getFoldername(uint8_t index); // return the long folder name if exists, otherwise the short one +const char * getFilename(uint8_t index); // return the long file name if exists, otherwise the short one + +// hide the extension of the file name and return a pointer to that file name (the long one if exists, otherwise the short one). +// The hide of the extension is not temporary so do not forget to restore it afterwards! +const char * hideFilenameExtension(uint8_t index); + +// restore the extension of the file name and return a pointer to that file name (the long one if exists, otherwise the short one) +const char * restoreFilenameExtension(uint8_t index); // called in PrintingMenu.c -char * getPrintFilename(void); // get print filename according to print originator (remote or local to TFT) +const char * getPrintFilename(void); // get print filename according to print originator (remote or local to TFT) bool getPrintTitle(char * buf, uint8_t len); // get print title according to print originator (remote or local to TFT) // called in menu.c diff --git a/TFT/src/User/API/comment.c b/TFT/src/User/API/comment.c index 9fa071ff74..cd5d34ad82 100644 --- a/TFT/src/User/API/comment.c +++ b/TFT/src/User/API/comment.c @@ -1,9 +1,8 @@ #include "comment.h" #include "includes.h" -#include -#define TOKEN_DELIMITERS " :=_" -#define HIGH_TO_LOW_CASE 32 // 'a' - 'A' +#define TOKEN_DELIMITERS " :=_" // possible delimiters found in the comments of the G-code file +#define KEYWORD_INTIALS "lLrRtT" // the initials of the searched keywords, add new initials for new keywords char gCodeCommentLine[COMMENT_MAX_CHAR] = {0}; bool slicerTimePresence = false; @@ -18,95 +17,92 @@ void parseComment(void) if (gCodeCommentLine[0] == '\0') return; - char * temp_char = strtok(gCodeCommentLine, TOKEN_DELIMITERS); - uint32_t temp_value = 0; + // check for words starting with "l", "L", "r", "R", "t" or "T". + // It is done so for speed purposes, it is a waste of MCU cycles to extract + // tokens, convert them to lower case and check if they are among the known + // keywords if they do not start with the above mentioned letters + // + if (strchr(KEYWORD_INTIALS, gCodeCommentLine[0]) != NULL) + { + char * token; + uint32_t token_value; - strlwr(temp_char); + token = strlwr(strtok(gCodeCommentLine, TOKEN_DELIMITERS)); - switch (gCodeCommentLine[0]) - { - case 'l': - case 'L': + // check for "layer" keyword in comment (layer number or layer count) + if (strcmp(token, "layer") == 0) { - if (strcmp(temp_char, "layer") == 0) + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) { - // check for "layer" keyword in comment (layer number or layer count) - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); + strlwr(token); - if (strcmp(temp_char, "count") == 0) // check if next word is "count" + if (strcmp(token, "count") == 0) // check if next word is "count" { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - temp_value = strtoul(temp_char, NULL, 0); + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) // get the layer number + { + token_value = strtoul(token, NULL, 0); - if (temp_value != 0) - setPrintLayerCount(temp_value); + if (token_value != 0) + setPrintLayerCount(token_value); + } } - else if (NUMERIC(temp_char[0])) // check if a number is found + else if (NUMERIC(token[0])) // check if a number is found { - temp_value = strtoul(temp_char, NULL, 0); - // "temp_value == 0" for object by object printing, when print goes to the next object + token_value = strtoul(token, NULL, 0); + + // "token_value == 0" for object by object printing, when print goes to the next object // if there is "layer 0" add an offset of 1 (avoiding using an offset variable) - setPrintLayerNumber(((temp_value == 0) || (getPrintLayerNumber() == temp_value)) ? temp_value + 1 : temp_value); + setPrintLayerNumber(((token_value == 0) || (getPrintLayerNumber() == token_value)) ? token_value + 1 : token_value); } } - // continue here with "else if" for another token that starts with "l" or "L" - break; } - case 't': - case 'T': + // check for "time" keyword in comment to retrieve total or elapsed time, Cura specific + else if (strcmp(token, "time") == 0 && slicerTimePresence == false) // check if first word is "time" { - // check for "time" keyword in comment to retrieve total or elapsed time, Cura specific - if (strcmp(temp_char, "time") == 0 && slicerTimePresence == false) // check if first word is "time" + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); + strlwr(token); - if (strcmp(temp_char, "elapsed") == 0 && getPrintExpectedTime() > 0) // check if next word is "elapsed" + if (strcmp(token, "elapsed") == 0 && getPrintExpectedTime() > 0) // check if next word is "elapsed" { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - temp_value = strtoul(temp_char, NULL, 0); // get the elapsed time in seconds - setPrintRemainingTime(getPrintExpectedTime() - temp_value); + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) // get the elapsed time in seconds + { + setPrintRemainingTime(getPrintExpectedTime() - strtoul(token, NULL, 0)); + } } - else if (temp_char[0] >= '0' && temp_char[0] <= '9') // check if a number is found + else if (NUMERIC(token[0])) // check if a number is found { - setPrintExpectedTime(strtoul(temp_char, NULL, 0)); - setPrintRemainingTime(getPrintExpectedTime()); + token_value = strtoul(token, NULL, 0); // get the time in seconds + + setPrintExpectedTime(token_value); + setPrintRemainingTime(token_value); if (getPrintProgressSource() < PROG_TIME && infoSettings.prog_source == 1) setPrintProgressSource(PROG_TIME); } } - // continue here with "else if" for another token that starts with "t" or "T" - break; } - case 'r': - case 'R': + // check for "remaining" keyword in comment to retrieve remaining time, IdeaMaker specific + else if (strcmp(token, "remaining") == 0 && slicerTimePresence == false) // check if first word is "remaining" { - // check for "remaining" keyword in comment to retrieve remaining time, IdeaMaker specific - if (strcmp(temp_char, "remaining") == 0 && slicerTimePresence == false) // check if first word is "remaining" + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); + strlwr(token); - if (strcmp(temp_char, "time") == 0) // check if next word is "time" + if (strcmp(token, "time") == 0) // check if next word is "time" { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - temp_value = strtoul(temp_char, NULL, 0); // get the remaining time in seconds - setPrintRemainingTime(temp_value); + if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) // get the remaining time in seconds + { + setPrintRemainingTime(strtoul(token, NULL, 0)); - if (getPrintProgressSource() < PROG_TIME && infoSettings.prog_source == 1) - setPrintProgressSource(PROG_TIME); + if (getPrintProgressSource() < PROG_TIME && infoSettings.prog_source == 1) + setPrintProgressSource(PROG_TIME); + } } } - // continue here with "else if" for another token that starts with "r" or "R" - break; } - - default: - break; } gCodeCommentLine[0] = '\0'; diff --git a/TFT/src/User/API/comment.h b/TFT/src/User/API/comment.h index e914870e09..46d1b05f5e 100644 --- a/TFT/src/User/API/comment.h +++ b/TFT/src/User/API/comment.h @@ -6,7 +6,6 @@ extern "C" { #endif #include -#include #define COMMENT_MAX_CHAR 100 diff --git a/TFT/src/User/API/interfaceCmd.c b/TFT/src/User/API/interfaceCmd.c index d3e1cfb338..69365ff968 100644 --- a/TFT/src/User/API/interfaceCmd.c +++ b/TFT/src/User/API/interfaceCmd.c @@ -26,7 +26,6 @@ typedef enum } WRITING_MODE; GCODE_QUEUE cmdQueue; // command queue where commands to be sent are stored -GCODE_QUEUE cmdCache; // only when heatHasWaiting() returns "false" the cmd in this cache will move to cmdQueue queue char * cmd_ptr; uint8_t cmd_len; SERIAL_PORT_INDEX cmd_port_index; // index of serial port originating the gcode @@ -113,7 +112,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(isFullCmdQueue()); // wait for a free slot in the queue in case the queue is currently full } va_list va; @@ -175,40 +174,10 @@ bool storeCmdFromUART(const CMD cmd, const SERIAL_PORT_INDEX portIndex) return true; } -// Store gcode cmd to cmdCache queue. -// This command will be moved to cmdQueue queue by loopPrintFromTFT() -> moveCacheToCmd(). -// This function is used only to restore the printing status after a power failed. -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 - } - - va_list va; - va_start(va, format); - commonStoreCmd(&cmdCache, format, va); - va_end(va); -} - -// Move gcode cmd from cmdCache to cmdQueue queue. -bool moveCacheToCmd(void) -{ - if (cmdQueue.count >= CMD_QUEUE_SIZE || cmdCache.count == 0) return false; - - storeCmd("%s", cmdCache.queue[cmdCache.index_r].gcode); - cmdCache.count--; - cmdCache.index_r = (cmdCache.index_r + 1) % CMD_QUEUE_SIZE; - - return true; -} - // Clear all gcode cmd in cmdQueue queue. void clearCmdQueue(void) { cmdQueue.count = cmdQueue.index_w = cmdQueue.index_r = 0; - cmdCache.count = cmdCache.index_w = cmdCache.index_r = 0; } // Strip out any leading space from the passed command. diff --git a/TFT/src/User/API/interfaceCmd.h b/TFT/src/User/API/interfaceCmd.h index d905e32f5f..79995c0937 100644 --- a/TFT/src/User/API/interfaceCmd.h +++ b/TFT/src/User/API/interfaceCmd.h @@ -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); @@ -32,8 +32,6 @@ bool storeCmd(const char * format, ...); void mustStoreCmd(const char * format, ...); void mustStoreScript(const char * format, ...); bool storeCmdFromUART(const CMD cmd, const SERIAL_PORT_INDEX portIndex); -void mustStoreCacheCmd(const char * format, ...); -bool moveCacheToCmd(void); void clearCmdQueue(void); void handleCmd(CMD cmd, const SERIAL_PORT_INDEX portIndex); void sendEmergencyCmd(const CMD emergencyCmd, const SERIAL_PORT_INDEX portIndex); diff --git a/TFT/src/User/API/menu.c b/TFT/src/User/API/menu.c index 2727ddbca6..17ed586a79 100644 --- a/TFT/src/User/API/menu.c +++ b/TFT/src/User/API/menu.c @@ -1334,22 +1334,17 @@ void menuDummy(void) CLOSE_MENU(); } -void loopProcessToCondition(CONDITION_CALLBACK condCallback) +void loopProcessAndGUI(void) { 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), handle it { - loopProcess(); + (*infoMenu.menu[infoMenu.cur])(); // handle user interaction - if (infoMenu.cur > curMenu) // if a user interaction is needed (e.g. dialog box UI), handle it - { - invokedUI = true; - (*infoMenu.menu[infoMenu.cur])(); - } + if (MENU_IS_NOT(menuDummy)) // avoid to nest menuDummy menu type + OPEN_MENU(menuDummy); // load a dummy menu just to force the redraw of the underlying menu (caller menu) } - - if (invokedUI) // if a UI was invoked, load a dummy menu just to force the caller also to refresh its menu - OPEN_MENU(menuDummy); } diff --git a/TFT/src/User/API/menu.h b/TFT/src/User/API/menu.h index cb344b78ca..ef6f94ff43 100644 --- a/TFT/src/User/API/menu.h +++ b/TFT/src/User/API/menu.h @@ -216,7 +216,7 @@ void menuDummy(void); void loopBackEnd(void); void loopFrontEnd(void); void loopProcess(void); -void loopProcessToCondition(CONDITION_CALLBACK condCallback); +void loopProcessAndGUI(void); #ifdef __cplusplus } diff --git a/TFT/src/User/Menu/Extrude.c b/TFT/src/User/Menu/Extrude.c index 89f95c0d9a..2cac30b5ea 100644 --- a/TFT/src/User/Menu/Extrude.c +++ b/TFT/src/User/Menu/Extrude.c @@ -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(); diff --git a/TFT/src/User/Menu/LoadUnload.c b/TFT/src/User/Menu/LoadUnload.c index 24ce73092d..d184422a49 100644 --- a/TFT/src/User/Menu/LoadUnload.c +++ b/TFT/src/User/Menu/LoadUnload.c @@ -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; diff --git a/TFT/src/User/Menu/MeshEditor.c b/TFT/src/User/Menu/MeshEditor.c index eb08da2320..af0b973ace 100644 --- a/TFT/src/User/Menu/MeshEditor.c +++ b/TFT/src/User/Menu/MeshEditor.c @@ -451,14 +451,10 @@ uint16_t meshGetRGBColor(const float value) if (meshData->valueDelta == 0) return (meshData->rStart << 11) | (meshData->gStart << 5) | (meshData->bStart); - float valueDiff; - uint16_t r, g, b; - - valueDiff = value - meshData->valueMin; - - r = mapRGBdata(&meshData->rStart, &meshData->rDelta, &valueDiff, &meshData->valueDelta); - g = mapRGBdata(&meshData->gStart, &meshData->gDelta, &valueDiff, &meshData->valueDelta); - b = mapRGBdata(&meshData->bStart, &meshData->bDelta, &valueDiff, &meshData->valueDelta); + float valueDiff = value - meshData->valueMin; + uint16_t r = mapRGBdata(&meshData->rStart, &meshData->rDelta, &valueDiff, &meshData->valueDelta); + uint16_t g = mapRGBdata(&meshData->gStart, &meshData->gDelta, &valueDiff, &meshData->valueDelta); + uint16_t b = mapRGBdata(&meshData->bStart, &meshData->bDelta, &valueDiff, &meshData->valueDelta); return (r << 11) | (g << 5) | (b); } @@ -787,12 +783,10 @@ void meshUpdateData(char * dataRow) void menuMeshEditor(void) { MESH_KEY_VALUES key_num = ME_KEY_IDLE; - bool forceExit = false; - uint16_t oldIndex; uint16_t curIndex; meshAllocData(); // allocates and initialize mesh data if not already allocated and initialized - oldIndex = curIndex = meshData->index; + curIndex = meshData->index; mustStoreCmd("M420 V1 T1\n"); // retrieve the mesh data @@ -823,6 +817,11 @@ void menuMeshEditor(void) case ME_KEY_NEXT: case ME_KEY_INCREASE: meshUpdateIndex(key_num); + + meshDrawGridCell(curIndex, true); // draw point with old index + curIndex = meshData->index; // update current index with new index + meshDrawGridCell(curIndex, true); // draw point with new index + meshDrawInfo(false); break; case ME_KEY_EDIT: @@ -854,7 +853,10 @@ void menuMeshEditor(void) break; case ME_KEY_OK: - forceExit = true; + if (memcmp(meshData->oriData, meshData->curData, sizeof(meshData->curData))) // check for changes + meshSave(); + + meshDeallocData(); // finally, deallocate mesh data (meshData no more accessible) CLOSE_MENU(); break; @@ -863,28 +865,9 @@ void menuMeshEditor(void) break; } - if (curIndex != meshData->index) - { - curIndex = meshData->index; - - meshDrawGridCell(oldIndex, true); // draw point with old index - meshDrawGridCell(curIndex, true); // draw point with new index - meshDrawInfo(false); - - oldIndex = curIndex; - } - loopProcess(); } - if (forceExit) - { - if (memcmp(meshData->oriData, meshData->curData, sizeof(meshData->curData))) // check for changes - meshSave(); - - meshDeallocData(); // finally, deallocate mesh data (meshData no more accessible) - } - // restore default GUI_RestoreColorDefault(); } diff --git a/TFT/src/User/Menu/Print.c b/TFT/src/User/Menu/Print.c index 21ba1bf5c7..84b6650010 100644 --- a/TFT/src/User/Menu/Print.c +++ b/TFT/src/User/Menu/Print.c @@ -56,7 +56,7 @@ const int16_t labelVolumeError[3] = {LABEL_TFT_SD_READ_ERROR, LABEL_TFT_USB_READ static bool list_mode = true; -void normalNameDisp(const GUI_RECT *rect, uint8_t *name) +void normalNameDisp(const GUI_RECT * rect, uint8_t * name) { if (name == NULL) return; @@ -68,6 +68,11 @@ void normalNameDisp(const GUI_RECT *rect, uint8_t *name) } // update files menu in icon mode +// +// NOTES: +// - icon mode menu is an option available only for browsing files from TFT SD card / TFT USB disk. +// It is not available for browsing files from onboard media +// - only short (not long) folder names and filenames are available browsing files from TFT SD card / TFT USB disk void gocdeIconDraw(void) { ITEM curItem = {ICON_NULL, LABEL_NULL}; @@ -79,15 +84,16 @@ void gocdeIconDraw(void) { curItem.icon = ICON_FOLDER; menuDrawItem(&curItem, i); - normalNameDisp(&gcodeRect[i], (uint8_t*)infoFile.folder[baseIndex + i]); // always use short folder name + normalNameDisp(&gcodeRect[i], (uint8_t *)getFoldername(baseIndex + i)); // display folder name } // draw gcode files for (; (baseIndex + i < infoFile.folderCount + infoFile.fileCount) && (i < NUM_PER_PAGE); i++) { - restoreFilenameExtension(baseIndex + i - infoFile.folderCount); // restore filename extension if filename extension feature is disabled - - if (enterFolder(infoFile.file[baseIndex + i - infoFile.folderCount]) == false) // always use short filename for file path + // in order to properly access the file (e.g. for print thumbnail preview, printing etc.), FQDN short (not long) + // filename (filename extension must be restored, if previously hidden) must be used for the file path + // + if (enterFolder(restoreFilenameExtension(baseIndex + i - infoFile.folderCount)) == false) break; // if model preview bmp exists, display bmp directly without writing to flash @@ -99,8 +105,8 @@ void gocdeIconDraw(void) exitFolder(); - hideFilenameExtension(baseIndex + i - infoFile.folderCount); // hide filename extension if filename extension feature is disabled - normalNameDisp(&gcodeRect[i], (uint8_t*)infoFile.file[baseIndex + i - infoFile.folderCount]); // always use short filename + // display filename hiding filename extension if filename extension feature is disabled + normalNameDisp(&gcodeRect[i], (uint8_t *)hideFilenameExtension(baseIndex + i - infoFile.folderCount)); } // clear blank icons @@ -119,14 +125,16 @@ void gocdeListDraw(LISTITEM * item, uint16_t index, uint8_t itemPos) item->icon = CHARICON_FOLDER; item->itemType = LIST_LABEL; item->titlelabel.index = LABEL_DYNAMIC; - setDynamicLabel(itemPos, getFoldername(index)); // display short or long folder name + setDynamicLabel(itemPos, (char *)getFoldername(index)); // display short or long folder name } else if (index < infoFile.folderCount + infoFile.fileCount) // gcode file { item->icon = CHARICON_FILE; item->itemType = LIST_LABEL; item->titlelabel.index = LABEL_DYNAMIC; - setDynamicLabel(itemPos, hideFilenameExtension(index - infoFile.folderCount)); // hide filename extension if filename extension feature is disabled + + // display short or long filename hiding filename extension if filename extension feature is disabled + setDynamicLabel(itemPos, (char *)hideFilenameExtension(index - infoFile.folderCount)); } } @@ -137,7 +145,10 @@ bool printPageItemSelected(uint16_t index) if (index < infoFile.folderCount) // folder { - if (enterFolder(infoFile.folder[index]) == false) // always use short folder name for file path + // in order to properly access the folder (e.g. for browsing its files and folders), short (not long) + // folder name must be used for the file path + // + if (enterFolder(infoFile.folder[index]) == false) { hasUpdate = false; } @@ -150,9 +161,14 @@ bool printPageItemSelected(uint16_t index) else if (index < infoFile.folderCount + infoFile.fileCount) // gcode file { infoFile.fileIndex = index - infoFile.folderCount; - char * filename = restoreFilenameExtension(infoFile.fileIndex); // restore filename extension if filename extension feature is disabled - if (infoHost.connected == false || enterFolder(infoFile.file[infoFile.fileIndex]) == false) // always use short filename for file path + // restore filename extension if filename extension feature is disabled + const char * filename = restoreFilenameExtension(infoFile.fileIndex); + + // in order to properly access the file (e.g. for print thumbnail preview, printing etc.), FQDN short (not long) + // filename (filename extension must be restored, if previously hidden) must be used for the file path + // + if (infoHost.connected == false || enterFolder(infoFile.file[infoFile.fileIndex]) == false) { hasUpdate = false; } @@ -207,14 +223,14 @@ void menuPrintFromSource(void) if (list_mode != true) { - printIconItems.title.address = (uint8_t*)infoFile.path; + printIconItems.title.address = (uint8_t *)infoFile.path; menuDrawPage(&printIconItems); } } else { if (infoFile.source == FS_ONBOARD_MEDIA) // error when the filesystem selected from TFT media not available - GUI_DispStringInRect(0, 0, LCD_WIDTH, LCD_HEIGHT, (uint8_t*)requestCommandInfo.cmd_rev_buf); + GUI_DispStringInRect(0, 0, LCD_WIDTH, LCD_HEIGHT, (uint8_t *)requestCommandInfo.cmd_rev_buf); else GUI_DispStringInRect(0, 0, LCD_WIDTH, LCD_HEIGHT, labelVolumeError[infoFile.source]); diff --git a/TFT/src/User/Menu/PrintRestore.c b/TFT/src/User/Menu/PrintRestore.c index ae62b641e2..ef0d29da90 100644 --- a/TFT/src/User/Menu/PrintRestore.c +++ b/TFT/src/User/Menu/PrintRestore.c @@ -33,7 +33,6 @@ void menuPrintRestore(void) case KEY_POPUP_CANCEL: powerFailedSetRestore(false); - // note: powerFailedExist function must be called first, otherwise powerFailedDelete will fail powerFailedDelete(); // in case the calling function is menuPrintFromSource, // remove the filename from path to allow the files scanning from its folder avoiding a scanning error message diff --git a/TFT/src/User/Menu/StatusScreen.h b/TFT/src/User/Menu/StatusScreen.h index a4f00074a3..ffecc99a47 100644 --- a/TFT/src/User/Menu/StatusScreen.h +++ b/TFT/src/User/Menu/StatusScreen.h @@ -10,15 +10,9 @@ extern "C" { extern const GUI_RECT msgRect; -void menuStatus(void); -void drawTemperature(void); -void storegantry(int n, float val); void statusScreen_setMsg(const uint8_t *title,const uint8_t *msg); void statusScreen_setReady(void); -void drawStatusScreenMsg(void); -float getAxisLocation(uint8_t n); -void gantry_dec(int n, float val); -void gantry_inc(int n, float val); +void menuStatus(void); #ifdef __cplusplus } diff --git a/TFT/src/User/my_misc.h b/TFT/src/User/my_misc.h index 56d3c929ef..2ce0a59e49 100644 --- a/TFT/src/User/my_misc.h +++ b/TFT/src/User/my_misc.h @@ -67,13 +67,13 @@ extern "C" { _Pragma("GCC error \"Error: strncpy() is deprecated! Use the alternatives like strncpy_pad() or strncpy_no_pad()\""); \ } while (0) -// call processes from the argument and than loopProcess() while condition is true +// call processes from the argument and than loopProcessAndGUI() 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(); \ + loopProcessAndGUI(); \ } uint8_t inRange(int cur, int tag , int range);