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
This commit is contained in:
gudnimg 2023-10-21 11:22:53 +00:00
parent 3b10c6130e
commit 8fcfdf31c4
5 changed files with 49 additions and 1 deletions

View File

@ -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

View File

@ -66,6 +66,9 @@
*/
#define AUTO_REPORT
// Keepalive period which is restarted with M79
#define M79_TIMEOUT 30 * 1000 // ms
//===========================================================================
//=============================Mechanical Settings===========================
//===========================================================================

View File

@ -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 <a href="https://reprap.org/wiki/G-code#M104:_Set_Extruder_Temperature">M104: Set Extruder Temperature</a>
#### 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) {

17
Firmware/host.cpp Normal file
View File

@ -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);
}

12
Firmware/host.h Normal file
View File

@ -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();