Skip to content

Commit

Permalink
cumulative patches + cleanup (#2873)
Browse files Browse the repository at this point in the history
* cumulative patches + cleanup
* fixed #2881 and wrong buffer allocation
* global fix on Level Corner menu
  • Loading branch information
digant73 committed Jan 15, 2024
1 parent 3779fa5 commit 156e04b
Show file tree
Hide file tree
Showing 51 changed files with 989 additions and 1,286 deletions.
4 changes: 2 additions & 2 deletions TFT/src/User/API/AddonHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool FIL_NormalRunoutDetect(void)
return runout;
}

bool FIL_SmartRunoutDetect(void)
static inline bool FIL_SmartRunoutDetect(void)
{
static float lastPosE = 0.0f;
static bool lastRunout = false;
Expand Down Expand Up @@ -203,7 +203,7 @@ bool FIL_SmartRunoutDetect(void)
return false;
}

bool FIL_IsRunout(void)
static inline bool FIL_IsRunout(void)
{
switch (GET_BIT(infoSettings.runout, RUNOUT_SENSOR_TYPE))
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool fanIsValid(const uint8_t index)
return false;
else if (!infoSettings.ctrl_fan_en && index >= MAX_COOLING_FAN_COUNT) // controller cooling fan is disabled
return false;
else if (index >= (MAX_COOLING_FAN_COUNT + MAX_CRTL_FAN_COUNT)) // invalid controller cooling fan index (not active/idle)
else if (index >= (MAX_COOLING_FAN_COUNT + MAX_CTRL_FAN_COUNT)) // invalid controller cooling fan index (not active/idle)
return false;
else
return true;
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/LevelingControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ float probedZ = 0.0f; // last Z offset measured by probe

int16_t setCoordValue(AXIS axis, ALIGN_POSITION align)
{
return ((align == LEFT || align == BOTTOM) ? infoSettings.machine_size_min[axis] + infoSettings.level_edge
: infoSettings.machine_size_max[axis] - infoSettings.level_edge) - infoParameters.HomeOffset[axis];
return (align == LEFT || align == BOTTOM) ? infoSettings.machine_size_min[axis] + infoSettings.level_edge
: infoSettings.machine_size_max[axis] - infoSettings.level_edge;
}

void levelingGetPointCoords(LEVELING_POINT_COORDS coords)
Expand Down
94 changes: 47 additions & 47 deletions TFT/src/User/API/Notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
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};

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

// toast notification variables
static TOAST toastlist[TOAST_MSG_COUNT];

Expand All @@ -24,11 +31,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 @@ -39,7 +44,7 @@ bool toastRunning(void)
}

