Skip to content

Commit

Permalink
Fix speed regression
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Nov 6, 2023
1 parent c59153a commit ee6c6e0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 61 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/buildTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Setup Python
uses: actions/setup-python@master
Expand All @@ -26,6 +31,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -U platformio
pip install --upgrade setuptools
- name: Build TFT24 V1.1
run: platformio run --environment BIGTREE_TFT24_V1_1
Expand Down
102 changes: 43 additions & 59 deletions TFT/src/User/API/comment.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#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)
{
Expand All @@ -17,90 +17,74 @@ void parseComment(void)
if (gCodeCommentLine[0] == '\0')
return;

// check for words starting with "l", "L", "r", "R", "t" or "T".
// - 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
//
// keywords if they do not start with the above mentioned letters.
if (strchr(KEYWORD_INTIALS, gCodeCommentLine[0]) != NULL)
{
char * token;
uint32_t token_value;

token = strlwr(strtok(gCodeCommentLine, TOKEN_DELIMITERS));
token = strToLwr(strtok(gCodeCommentLine, TOKEN_DELIMITERS));

// check for "layer" keyword in comment (layer number or layer count)
if (strcmp(token, "layer") == 0)
{
if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL)
token = strToLwr(strtok(NULL, TOKEN_DELIMITERS));

if (strcmp(token, "count") == 0) // check if next word is "count"
{
strlwr(token);

if (strcmp(token, "count") == 0) // check if next word is "count"
{
if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) // get the layer number
{
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);
}
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);
}
}

// 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"
{
if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL)
token = strToLwr(strtok(NULL, TOKEN_DELIMITERS));

if (strcmp(token, "elapsed") == 0 && getPrintExpectedTime() > 0) // check if next word is "elapsed"
{
strlwr(token);

if (strcmp(token, "elapsed") == 0 && getPrintExpectedTime() > 0) // check if next word is "elapsed"
{
if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL) // get the elapsed time in seconds
{
setPrintRemainingTime(getPrintExpectedTime() - strtoul(token, NULL, 0));
}
}
else if (NUMERIC(token[0])) // check if a number is found
{
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);
}
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
{
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);
}
}

// 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"
{
if ((token = strtok(NULL, TOKEN_DELIMITERS)) != NULL)
token = strToLwr(strtok(NULL, TOKEN_DELIMITERS));

if (strcmp(token, "time") == 0) // check if next word is "time"
{
strlwr(token);

if (strcmp(token, "time") == 0) // check if next word is "time"
{
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);
}
}
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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@
* Uncomment to enable a progress bar with 10% markers.
* Comment to enable a standard progress bar.
*/
#define MARKED_PROGRESS_BAR // Default: commented (disabled)
//#define MARKED_PROGRESS_BAR // Default: commented (disabled)

/**
* Live Text Common Color Layout (Status Screen menu)
Expand Down
30 changes: 30 additions & 0 deletions TFT/src/User/my_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stddef.h>

#define CRC_POLY 0xA001
#define HIGH_TO_LOW_CASE 32 // 'a' - 'A'

uint8_t inRange(int cur, int tag , int range)
{
Expand Down Expand Up @@ -174,6 +175,35 @@ double strtod_ligth(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;
}


// light weight and safe strncpy() function with padding:
// - copy "src" to "dest" for a maximum of "n-1" characters
// - if null terminating character is found in "src" the rest in "dest" is padded with '\0'
Expand Down
5 changes: 5 additions & 0 deletions TFT/src/User/my_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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

Expand Down Expand Up @@ -91,6 +93,9 @@ double strtod_ligth(char *str, char **endptr); // light weight str
void strncpy_pad(char *dest, const char *src, size_t n); // light weight and safe strncpy() function with padding
void strncpy_no_pad(char *dest, const char *src, size_t n); // light weight and safe strncpy() function without padding

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

const char *stripHead(const char *str); // strip out any leading " ", "/" or ":" character that might be in the string
void stripChecksum(char *str); // strip out any trailing checksum that might be in the string
uint8_t getChecksum(char *str);
Expand Down

0 comments on commit ee6c6e0

Please sign in to comment.