Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another FW size reduction #2778

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More size reduction
  • Loading branch information
kisslorand committed Nov 7, 2023
commit e7d6a9338e1add824898efa0239e87ceb375f06a
100 changes: 47 additions & 53 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;
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 @@ -971,7 +971,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 @@ -263,7 +263,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 @@ -930,6 +930,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 @@ -1212,7 +1218,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 @@ -1234,7 +1240,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 @@ -1245,7 +1251,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
2 changes: 1 addition & 1 deletion TFT/src/User/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@
* Monitoring Debug
* Uncomment/Enable to monitor/show system resources usage in Monitoring menu.
*/
#define DEBUG_MONITORING // Default: commented (disabled)
//#define DEBUG_MONITORING // Default: commented (disabled)

/**
* Generic Debug
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