Skip to content

Commit

Permalink
More size reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand committed Sep 27, 2023
1 parent b440c7e commit bbc9449
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 181 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 @@ -300,7 +300,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
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
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 @@ -1000,7 +1000,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 @@ -927,6 +927,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 @@ -1205,7 +1211,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 @@ -1227,7 +1233,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 @@ -1238,7 +1244,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
58 changes: 19 additions & 39 deletions TFT/src/User/Menu/LevelCorner.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "LevelCorner.h"
#include "includes.h"

const uint8_t valIconIndex[LEVELING_POINT_COUNT] = {4, 5, 1, 0, 3};
const uint8_t valIconIndex[LEVELING_POINT_COUNT] = {KEY_ICON_4, KEY_ICON_5, KEY_ICON_1, KEY_ICON_0, KEY_ICON_3};

// buffer current Z value measured in Level Corner = {position 1, position 2, position 3, position 4, probe accuracy(M48)}
float levelCornerPosition[LEVELING_POINT_COUNT] = {0};
Expand Down Expand Up @@ -37,19 +37,6 @@ static void refreshValue(MENUITEMS * levelItems, uint8_t index)
menuDrawIconText(&levelItems->items[valIconIndex[index]], valIconIndex[index]);
}

static void checkRefreshValue(MENUITEMS * levelItems)
{
LEVELING_POINT levelingPoint = levelingGetProbedPoint();

if (levelingPoint != LEVEL_NO_POINT)
{
levelCornerPosition[levelingPoint] = levelingGetProbedZ();
refreshValue(levelItems, levelingPoint);

levelingResetProbedPoint(); // reset to check for new updates
}
}

// show M48 on icon
static void drawProbeAccuracyIcon(MENUITEMS * levelItems)
{
Expand Down Expand Up @@ -129,11 +116,25 @@ void menuLevelCorner(void)
switch (key_num)
{
case KEY_ICON_0:
levelingProbePoint(LEVEL_TOP_LEFT);
break;

case KEY_ICON_1:
levelingProbePoint(LEVEL_TOP_RIGHT);
case KEY_ICON_4:
case KEY_ICON_5:
case KEY_ICON_6:
for (int lvlPoint = LEVEL_BOTTOM_LEFT; lvlPoint <= LEVEL_TOP_LEFT; lvlPoint++)
{
if (key_num < KEY_ICON_6 && key_num != valIconIndex[lvlPoint])
continue;

levelingProbePoint(lvlPoint);

// wait until point probing is executed
TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT);

levelCornerPosition[lvlPoint] = levelingGetProbedZ();
refreshValue(&levelCornerItems, lvlPoint);
levelingResetProbedPoint(); // reset to check for new updates
}

break;

case KEY_ICON_2:
Expand All @@ -155,25 +156,6 @@ void menuLevelCorner(void)
drawProbeAccuracyIcon(&levelCornerItems);
break;

case KEY_ICON_4:
levelingProbePoint(LEVEL_BOTTOM_LEFT);
break;

case KEY_ICON_5:
levelingProbePoint(LEVEL_BOTTOM_RIGHT);
break;

case KEY_ICON_6:
for (int i = LEVEL_BOTTOM_LEFT; i <= LEVEL_TOP_LEFT; i++)
{
levelingProbePoint(i);

// following loop needed to guarantee the value for each point beeing probed is updated at least one time on the menu
TASK_LOOP_WHILE(isNotEmptyCmdQueue(), checkRefreshValue(&levelCornerItems));
}

break;

case KEY_ICON_7:
infoSettings.level_edge = origLevelEdge; // restore original leveling edge value
origLevelEdge = -1;
Expand All @@ -185,7 +167,5 @@ void menuLevelCorner(void)
}

loopProcess();

checkRefreshValue(&levelCornerItems);
}
}
Loading

0 comments on commit bbc9449

Please sign in to comment.