Skip to content

Commit

Permalink
More size reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Jul 22, 2023
1 parent 01da6d1 commit 30e3758
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 184 deletions.
2 changes: 1 addition & 1 deletion TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ 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();

Expand Down
3 changes: 2 additions & 1 deletion TFT/src/User/API/ModeSwitching.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void Mode_Switch(void)
LOGO_ReadDisplay();
updateNextHeatCheckTime(); // send "M105" after a delay, because of mega2560 will be hanged when received data at startup

TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME) // display logo BTT_BOOTSCREEN_TIME ms
// display logo BTT_BOOTSCREEN_TIME ms
TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME);

heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS);
modeFreshBoot = false;
Expand Down
102 changes: 48 additions & 54 deletions TFT/src/User/API/Notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
const GUI_RECT toastRect = {START_X + TITLE_END_Y - (TOAST_Y_PAD * 2), TOAST_Y_PAD, LCD_WIDTH - START_X, TITLE_END_Y - TOAST_Y_PAD};
const GUI_RECT toastIconRect = {START_X, TOAST_Y_PAD, START_X + TITLE_END_Y - (TOAST_Y_PAD * 2), TITLE_END_Y - TOAST_Y_PAD};

// toast notification variables
static TOAST toastlist[TOAST_MSG_COUNT];
static struct
{
DIALOG_TYPE style;
uint8_t isNew;
char text[TOAST_MSG_LENGTH];
} toastlist[TOAST_MSG_COUNT];

static uint8_t nextToastIndex = 0; // next index to store new toast
static uint8_t curToastDisplay = 0; // current toast notification being displayed
Expand All @@ -24,11 +28,9 @@ void addToast(DIALOG_TYPE style, char * text)
{
LCD_WAKE();

TOAST t;
strncpy_no_pad(t.text, text, TOAST_MSG_LENGTH);
t.style = style;
t.isNew = true;
toastlist[nextToastIndex] = t;
strncpy_no_pad(toastlist[nextToastIndex].text, text, TOAST_MSG_LENGTH);
toastlist[nextToastIndex].style = style;
toastlist[nextToastIndex].isNew = true;
nextToastIndex = (nextToastIndex + 1) % TOAST_MSG_COUNT;
}

Expand All @@ -41,7 +43,7 @@ bool toastRunning(void)
// check if any new notification is available
static bool toastAvailable(void)
{
for (int i = 0; i < TOAST_MSG_COUNT; i++)
for (uint8_t i = 0; i < TOAST_MSG_COUNT; i++)
{
if (toastlist[i].isNew == true)
return true;
Expand All @@ -62,29 +64,35 @@ void drawToast(bool redraw)

// draw icon
uint8_t *icon;
uint8_t cursound;
if (toastlist[curToastDisplay].style == DIALOG_TYPE_ERROR)
{
GUI_SetColor(NOTIF_ICON_ERROR_BG_COLOR);
icon = IconCharSelect(CHARICON_ERROR);
cursound = SOUND_ERROR;
}
else if (toastlist[curToastDisplay].style == DIALOG_TYPE_SUCCESS)
SOUND cursound;

switch (toastlist[curToastDisplay].style)
{
GUI_SetColor(NOTIF_ICON_SUCCESS_BG_COLOR);
icon = IconCharSelect(CHARICON_OK_ROUND);
cursound = SOUND_SUCCESS;
case DIALOG_TYPE_ERROR:
GUI_SetColor(NOTIF_ICON_ERROR_BG_COLOR);
icon = IconCharSelect(CHARICON_ERROR);
cursound = SOUND_ERROR;
break;

case DIALOG_TYPE_SUCCESS:
GUI_SetColor(NOTIF_ICON_SUCCESS_BG_COLOR);
icon = IconCharSelect(CHARICON_OK_ROUND);
cursound = SOUND_SUCCESS;
break;

default:
GUI_SetColor(NOTIF_ICON_INFO_BG_COLOR);
icon = IconCharSelect(CHARICON_INFO);
cursound = SOUND_TOAST;
break;
}
else

if (!redraw) // if notification is new
{
GUI_SetColor(NOTIF_ICON_INFO_BG_COLOR);
icon = IconCharSelect(CHARICON_INFO);
cursound = SOUND_TOAST;
BUZZER_PLAY(cursound); // play sound
nextToastTime = OS_GetTimeMs() + SEC_TO_MS(TOAST_DURATION); // set new timer
}

if (cursound >= 0 && !redraw)
BUZZER_PLAY(cursound);

GUI_SetTextMode(GUI_TEXTMODE_TRANS);
GUI_FillPrect(&toastIconRect);
GUI_SetColor(NOTIF_ICON_FG_COLOR);
Expand All @@ -99,21 +107,14 @@ void drawToast(bool redraw)
// set current toast notification as old/completed
toastlist[curToastDisplay].isNew = false;

// set new timer if notification is new
if (!redraw)
nextToastTime = OS_GetTimeMs() + SEC_TO_MS(TOAST_DURATION);

GUI_RestoreColorDefault();
}
}