// check if any new notification is available
bool toastAvailable(void)
static inline bool toastAvailable(void)
{
for (int i = 0; i < TOAST_MSG_COUNT; i++)
{
Expand All @@ -62,29 +67,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 +110,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,11 +134,11 @@ 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 drawDialog)
{
LCD_WAKE();

if (nextMsgIndex > MAX_MSG_COUNT - 1)
if (nextMsgIndex >= MAX_MSG_COUNT) // if no more available slots, skip the oldest notification
{
// remove oldest message and move all messages up one step
for (int i = 0; i < MAX_MSG_COUNT - 1; i++)
Expand All @@ -148,18 +152,17 @@ void addNotification(DIALOG_TYPE style, char *title, char *text, bool ShowDialog
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 (drawDialog && 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);
statusSetMsg((uint8_t *)title, (uint8_t *)text);
}

// replay a notification
Expand All @@ -172,30 +175,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();
statusSetReady();
}

// check if pressed on titlebar area
Expand Down
9 changes: 1 addition & 8 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 All @@ -38,7 +31,7 @@ bool toastRunning(void);
void addToast(DIALOG_TYPE style, char * text);
void drawToast(bool redraw);
void loopToast(void);
void addNotification(DIALOG_TYPE style, char * title, char * text, bool ShowDialog);
void addNotification(DIALOG_TYPE style, char * title, char * text, bool drawDialog);
void replayNotification(uint8_t index);
NOTIFICATION * getNotification(uint8_t index);
bool hasNotification(void);
Expand Down
48 changes: 19 additions & 29 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ void abortAndTerminate(void)

if (infoMachineSettings.firmwareType != FW_REPRAPFW)
{
// clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message.
// Otherwise, store the gcode on command queue to send it waiting for its related ACK message
//
if (isPendingCmd())
sendEmergencyCmd("M524\n");
else
mustStoreCmd("M524\n");
sendEmergencyCmd("M524\n");
}
else // if RepRap
{
Expand All @@ -98,9 +92,9 @@ void abortAndTerminate(void)
}
}

void loopBreakToCondition(CONDITION_CALLBACK condCallback)
void waitForAbort(void)
{
// M108 is sent to Marlin because consecutive blocking operations such as heating bed, extruder may defer processing of other gcodes.
// M108 is sent to Marlin because consecutive blocking operations such as heating bed/extruder may defer processing of other gcodes.
// If there's any ongoing blocking command, "M108" will take that out from the closed loop and a response will be received
// from that command. Than another "M108" will be sent to unlock a next possible blocking command.
// This way enough "M108" will be sent to unlock all possible blocking command(s) (ongoing or enqueued) but not too much and
Expand All @@ -109,7 +103,7 @@ void loopBreakToCondition(CONDITION_CALLBACK condCallback)
uint16_t rIndex_old = -1; // out of band value -1 will guarantee the beginning of M108 transmission loop
uint16_t rIndex;

TASK_LOOP_WHILE(condCallback(),
TASK_LOOP_WHILE(!infoPrinting.aborted,
if ((rIndex = Serial_GetReadingIndexRX(SERIAL_PORT)) != rIndex_old)
{
sendEmergencyCmd("M108\n");
Expand Down Expand Up @@ -571,40 +565,36 @@ void abortPrint(void)
{
case FS_TFT_SD:
case FS_TFT_USB:
loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any
setPrintAbort(); // finalize the print abort
break;

case FS_ONBOARD_MEDIA:
case FS_ONBOARD_MEDIA_REMOTE:
popupSplash(DIALOG_TYPE_INFO, LABEL_SCREEN_INFO, LABEL_BUSY);
loopPopup(); // trigger the immediate draw of the above popup

// clear the command queue and send the M524 gcode immediately if there is an already pending gcode waiting for an ACK message.
// Otherwise, store the gcode on command queue to send it waiting for its related ACK message.
// Furthermore, forward the print cancel action to all hosts (also TFT) to notify the print cancelation
//
// NOTE: the print cancel action received by the TFT always guarantees the invokation of setPrintAbort() in parseAck.c
// to finalize the print (e.g. stats) in case the ACK messages "Not SD printing" and/or "//action:cancel"
// are not received from Marlin
//
abortAndTerminate();
mustStoreCmd("M118 P0 A1 action:cancel\n");

// loop on break until infoHost.status is set to "HOST_STATUS_IDLE" by setPrintAbort() in parseAck.c
loopBreakToCondition(&isPrintingFromOnboard);
abortAndTerminate(); // send a print abort command before calling the following waitForAbort() function
break;

case FS_REMOTE_HOST:
loopBreakToCondition(&isPendingCmd); // break a pending gcode waiting for an ACK message, if any

// forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print
// - forward a print cancel notification to all hosts (so also the one handling the print) asking to cancel the print
// - the host handling the print should respond to this notification with "M118 P0 A1 action:cancel" that will
// trigger setPrintAbort() in parseACK() once the following loop does its job (stopping all blocking operations)
//
mustStoreCmd("M118 P0 A1 action:notification remote cancel\n");
waitForAbort();

loopDetected = false; // finally, remove lock and exit
return;
}

// - forward a print cancel action to all hosts (also TFT) to notify the print cancelation
// - the print cancel action received by the TFT always guarantees the invokation of setPrintAbort() in parseAck.c
// (e.g. to finalize the print (e.g. stats) in case the ACK messages "Not SD printing" and/or "//action:cancel"
// are not received from Marlin) once the following loop does its job (stopping all blocking operations)
//
mustStoreCmd("M118 P0 A1 action:cancel\n");
waitForAbort();

// execute post print cancel tasks
if (GET_BIT(infoSettings.send_gcodes, SEND_GCODES_CANCEL_PRINT))
sendPrintCodes(2);
Expand Down Expand Up @@ -825,7 +815,6 @@ void loopPrintFromTFT(void)

CMD gcode;
uint8_t gcode_count = 0;
uint8_t comment_count = 0;
char read_char = '\0';
UINT br = 0;
FIL * ip_file = &infoPrinting.file;
Expand Down Expand Up @@ -870,6 +859,7 @@ void loopPrintFromTFT(void)
// if file comment parsing is enabled and a comment tag was previously intercepted parsing the gcode, enable comment parsing
bool comment_parsing = (GET_BIT(infoSettings.general_settings, INDEX_FILE_COMMENT_PARSING) == 1 &&
read_char == ';') ? true : false;
uint8_t comment_count = 0;

for ( ; ip_cur < ip_size; ip_cur++) // continue to parse the line (e.g. comment) until command end flag
{
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/Printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void resumeAndContinue(void);
// commented because NOT externally invoked
//
//void abortAndTerminate(void);
//void loopBreakToCondition(CONDITION_CALLBACK condCallback);
//void waitForAbort(void);

void setPrintExpectedTime(uint32_t expectedTime);
uint32_t getPrintExpectedTime(void);
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
Loading

0 comments on commit 156e04b

Please sign in to comment.