From 20a2216623c2d54eb8c58d9a27a6cec6e0000624 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sat, 4 Nov 2023 17:43:13 +0000 Subject: [PATCH] PFW-1523 Implement S parameter for M79 Change in memory: Flash: +112 bytes SRAM: +3 bytes --- Firmware/Marlin_main.cpp | 14 ++++++++++++-- Firmware/host.cpp | 15 +++++++++++++++ Firmware/host.h | 10 ++++++++++ Firmware/ultralcd.cpp | 19 ++++++++++++++----- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index eb703187a..3bcc36b3b 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5857,12 +5857,22 @@ Sigma_Exit: Restart the printer-host enable keepalive timer. While the timer has not expired, the printer will enable host specific features. #### Usage - M79 + M79 [ S ] #### Parameters - None + - `S` - Quoted string containing two characters e.g. "PL" */ case 79: M79_timer_restart(); + + if (code_seen('S')) + { + unquoted_string str = unquoted_string(strchr_pointer); + if (str.WasFound()) + { + ResetHostStatusScreenName(); + SetHostStatusScreenName(str.GetUnquotedString()); + } + } break; /*! diff --git a/Firmware/host.cpp b/Firmware/host.cpp index bd3c7c1e3..0f26c7068 100644 --- a/Firmware/host.cpp +++ b/Firmware/host.cpp @@ -1,8 +1,23 @@ +#include #include "Configuration_adv.h" #include "host.h" #include "Timer.h" static LongTimer M79_timer; +static char host_status_screen_name[3]; + +void SetHostStatusScreenName(const char * name) { + strncpy(host_status_screen_name, name, 2); + host_status_screen_name[2] = '\0'; +} + +char * GetHostStatusScreenName() { + return host_status_screen_name; +} + +void ResetHostStatusScreenName() { + memset(host_status_screen_name, 0, sizeof(host_status_screen_name)); +} void M79_timer_restart() { M79_timer.start(); diff --git a/Firmware/host.h b/Firmware/host.h index 373d6a28f..d759d7d22 100644 --- a/Firmware/host.h +++ b/Firmware/host.h @@ -1,5 +1,15 @@ #pragma once +/// Assigns host name with up to two characters which will be shown on +/// the UI when printing. The function forces the third byte to be null delimiter. +void SetHostStatusScreenName(const char * name); + +/// Returns a pointer to the host name +char * GetHostStatusScreenName(); + +/// Reset the memory to NULL when the host name should not be used +void ResetHostStatusScreenName(); + /// Restart the M79 timer void M79_timer_restart(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 33f289785..c0aab9fe8 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -19,7 +19,7 @@ #include "menu.h" #include "backlight.h" - +#include "host.h" #include "util.h" #include "mesh_bed_leveling.h" #include "mesh_bed_calibration.h" @@ -359,8 +359,7 @@ void lcdui_print_feedrate(void) // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total) void lcdui_print_percent_done(void) { - const char* src = usb_timer.running()?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" ")); - char per[4]; + const char* src = usb_timer.running()?_N(" HO"):(IS_SD_PRINTING?_N(" SD"):_N(" ")); bool num = IS_SD_PRINTING || (printer_active() && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT)); if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating { @@ -375,8 +374,18 @@ void lcdui_print_percent_done(void) return; //do not also print the percentage } } - sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done()); - lcd_printf_P(_N("%3S%3s%%"), src, per); + + if (M79_timer_get_status() && GetHostStatusScreenName()) + { + // Overwrite the name + char * hostName = GetHostStatusScreenName(); + lcd_space(1); // Blank space + lcd_print(hostName); // Two characters + } else { + lcd_printf_P(PSTR("%3S"), src); + } + + lcd_printf_P(num ? _N("%3d%%"):_N("---%%"), calc_percent_done()); } // Print extruder status (5 chars total)