diff --git a/TFT/src/User/API/comment.c b/TFT/src/User/API/comment.c index 874e9cf378..969419f236 100644 --- a/TFT/src/User/API/comment.c +++ b/TFT/src/User/API/comment.c @@ -1,12 +1,11 @@ #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; +static bool slicerTimePresence = false; void setTimeFromSlicer(bool present) { @@ -18,94 +17,76 @@ 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 = strToLwr(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) - { // check for "layer" keyword in comment (layer number or layer count) - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); - - if (strcmp(temp_char, "count") == 0) // check if next word is "count" - { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - temp_value = strtoul(temp_char, NULL, 0); - - if (temp_value != 0) - setPrintLayerCount(temp_value); - } - else if (NUMERIC(temp_char[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 - // 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); - } + token = strToLwr(strtok(NULL, TOKEN_DELIMITERS)); + + if (strcmp(token, "count") == 0) // check if next word is "count" + { + token = strtok(NULL, TOKEN_DELIMITERS); + token_value = strtoul(token, NULL, 0); + + if (token_value != 0) + setPrintLayerCount(token_value); + } + else if (NUMERIC(token[0])) // check if a number is found + { + 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(((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" + token = strToLwr(strtok(NULL, TOKEN_DELIMITERS)); + + if (strcmp(token, "elapsed") == 0 && getPrintExpectedTime() > 0) // check if next word is "elapsed" + { + token = strtok(NULL, TOKEN_DELIMITERS); + token_value = strtoul(token, NULL, 0); // get the elapsed time in seconds + setPrintRemainingTime(getPrintExpectedTime() - token_value); + } + else if (NUMERIC(token[0])) // check if a number is found { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); - - if (strcmp(temp_char, "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); - } - else if (temp_char[0] >= '0' && temp_char[0] <= '9') // check if a number is found - { - setPrintExpectedTime(strtoul(temp_char, NULL, 0)); - setPrintRemainingTime(getPrintExpectedTime()); - - if (getPrintProgressSource() < PROG_TIME && infoSettings.prog_source == 1) - setPrintProgressSource(PROG_TIME); - } + 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" + token = strToLwr(strtok(NULL, TOKEN_DELIMITERS)); + + if (strcmp(token, "time") == 0) // check if next word is "time" { - temp_char = strtok(NULL, TOKEN_DELIMITERS); - strlwr(temp_char); - - if (strcmp(temp_char, "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 (getPrintProgressSource() < PROG_TIME && infoSettings.prog_source == 1) - setPrintProgressSource(PROG_TIME); - } + token = strtok(NULL, TOKEN_DELIMITERS); + token_value = strtoul(token, NULL, 0); // get the remaining time in seconds + 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 "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/Menu/Extrude.c b/TFT/src/User/Menu/Extrude.c index dcfe63b814..e4eb6b85f0 100644 --- a/TFT/src/User/Menu/Extrude.c +++ b/TFT/src/User/Menu/Extrude.c @@ -18,7 +18,7 @@ void menuExtrude(void) {ICON_NULL, LABEL_NULL}, {ICON_NULL, LABEL_NULL}, {ICON_LOAD, LABEL_LOAD}, - {ICON_NULL, LABEL_NULL}, + {ICON_HEAT, LABEL_HEAT}, {ICON_E_5_MM, LABEL_5_MM}, {ICON_NORMAL_SPEED, LABEL_NORMAL}, {ICON_BACK, LABEL_BACK}, @@ -29,8 +29,11 @@ void menuExtrude(void) float extrLength = 0.0f; float extrAmount = 0.0f; - extrudeItems.items[KEY_ICON_4].icon = (infoSettings.ext_count > 1) ? ICON_NOZZLE : ICON_HEAT; - extrudeItems.items[KEY_ICON_4].label.index = (infoSettings.ext_count > 1) ? LABEL_NOZZLE : LABEL_HEAT; + if (infoSettings.ext_count > 1) + { + extrudeItems.items[KEY_ICON_4].icon = ICON_NOZZLE; + extrudeItems.items[KEY_ICON_4].label.index = LABEL_NOZZLE; + } extrudeItems.items[KEY_ICON_5] = itemExtLenSteps[extlenSteps_index]; extrudeItems.items[KEY_ICON_6] = itemSpeed[itemSpeed_index]; diff --git a/TFT/src/User/my_misc.c b/TFT/src/User/my_misc.c index d8ba85b533..2e6491d0d1 100644 --- a/TFT/src/User/my_misc.c +++ b/TFT/src/User/my_misc.c @@ -6,6 +6,7 @@ #include #define CRC_POLY 0xA001 +#define HIGH_TO_LOW_CASE 32 // 'a' - 'A' uint8_t inRange(int cur, int tag , int range) { @@ -166,6 +167,35 @@ double stringToDouble(char *str, char **endptr) return val * sign; } +// converts a string to lower case, returns the pointer of said string +char * strToLwr(char * string) +{ + char * tmp_str = string; + while (*tmp_str != '\0') + { + if (UPPER_CASE(*tmp_str)) + *tmp_str |= HIGH_TO_LOW_CASE; + tmp_str++; + } + + return string; +} + +// converts a string to upper case, returns the pointer of said string +char * strToUpr(char * string) +{ + char * tmp_str = string; + while (*tmp_str != '\0') + { + if (LOWER_CASE(*tmp_str)) + *tmp_str &= ~HIGH_TO_LOW_CASE; + tmp_str++; + } + + return string; +} + + // convert time to string with given formatting void timeToString(char *buf, char *strFormat, uint32_t time) { diff --git a/TFT/src/User/my_misc.h b/TFT/src/User/my_misc.h index 7c9fdcc55a..9e678adaa9 100644 --- a/TFT/src/User/my_misc.h +++ b/TFT/src/User/my_misc.h @@ -28,6 +28,8 @@ extern "C" { #define WITHIN(N, L, H) ((N) >= (L) && (N) <= (H)) #define NUMERIC(a) WITHIN(a, '0', '9') +#define LOWER_CASE(c) WITHIN(c, 'a', 'z') +#define UPPER_CASE(c) WITHIN(c, 'A', 'Z') // Bitwise macros @@ -71,6 +73,8 @@ uint8_t *uint8_2_string(uint8_t num, uint8_t *string); uint32_t string_2_uint32(const uint8_t *string, const uint8_t bytes_num); uint8_t *uint32_2_string(uint32_t num, uint8_t bytes_num, uint8_t *string); double stringToDouble(char *str, char **endptr); +char * strToLwr(char * string); // converts a string to lower case, returns the pointer of said string +char * strToUpr(char * string); // converts a string to upper case, returns the pointer of said string void timeToString(char *buf, char *strFormat, uint32_t time); const char *stripHead(const char *str); // strip out any leading " ", "/" or ":" character that might be in the string