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

@ -353,14 +353,6 @@ float cartes[XYZ] = { 0 };
int lpq_len = 20;
#endif
#if ENABLED(HOST_KEEPALIVE_FEATURE)
MarlinBusyState busy_state = NOT_BUSY;
static millis_t next_busy_signal_ms = 0;
uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
#else
#define host_keepalive() NOOP
#endif
#if ENABLED(I2C_POSITION_ENCODERS)
I2CPositionEncodersMgr I2CPEM;
uint8_t blockBufferIndexRef = 0;
@ -2245,46 +2237,6 @@ static void homeaxis(const AxisEnum axis) {
#endif
/**
* ***************************************************************************
* ***************************** G-CODE HANDLING *****************************
* ***************************************************************************
*/
#if ENABLED(HOST_KEEPALIVE_FEATURE)
/**
* Output a "busy" message at regular intervals
* while the machine is not accepting commands.
*/
void host_keepalive() {
const millis_t ms = millis();
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
/**************************************************
***************** GCode Handlers *****************
**************************************************/
@ -3574,7 +3526,9 @@ void idle(
lcd_update();
host_keepalive();
#if ENABLED(HOST_KEEPALIVE_FEATURE)
gcode.host_keepalive();
#endif
#if ENABLED(AUTO_REPORT_TEMPERATURES) && (HAS_TEMP_HOTEND || HAS_TEMP_BED)
auto_report_temperatures();

View File

@ -266,13 +266,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
#define STOW_PROBE()
#endif
#if ENABLED(HOST_KEEPALIVE_FEATURE)
extern MarlinBusyState busy_state;
#define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
#else
#define KEEPALIVE_STATE(n) NOOP
#endif
#if FAN_COUNT > 0
extern int16_t fanSpeeds[FAN_COUNT];
#if ENABLED(PROBING_FANS_OFF)

View File

@ -121,20 +121,6 @@ enum EndstopEnum {
#endif
#endif
/**
* States for managing Marlin and host communication
* Marlin sends messages if blocked or busy
*/
#if ENABLED(HOST_KEEPALIVE_FEATURE)
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)
};
#endif
/**
* SD Card
*/

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