Skip to content

Commit 70ca669

Browse files
committed
Size reduction
1 parent 151ce1b commit 70ca669

17 files changed

+131
-180
lines changed

TFT/src/User/API/Gcode/gcode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void request_M98(const char * filename)
260260
mustStoreCmd(command);
261261

262262
// prevent a race condition when rrfStatusQuery returns !busy before executing the macro
263-
TASK_LOOP_WHILE(isEnqueued(command))
263+
TASK_LOOP_WHILE(isEnqueued(command));
264264

265265
rrfStatusQueryFast();
266266

TFT/src/User/API/ModeSwitching.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ void Mode_Switch(void)
3535
LOGO_ReadDisplay();
3636
updateNextHeatCheckTime(); // send "M105" after a delay, because of mega2560 will be hanged when received data at startup
3737

38-
TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME) // display logo BTT_BOOTSCREEN_TIME ms
38+
// display logo BTT_BOOTSCREEN_TIME ms
39+
TASK_LOOP_WHILE(OS_GetTimeMs() - startUpTime < BTT_BOOTSCREEN_TIME);
3940

4041
heatSetUpdateSeconds(TEMPERATURE_QUERY_SLOW_SECONDS);
4142
modeFreshBoot = false;

TFT/src/User/API/Notification.c

+48-54
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
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};
77
const GUI_RECT toastIconRect = {START_X, TOAST_Y_PAD, START_X + TITLE_END_Y - (TOAST_Y_PAD * 2), TITLE_END_Y - TOAST_Y_PAD};
88

9-
// toast notification variables
10-
static TOAST toastlist[TOAST_MSG_COUNT];
9+
static struct
10+
{
11+
DIALOG_TYPE style;
12+
uint8_t isNew;
13+
char text[TOAST_MSG_LENGTH];
14+
} toastlist[TOAST_MSG_COUNT];
1115

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

27-
TOAST t;
28-
strscpy(t.text, text, TOAST_MSG_LENGTH);
29-
t.style = style;
30-
t.isNew = true;
31-
toastlist[nextToastIndex] = t;
31+
strscpy(toastlist[nextToastIndex].text, text, TOAST_MSG_LENGTH);
32+
toastlist[nextToastIndex].style = style;
33+
toastlist[nextToastIndex].isNew = true;
3234
nextToastIndex = (nextToastIndex + 1) % TOAST_MSG_COUNT;
3335
}
3436

@@ -41,7 +43,7 @@ bool toastRunning(void)
4143
// check if any new notification is available
4244
bool toastAvailable(void)
4345
{
44-
for (int i = 0; i < TOAST_MSG_COUNT; i++)
46+
for (uint8_t i = 0; i < TOAST_MSG_COUNT; i++)
4547
{
4648
if (toastlist[i].isNew == true)
4749
return true;
@@ -62,29 +64,35 @@ void drawToast(bool redraw)
6264

6365
// draw icon
6466
uint8_t *icon;
65-
uint8_t cursound;
66-
if (toastlist[curToastDisplay].style == DIALOG_TYPE_ERROR)
67-
{
68-
GUI_SetColor(NOTIF_ICON_ERROR_BG_COLOR);
69-
icon = IconCharSelect(CHARICON_ERROR);
70-
cursound = SOUND_ERROR;
71-
}
72-
else if (toastlist[curToastDisplay].style == DIALOG_TYPE_SUCCESS)
67+
SOUND cursound;
68+
69+
switch (toastlist[curToastDisplay].style)
7370
{
74-
GUI_SetColor(NOTIF_ICON_SUCCESS_BG_COLOR);
75-
icon = IconCharSelect(CHARICON_OK_ROUND);
76-
cursound = SOUND_SUCCESS;
71+
case DIALOG_TYPE_ERROR:
72+
GUI_SetColor(NOTIF_ICON_ERROR_BG_COLOR);
73+
icon = IconCharSelect(CHARICON_ERROR);
74+
cursound = SOUND_ERROR;
75+
break;
76+
77+
case DIALOG_TYPE_SUCCESS:
78+
GUI_SetColor(NOTIF_ICON_SUCCESS_BG_COLOR);
79+
icon = IconCharSelect(CHARICON_OK_ROUND);
80+
cursound = SOUND_SUCCESS;
81+
break;
82+
83+
default:
84+
GUI_SetColor(NOTIF_ICON_INFO_BG_COLOR);
85+
icon = IconCharSelect(CHARICON_INFO);
86+
cursound = SOUND_TOAST;
87+
break;
7788
}
78-
else
89+
90+
if (!redraw) // if notification is new
7991
{
80-
GUI_SetColor(NOTIF_ICON_INFO_BG_COLOR);
81-
icon = IconCharSelect(CHARICON_INFO);
82-
cursound = SOUND_TOAST;
92+
BUZZER_PLAY(cursound); // play sound
93+
nextToastTime = OS_GetTimeMs() + SEC_TO_MS(TOAST_DURATION); // set new timer
8394
}
8495

85-
if (cursound >= 0 && !redraw)
86-
BUZZER_PLAY(cursound);
87-
8896
GUI_SetTextMode(GUI_TEXTMODE_TRANS);
8997
GUI_FillPrect(&toastIconRect);
9098
GUI_SetColor(NOTIF_ICON_FG_COLOR);
@@ -99,21 +107,14 @@ void drawToast(bool redraw)
99107
// set current toast notification as old/completed
100108
toastlist[curToastDisplay].isNew = false;
101109

102-
// set new timer if notification is new
103-
if (!redraw)
104-
nextToastTime = OS_GetTimeMs() + SEC_TO_MS(TOAST_DURATION);
105-
106110
GUI_RestoreColorDefault();
107111
}
108112
}
109113