// check and control toast notification display
void loopToast(void)
{
if (getMenuType() == MENU_TYPE_FULLSCREEN)
return;

if (OS_GetTimeMs() > nextToastTime)
if (getMenuType() != MENU_TYPE_FULLSCREEN && OS_GetTimeMs() > nextToastTime)
{
if (toastAvailable())
{
Expand All @@ -130,36 +131,32 @@ void loopToast(void)
}

// add new message to notification queue
void addNotification(DIALOG_TYPE style, char *title, char *text, bool ShowDialog)
void addNotification(DIALOG_TYPE style, char *title, char *text, bool draw_dialog)
{
LCD_WAKE();

if (nextMsgIndex > MAX_MSG_COUNT - 1)
if (nextMsgIndex >= MAX_MSG_COUNT)
{
// remove oldest message and move all messages up one step
for (int i = 0; i < MAX_MSG_COUNT - 1; i++)
{
memcpy(&msglist[i], &msglist[i + 1], sizeof(NOTIFICATION));
}
memmove(msglist, &msglist[1], (MAX_MSG_COUNT - 1) * (sizeof(NOTIFICATION)));
nextMsgIndex = MAX_MSG_COUNT - 1;
}

// store message
msglist[nextMsgIndex].style = style;
msglist[nextMsgIndex].style = style;
strncpy_no_pad(msglist[nextMsgIndex].text, text, MAX_MSG_LENGTH);
strncpy_no_pad(msglist[nextMsgIndex].title, title, MAX_MSG_TITLE_LENGTH);
nextMsgIndex++;

if (ShowDialog && MENU_IS_NOT(menuNotification))
popupReminder(style, (uint8_t *)title, (uint8_t *)msglist[nextMsgIndex].text);

if (nextMsgIndex < MAX_MSG_COUNT) nextMsgIndex += 1; //(nextMsgIndex + 1) % MAX_MSG_COUNT;
if (draw_dialog && MENU_IS_NOT(menuNotification))
popupReminder(style, (uint8_t *)title, (uint8_t *)text);

if (notificationHandler != NULL)
notificationHandler();

notificationDot();

statusScreen_setMsg((uint8_t *)title, (uint8_t *)text);
statusScreenSetMsg((uint8_t *)title, (uint8_t *)text);
}

// replay a notification
Expand All @@ -172,30 +169,27 @@ void replayNotification(uint8_t index)
// retrieve a stored notification
NOTIFICATION *getNotification(uint8_t index)
{
if (strlen(msglist[index].title) > 0 && strlen(msglist[index].text) > 0)
if (msglist[index].title[0] != '\0' && msglist[index].text[0] != '\0')
return &msglist[index];
else
return NULL;
}

bool hasNotification(void)
{
if (nextMsgIndex == 0)
return false;
else
return true;
return (nextMsgIndex != 0);
}

void clearNotification(void)
{
nextMsgIndex = 0;
for (int i = 0; i < MAX_MSG_COUNT; i++)
{
msglist[i].text[0] = 0;
msglist[i].title[0] = 0;
msglist[i].text[0] = '\0';
msglist[i].title[0] = '\0';
}
notificationDot();
statusScreen_setReady();
statusScreenSetReady();
}

// check if pressed on titlebar area
Expand Down
7 changes: 0 additions & 7 deletions TFT/src/User/API/Notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ extern "C" {
#define MAX_MSG_TITLE_LENGTH 15
#define MAX_MSG_LENGTH 70

typedef struct
{
DIALOG_TYPE style;
uint8_t isNew;
char text[TOAST_MSG_LENGTH];
} TOAST;

typedef struct
{
DIALOG_TYPE style;
Expand Down
3 changes: 2 additions & 1 deletion TFT/src/User/API/ProbeOffsetControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void probeOffsetEnable(float shim)
{
levelingProbePoint(LEVEL_CENTER); // probe center of bed

TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT) // if probed Z is set, exit from loop and read probed Z
// if probed Z is set, exit from loop and read probed Z
TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT);

probedZ = levelingGetProbedZ();
levelingResetProbedPoint(); // reset to check for new updates
Expand Down
6 changes: 3 additions & 3 deletions TFT/src/User/API/RRFParseACK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ void ParseACKJsonParser::value(const char *value)
{
setupMachine(FW_REPRAPFW);
string_end = strstr(string_start, "ELECTRONICS");
infoSetFirmwareName((uint8_t *)string_start, string_end-string_start);
infoSetFirmwareName(string_start, string_end-string_start);
}
else if ((string_start = strstr(value, (char *)"access point")) != NULL) // parse M552
{
string_end = strstr(string_start, ",");
string_start += 13;
infoSetAccessPoint((uint8_t *)string_start, string_end-string_start);
infoSetAccessPoint(string_start, string_end-string_start);

if ((string_start = strstr(string_start, (char *)"IP address")) != NULL)
{
string_end = strstr(string_start, "\\n");
string_start += 11;
infoSetIPAddress((uint8_t *)string_start, string_end-string_start);
infoSetIPAddress(string_start, string_end-string_start);
}
}
else if ((string_start = strstr(value, (char *)"printing byte")) != NULL) // parse M27 {"seq":21,"resp":"SD printing byte 1226/5040433\n"}
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ void sendQueueCmd(void)
stripChecksum(rawMsg);
msgText = stripHead(rawMsg);

statusScreen_setMsg((uint8_t *)"M117", (uint8_t *)msgText);
statusScreenSetMsg((uint8_t *)"M117", (uint8_t *)msgText);

if (MENU_IS_NOT(menuStatus))
addToast(DIALOG_TYPE_INFO, (char *)msgText);
Expand Down
14 changes: 10 additions & 4 deletions TFT/src/User/API/parseACK.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static void __attribute__ ((noinline)) hostActionCommands(void)
}
else
{
statusScreen_setMsg((uint8_t *)magic_echo, (uint8_t *)ack_cache + index); // always display the notification on status screen
statusScreenSetMsg((uint8_t *)magic_echo, (uint8_t *)ack_cache + index); // always display the notification on status screen

if (!ack_continue_seen("Ready.")) // avoid to display unneeded/frequent useless notifications (e.g. "My printer Ready.")
{
Expand Down Expand Up @@ -882,6 +882,12 @@ void parseACK(void)
if (ack_continue_seen("Z: "))
levelingSetProbedPoint(x, y, ack_value()); // save probed Z value
}
// parse G30 coordinate unreachable message
else if (ack_seen("Z Probe Past Bed"))
{
levelingSetProbedPoint(infoSettings.machine_size_max[1] + 1, infoSettings.machine_size_max[2] + 1, 0); // cancel waiting for coordinates
BUZZER_PLAY(SOUND_ERROR);
}
#if DELTA_PROBE_TYPE != 0
// parse and store Delta calibration settings
else if (ack_seen("Calibration OK"))
Expand Down Expand Up @@ -1160,7 +1166,7 @@ void parseACK(void)
// parse M115 capability report
else if (ack_seen("FIRMWARE_NAME:"))
{
uint8_t * string = (uint8_t *)&ack_cache[ack_index];
char * string = &ack_cache[ack_index];
uint16_t string_start = ack_index;
uint16_t string_end = string_start;

Expand All @@ -1182,7 +1188,7 @@ void parseACK(void)

if (ack_seen("MACHINE_TYPE:"))
{
string = (uint8_t *)&ack_cache[ack_index];
string = &ack_cache[ack_index];
string_start = ack_index;

if (ack_seen("EXTRUDER_COUNT:"))
Expand All @@ -1193,7 +1199,7 @@ void parseACK(void)
string_end = ack_index - sizeof("EXTRUDER_COUNT:");
}

infoSetMachineType(string, string_end - string_start); // set firmware name
infoSetMachineType(string, string_end - string_start); // set printer name
}
}
else if (ack_starts_with("Cap:"))
Expand Down
Loading

0 comments on commit 30e3758

Please sign in to comment.