From 8fcfdf31c4eabe85ffc03977b292a5a93dbf62b8 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sat, 21 Oct 2023 11:22:53 +0000 Subject: [PATCH] PFW-1523 Implement M79 timer for PrusaLink The idea is to have the host ping the printer periodically with a M79 to enable certain features/UI. Using the usb_timer is not a good solution for this as it depends on seeing a 'G' character The LCD code, or whatever code is implementing the new functionality will need to include host.h and check whether M79_timer_get_status() returns 0 (timer not running) or 1 (timer is running). I created a new file for the code host.cpp which we can use to expand host related functionality and not clutter Marlin_main.cpp further. Change in memory: Flash: +104 bytes SRAM: +5 bytes --- CMakeLists.txt | 1 + Firmware/Configuration_adv.h | 3 +++ Firmware/Marlin_main.cpp | 17 ++++++++++++++++- Firmware/host.cpp | 17 +++++++++++++++++ Firmware/host.h | 12 ++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Firmware/host.cpp create mode 100644 Firmware/host.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a48c9309..aa08d6ba8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,7 @@ set(FW_SOURCES Filament_sensor.cpp first_lay_cal.cpp heatbed_pwm.cpp + host.cpp la10compat.cpp language.c lcd.cpp diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 94b86c608..34c683ce2 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -66,6 +66,9 @@ */ #define AUTO_REPORT +// Keepalive period which is restarted with M79 +#define M79_TIMEOUT 30 * 1000 // ms + //=========================================================================== //=============================Mechanical Settings=========================== //=========================================================================== diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5cc53da95..eb703187a 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -68,6 +68,7 @@ #include "backlight.h" #include "planner.h" +#include "host.h" #include "stepper.h" #include "temperature.h" #include "fancheck.h" @@ -5850,6 +5851,20 @@ Sigma_Exit: } break; } + + /*! + ### M79 - TODO + Restart the printer-host enable keepalive timer. While the timer has not expired, the printer will enable host specific features. + #### Usage + + M79 + #### Parameters + None + */ + case 79: + M79_timer_restart(); + break; + /*! ### M104 - Set hotend temperature M104: Set Extruder Temperature #### Usage @@ -6306,7 +6321,6 @@ Sigma_Exit: case 113: if (code_seen('S')) { host_keepalive_interval = code_value_uint8(); -// NOMORE(host_keepalive_interval, 60); } else { SERIAL_ECHO_START; @@ -9424,6 +9438,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s host_autoreport(); #endif //AUTO_REPORT host_keepalive(); + M79_timer_update_status(); } void kill(const char *full_screen_message) { diff --git a/Firmware/host.cpp b/Firmware/host.cpp new file mode 100644 index 000000000..bd3c7c1e3 --- /dev/null +++ b/Firmware/host.cpp @@ -0,0 +1,17 @@ +#include "Configuration_adv.h" +#include "host.h" +#include "Timer.h" + +static LongTimer M79_timer; + +void M79_timer_restart() { + M79_timer.start(); +} + +bool M79_timer_get_status() { + return M79_timer.running(); +} + +void M79_timer_update_status() { + M79_timer.expired(M79_TIMEOUT); +} diff --git a/Firmware/host.h b/Firmware/host.h new file mode 100644 index 000000000..373d6a28f --- /dev/null +++ b/Firmware/host.h @@ -0,0 +1,12 @@ +#pragma once + +/// Restart the M79 timer +void M79_timer_restart(); + +/// Get the current M79 timer status +/// @returns true if running, false otherwise +bool M79_timer_get_status(); + +/// Checks if the timer period has expired. If the timer +/// has expired, the timer is stopped +void M79_timer_update_status();