110114
// check and control toast notification display
111115
void loopToast(void)
112116
{
113-
if (getMenuType() == MENU_TYPE_FULLSCREEN)
114-
return;
115-
116-
if (OS_GetTimeMs() > nextToastTime)
117+
if (getMenuType() != MENU_TYPE_FULLSCREEN && OS_GetTimeMs() > nextToastTime)
117118
{
118119
if (toastAvailable())
119120
{
@@ -130,36 +131,32 @@ void loopToast(void)
130131
}
131132

132133
// add new message to notification queue
133-
void addNotification(DIALOG_TYPE style, char *title, char *text, bool ShowDialog)
134+
void addNotification(DIALOG_TYPE style, char *title, char *text, bool draw_dialog)
134135
{
135136
LCD_WAKE();
136137

137-
if (nextMsgIndex > MAX_MSG_COUNT - 1)
138+
if (nextMsgIndex >= MAX_MSG_COUNT)
138139
{
139140
// remove oldest message and move all messages up one step
140-
for (int i = 0; i < MAX_MSG_COUNT - 1; i++)
141-
{
142-
memcpy(&msglist[i], &msglist[i + 1], sizeof(NOTIFICATION));
143-
}
141+
memmove(msglist, &msglist[1], (MAX_MSG_COUNT - 1) * (sizeof(NOTIFICATION)));
144142
nextMsgIndex = MAX_MSG_COUNT - 1;
145143
}
146144

147145
// store message
148-
msglist[nextMsgIndex].style = style;
146+
msglist[nextMsgIndex].style = style;
149147
strscpy(msglist[nextMsgIndex].text, text, MAX_MSG_LENGTH);
150148
strscpy(msglist[nextMsgIndex].title, title, MAX_MSG_TITLE_LENGTH);
149+
nextMsgIndex++;
151150

152-
if (ShowDialog && MENU_IS_NOT(menuNotification))
153-
popupReminder(style, (uint8_t *)title, (uint8_t *)msglist[nextMsgIndex].text);
154-
155-
if (nextMsgIndex < MAX_MSG_COUNT) nextMsgIndex += 1; //(nextMsgIndex + 1) % MAX_MSG_COUNT;
151+
if (draw_dialog && MENU_IS_NOT(menuNotification))
152+
popupReminder(style, (uint8_t *)title, (uint8_t *)text);
156153

157154
if (notificationHandler != NULL)
158155
notificationHandler();
159156

160157
notificationDot();
161158

162-
statusScreen_setMsg((uint8_t *)title, (uint8_t *)text);
159+
statusScreenSetMsg((uint8_t *)title, (uint8_t *)text);
163160
}
164161

165162
// replay a notification
@@ -172,30 +169,27 @@ void replayNotification(uint8_t index)
172169
// retrieve a stored notification
173170
NOTIFICATION *getNotification(uint8_t index)
174171
{
175-
if (strlen(msglist[index].title) > 0 && strlen(msglist[index].text) > 0)
172+
if (msglist[index].title[0] != '\0' && msglist[index].text[0] != '\0')
176173
return &msglist[index];
177174
else
178175
return NULL;
179176
}
180177

181178
bool hasNotification(void)
182179
{
183-
if (nextMsgIndex == 0)
184-
return false;
185-
else
186-
return true;
180+
return (nextMsgIndex != 0);
187181
}
188182

189183
void clearNotification(void)
190184
{
191185
nextMsgIndex = 0;
192186
for (int i = 0; i < MAX_MSG_COUNT; i++)
193187
{
194-
msglist[i].text[0] = 0;
195-
msglist[i].title[0] = 0;
188+
msglist[i].text[0] = '\0';
189+
msglist[i].title[0] = '\0';
196190
}
197191
notificationDot();
198-
statusScreen_setReady();
192+
statusScreenSetReady();
199193
}
200194

201195
// check if pressed on titlebar area

TFT/src/User/API/Notification.h

-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ extern "C" {
2020
#define MAX_MSG_TITLE_LENGTH 15
2121
#define MAX_MSG_LENGTH 70
2222

23-
typedef struct
24-
{
25-
DIALOG_TYPE style;
26-
uint8_t isNew;
27-
char text[TOAST_MSG_LENGTH];
28-
} TOAST;
29-
3023
typedef struct
3124
{
3225
DIALOG_TYPE style;

TFT/src/User/API/ProbeOffsetControl.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void probeOffsetEnable(float shim)
2020
{
2121
levelingProbePoint(LEVEL_CENTER); // probe center of bed
2222

23-
TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT) // if probed Z is set, exit from loop and read probed Z
23+
// if probed Z is set, exit from loop and read probed Z
24+
TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT);
2425

2526
probedZ = levelingGetProbedZ();
2627
levelingResetProbedPoint(); // reset to check for new updates

TFT/src/User/API/RRFParseACK.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,19 @@ void ParseACKJsonParser::value(const char *value)
209209
{
210210
setupMachine(FW_REPRAPFW);
211211
string_end = strstr(string_start, "ELECTRONICS");
212-
infoSetFirmwareName((uint8_t *)string_start, string_end-string_start);
212+
infoSetFirmwareName(string_start, string_end-string_start);
213213
}
214214
else if ((string_start = strstr(value, (char *)"access point")) != NULL) // parse M552
215215
{
216216
string_end = strstr(string_start, ",");
217217
string_start += 13;
218-
infoSetAccessPoint((uint8_t *)string_start, string_end-string_start);
218+
infoSetAccessPoint(string_start, string_end-string_start);
219219

220220
if ((string_start = strstr(string_start, (char *)"IP address")) != NULL)
221221
{
222222
string_end = strstr(string_start, "\\n");
223223
string_start += 11;
224-
infoSetIPAddress((uint8_t *)string_start, string_end-string_start);
224+
infoSetIPAddress(string_start, string_end-string_start);
225225
}
226226
}
227227
else if ((string_start = strstr(value, (char *)"printing byte")) != NULL) // parse M27 {"seq":21,"resp":"SD printing byte 1226/5040433\n"}

TFT/src/User/API/interfaceCmd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ void sendQueueCmd(void)
998998
stripChecksum(rawMsg);
999999
msgText = stripHead(rawMsg);
10001000

1001-
statusScreen_setMsg((uint8_t *)"M117", (uint8_t *)msgText);
1001+
statusScreenSetMsg((uint8_t *)"M117", (uint8_t *)msgText);
10021002

10031003
if (MENU_IS_NOT(menuStatus))
10041004
addToast(DIALOG_TYPE_INFO, (char *)msgText);

TFT/src/User/API/parseACK.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void hostActionCommands(void)
262262
}
263263
else
264264
{
265-
statusScreen_setMsg((uint8_t *)magic_echo, (uint8_t *)ack_cache + index); // always display the notification on status screen
265+
statusScreenSetMsg((uint8_t *)magic_echo, (uint8_t *)ack_cache + index); // always display the notification on status screen
266266

267267
if (!ack_continue_seen("Ready.")) // avoid to display unneeded/frequent useless notifications (e.g. "My printer Ready.")
268268
{
@@ -882,6 +882,12 @@ void parseACK(void)
882882
if (ack_continue_seen("Z: "))
883883
levelingSetProbedPoint(x, y, ack_value()); // save probed Z value
884884
}
885+
// parse G30 coordinate unreachable message
886+
else if (ack_seen("Z Probe Past Bed"))
887+
{
888+
levelingSetProbedPoint(infoSettings.machine_size_max[1] + 1, infoSettings.machine_size_max[2] + 1, 0); // cancel waiting for coordinates
889+
BUZZER_PLAY(SOUND_ERROR);
890+
}
885891
#if DELTA_PROBE_TYPE != 0
886892
// parse and store Delta calibration settings
887893
else if (ack_seen("Calibration OK"))
@@ -1160,7 +1166,7 @@ void parseACK(void)
11601166
// parse M115 capability report
11611167
else if (ack_seen("FIRMWARE_NAME:"))
11621168
{
1163-
uint8_t * string = (uint8_t *)&ack_cache[ack_index];
1169+
char * string = &ack_cache[ack_index];
11641170
uint16_t string_start = ack_index;
11651171
uint16_t string_end = string_start;
11661172

@@ -1182,7 +1188,7 @@ void parseACK(void)
11821188

11831189
if (ack_seen("MACHINE_TYPE:"))
11841190
{
1185-
string = (uint8_t *)&ack_cache[ack_index];
1191+
string = &ack_cache[ack_index];
11861192
string_start = ack_index;
11871193

11881194
if (ack_seen("EXTRUDER_COUNT:"))
@@ -1193,7 +1199,7 @@ void parseACK(void)
11931199
string_end = ack_index - sizeof("EXTRUDER_COUNT:");
11941200
}
11951201

1196-
infoSetMachineType(string, string_end - string_start); // set firmware name
1202+
infoSetMachineType(string, string_end - string_start); // set printer name
11971203
}
11981204
}
11991205
else if (ack_starts_with("Cap:"))

0 commit comments

Comments
 (0)