Move host keepalive to GcodeSuite

This commit is contained in:
Scott Lahteine
2017-09-08 23:49:49 -05:00
parent 8fbb833de9
commit 8dc2838d98
6 changed files with 69 additions and 74 deletions

View File

@ -41,6 +41,11 @@ millis_t GcodeSuite::previous_cmd_ms;
bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
#if ENABLED(HOST_KEEPALIVE_FEATURE)
GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
#endif
/**
* Set target_extruder from the T parameter or the active_extruder
*
@ -1068,3 +1073,37 @@ void GcodeSuite::process_next_command() {
ok_to_send();
}
#if ENABLED(HOST_KEEPALIVE_FEATURE)
/**
* Output a "busy" message at regular intervals
* while the machine is not accepting commands.
*/
void GcodeSuite::host_keepalive() {
const millis_t ms = millis();
static millis_t next_busy_signal_ms = 0;
if (host_keepalive_interval && busy_state != NOT_BUSY) {
if (PENDING(ms, next_busy_signal_ms)) return;
switch (busy_state) {
case IN_HANDLER:
case IN_PROCESS:
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_BUSY_PROCESSING);
break;
case PAUSED_FOR_USER:
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_USER);
break;
case PAUSED_FOR_INPUT:
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_INPUT);
break;
default:
break;
}
}
next_busy_signal_ms = ms + host_keepalive_interval * 1000UL;
}
#endif // HOST_KEEPALIVE_FEATURE

View File

@ -263,6 +263,8 @@ public:
static void get_destination_from_command();
static void process_next_command();
static FORCE_INLINE void home_all_axes() { G28(true); }
/**
* Multi-stepper support for M92, M201, M203
*/
@ -274,7 +276,28 @@ public:
#define TARGET_EXTRUDER 0
#endif
static FORCE_INLINE void home_all_axes() { G28(true); }
#if ENABLED(HOST_KEEPALIVE_FEATURE)
/**
* States for managing Marlin and host communication
* Marlin sends messages if blocked or busy
*/
enum MarlinBusyState {
NOT_BUSY, // Not in a handler
IN_HANDLER, // Processing a GCode
IN_PROCESS, // Known to be blocking command input (as in G29)
PAUSED_FOR_USER, // Blocking pending any input
PAUSED_FOR_INPUT // Blocking pending text input (concept)
};
static MarlinBusyState busy_state;
static uint8_t host_keepalive_interval;
static void host_keepalive();
#define KEEPALIVE_STATE(n) gcode.busy_state = gcode.n
#else
#define KEEPALIVE_STATE(n) NOOP
#endif
private:

View File

@ -27,11 +27,11 @@
*/
void gcode_M113() {
if (parser.seenval('S')) {
host_keepalive_interval = parser.value_byte();
NOMORE(host_keepalive_interval, 60);
gcode.host_keepalive_interval = parser.value_byte();
NOMORE(gcode.host_keepalive_interval, 60);
}
else {
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR("M113 S", (unsigned long)host_keepalive_interval);
SERIAL_ECHOLNPAIR("M113 S", (unsigned long)gcode.host_keepalive_interval);
}
}