Skip to content

Commit

Permalink
FULL_REPORT_TO_HOST_FEATURE
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 11, 2020
1 parent 6759aff commit 56747e9
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,9 @@
//
#define HOST_KEEPALIVE_FEATURE // Disable this if your host doesn't like keepalive messages
#define DEFAULT_KEEPALIVE_INTERVAL 2 // Number of seconds between "busy" messages. Set with M113.
#define KEEPALIVE_INTERVAL_DIVIDER 3 // Divide the KEEPALIVE_INTERVAL for faster reporting
#define BUSY_WHILE_HEATING // Some hosts require "busy" messages even during heating
#define FULL_REPORT_TO_HOST_FEATURE // Enable this to send Machine status reports while moving and status reports GRBL style

//
// G20/G21 Inch mode support
Expand Down
12 changes: 12 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMST

MarlinState marlin_state = MF_INITIALIZING;

M_StateEnum M_State_grbl = M_INIT;

// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
bool wait_for_heatup = true;

Expand Down Expand Up @@ -341,6 +343,16 @@ void quickstop_stepper() {
sync_plan_position();
}

void quickpause_stepper() {
planner.quick_pause();
//planner.synchronize();
}

void quickresume_stepper() {
planner.quick_resume();
//planner.synchronize();
}

void enable_e_steppers() {
#define _ENA_E(N) ENABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _ENA_E)
Expand Down
23 changes: 23 additions & 0 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, cons
void minkill(const bool steppers_off=false);

void quickstop_stepper();
void quickpause_stepper();
void quickresume_stepper();

// Global State of the firmware
enum MarlinState : uint8_t {
Expand All @@ -76,6 +78,27 @@ extern MarlinState marlin_state;
inline bool IsRunning() { return marlin_state == MF_RUNNING; }
inline bool IsStopped() { return marlin_state != MF_RUNNING; }

//
// Enumerated Status indices
// Coding as GRBL or TinyG for Machine states
//
enum M_StateEnum : uint8_t {
M_INIT = 0, // 0 machine is initializing
M_RESET, // 1 machine is ready for use
M_ALARM, // 2 machine is in alarm state (soft shut down)
M_IDLE, // 3 program stop or no more blocks (M0, M1, M60)
M_END, // 4 program end via M2, M30
M_RUNNING, // 5 motion is running
M_HOLD, // 6 motion is holding
M_PROBE, // 7 probe cycle active
M_CYCLING, // 8 machine is running (cycling)
M_HOMING, // 9 machine is homing
M_JOGGING, // 10 machine is jogging
M_ERROR // 11 machine is in hard alarm state (shut down)
};

extern M_StateEnum M_State_grbl;

bool printingIsActive();
bool printingIsPaused();
void startOrResumeJob();
Expand Down
120 changes: 58 additions & 62 deletions Marlin/src/feature/e_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,29 @@
// External references
extern bool wait_for_user, wait_for_heatup;
void quickstop_stepper();
void quickpause_stepper();
void quickresume_stepper();
void report_current_position_moving();

class EmergencyParser {

public:

// Currently looking for: M108, M112, M410, M876
// S000 STATE , P000 for Pause, R000 for resume
enum State : char {
EP_RESET,
EP_N,
EP_M,
EP_M1,
EP_M10,
EP_M108,
EP_M11,
EP_M112,
EP_M4,
EP_M41,
EP_M410,
EP_M10, EP_M108,
EP_M11, EP_M112,
EP_M4, EP_M41, EP_M410,
EP_S, EP_S0, EP_S00, EP_grblSTATUS,
EP_R, EP_R0, EP_R00, EP_grblRESUME,
EP_P, EP_P0, EP_P00, EP_grblPAUSE,
#if ENABLED(HOST_PROMPT_SUPPORT)
EP_M8,
EP_M87,
EP_M876,
EP_M876S,
EP_M876SN,
EP_M8, EP_M87, EP_M876, EP_M876S, EP_M876SN,
#endif
EP_IGNORE // to '\n'
};
Expand All @@ -71,7 +70,6 @@ class EmergencyParser {
EmergencyParser() { enable(); }

FORCE_INLINE static void enable() { enabled = true; }

FORCE_INLINE static void disable() { enabled = false; }

FORCE_INLINE static void update(State &state, const uint8_t c) {
Expand All @@ -80,23 +78,35 @@ class EmergencyParser {
case EP_RESET:
switch (c) {
case ' ': case '\n': case '\r': break;
case 'N': state = EP_N; break;
case 'M': state = EP_M; break;
default: state = EP_IGNORE;
case 'N': state = EP_N; break;
case 'M': state = EP_M; break;
case 'S': state = EP_S; break;
case 'P': state = EP_P; break;
case 'R': state = EP_R; break;
default: state = EP_IGNORE;
}
break;

case EP_N:
switch (c) {
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9': case '-': case ' ': break;
case '0' ... '9': case '-': case ' ': break;
case 'M': state = EP_M; break;
default: state = EP_IGNORE;
default: state = EP_IGNORE;
}
break;

case EP_S: state = (c == '0' ? EP_S0 : EP_IGNORE); break;
case EP_S0: state = (c == '0' ? EP_S00 : EP_IGNORE); break;
case EP_S00: state = (c == '0' ? EP_grblSTATUS : EP_IGNORE); break;

case EP_R: state = (c == '0' ? EP_R0 : EP_IGNORE); break;
case EP_R0: state = (c == '0' ? EP_R00 : EP_IGNORE); break;
case EP_R00: state = (c == '0' ? EP_grblRESUME : EP_IGNORE); break;

case EP_P: state = (c == '0' ? EP_P0 : EP_IGNORE); break;
case EP_P0: state = (c == '0' ? EP_P00 : EP_IGNORE); break;
case EP_P00: state = (c == '0' ? EP_grblPAUSE : EP_IGNORE); break;

case EP_M:
switch (c) {
case ' ': break;
Expand All @@ -117,52 +127,35 @@ class EmergencyParser {
}
break;

case EP_M10:
state = (c == '8') ? EP_M108 : EP_IGNORE;
break;

case EP_M11:
state = (c == '2') ? EP_M112 : EP_IGNORE;
break;

case EP_M4:
state = (c == '1') ? EP_M41 : EP_IGNORE;
break;

case EP_M41:
state = (c == '0') ? EP_M410 : EP_IGNORE;
break;
case EP_M10: state = (c == '8') ? EP_M108 : EP_IGNORE; break;
case EP_M11: state = (c == '2') ? EP_M112 : EP_IGNORE; break;
case EP_M4: state = (c == '1') ? EP_M41 : EP_IGNORE; break;
case EP_M41: state = (c == '0') ? EP_M410 : EP_IGNORE; break;

#if ENABLED(HOST_PROMPT_SUPPORT)
case EP_M8:
state = (c == '7') ? EP_M87 : EP_IGNORE;
break;

case EP_M87:
state = (c == '6') ? EP_M876 : EP_IGNORE;
break;
case EP_M8: state = (c == '7') ? EP_M87 : EP_IGNORE; break;
case EP_M87: state = (c == '6') ? EP_M876 : EP_IGNORE; break;

case EP_M876:
switch (c) {
case ' ': break;
case 'S': state = EP_M876S; break;
default: state = EP_IGNORE; break;
}
break;
case EP_M876:
switch (c) {
case ' ': break;
case 'S': state = EP_M876S; break;
default: state = EP_IGNORE; break;
}
break;

case EP_M876S:
switch (c) {
case ' ': break;
case '0' ... '9':
state = EP_M876SN;
M876_reason = (uint8_t)(c - '0');
break;
}
break;

case EP_M876S:
switch (c) {
case ' ': break;
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9':
state = EP_M876SN;
M876_reason = (uint8_t)(c - '0');
break;
}
break;
#endif
#endif // HOST_PROMPT_SUPPORT

case EP_IGNORE:
if (ISEOL(c)) state = EP_RESET;
Expand All @@ -177,6 +170,9 @@ class EmergencyParser {
#if ENABLED(HOST_PROMPT_SUPPORT)
case EP_M876SN: host_response_handler(M876_reason); break;
#endif
case EP_grblSTATUS: report_current_position_moving(); break;
case EP_grblPAUSE: quickpause_stepper(); break;
case EP_grblRESUME: quickresume_stepper(); break;
default: break;
}
state = EP_RESET;
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
*/
G29_TYPE GcodeSuite::G29() {

M_State_grbl = M_PROBE;
report_current_grblstate_moving();

reset_stepper_timeout();

const bool seenQ = EITHER(DEBUG_LEVELING_FEATURE, PROBE_MANUALLY) && parser.seen('Q');
Expand Down Expand Up @@ -898,6 +901,9 @@ G29_TYPE GcodeSuite::G29() {

report_current_position();

M_State_grbl = M_IDLE;
report_current_grblstate_moving();

G29_RETURN(isnan(measured_z));
}

Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/gcode/bedlevel/mbl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM("
*/
void GcodeSuite::G29() {

M_State_grbl = M_PROBE;
report_current_grblstate_moving();

static int mbl_probe_index = -1;
TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state);

Expand Down Expand Up @@ -197,6 +200,9 @@ void GcodeSuite::G29() {
}

report_current_position();

M_State_grbl = M_IDLE;
report_current_grblstate_moving();
}

#endif // MESH_BED_LEVELING
14 changes: 13 additions & 1 deletion Marlin/src/gcode/bedlevel/ubl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
#include "../../gcode.h"
#include "../../../feature/bedlevel/bedlevel.h"

void GcodeSuite::G29() { ubl.G29(); }
#include "../../../MarlinCore.h" // for M_State_grbl

void GcodeSuite::G29() {

M_State_grbl = M_PROBE;
report_current_grblstate_moving();

ubl.G29();

M_State_grbl = M_IDLE;
report_current_grblstate_moving();

}

#endif // AUTO_BED_LEVELING_UBL
6 changes: 6 additions & 0 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ void GcodeSuite::G28() {

TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);

M_State_grbl = M_HOMING;
report_current_grblstate_moving();

#if ENABLED(DUAL_X_CARRIAGE)
bool IDEX_saved_duplication_state = extruder_duplication_enabled;
DualXMode IDEX_saved_mode = dual_x_carriage_mode;
Expand Down Expand Up @@ -464,6 +467,9 @@ void GcodeSuite::G28() {
if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);

M_State_grbl = M_IDLE;
report_current_grblstate_moving();

#if HAS_L64XX
// Set L6470 absolute position registers to counts
// constexpr *might* move this to PROGMEM.
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ static float auto_tune_a() {
*/
void GcodeSuite::G33() {

M_State_grbl = M_PROBE;
report_current_grblstate_moving();

const int8_t probe_points = parser.intval('P', DELTA_CALIBRATION_DEFAULT_POINTS);
if (!WITHIN(probe_points, 0, 10)) {
SERIAL_ECHOLNPGM("?(P)oints implausible (0-10).");
Expand Down Expand Up @@ -643,6 +646,9 @@ void GcodeSuite::G33() {
while (((zero_std_dev < test_precision && iterations < 31) || iterations <= force_iterations) && zero_std_dev > calibration_precision);

ac_cleanup(TERN_(HAS_MULTI_HOTEND, old_tool_index));

M_State_grbl = M_IDLE;
report_current_grblstate_moving();
}

#endif // DELTA_AUTO_CALIBRATION
13 changes: 11 additions & 2 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ GcodeSuite gcode;
#include "../feature/password/password.h"
#endif

#include "../MarlinCore.h" // for idle()
#include "../MarlinCore.h" // for idle(), M_State_grbl

// Inactivity shutdown
millis_t GcodeSuite::previous_move_ms = 0,
Expand All @@ -82,6 +82,10 @@ uint8_t GcodeSuite::axis_relative = (
#endif

#if ENABLED(HOST_KEEPALIVE_FEATURE)
#if !KEEPALIVE_INTERVAL_DIVIDER
#undef KEEPALIVE_INTERVAL_DIVIDER
#define KEEPALIVE_INTERVAL_DIVIDER 1
#endif
GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
#endif
Expand Down Expand Up @@ -1017,18 +1021,23 @@ void GcodeSuite::process_subcommands_now(char * gcode) {
case IN_HANDLER:
case IN_PROCESS:
SERIAL_ECHO_MSG(STR_BUSY_PROCESSING);
TERN_(FULL_REPORT_TO_HOST_FEATURE, report_current_position_moving());
break;
case PAUSED_FOR_USER:
SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_USER);
M_State_grbl = M_HOLD;
report_current_grblstate_moving();
break;
case PAUSED_FOR_INPUT:
SERIAL_ECHO_MSG(STR_BUSY_PAUSED_FOR_INPUT);
M_State_grbl = M_HOLD;
report_current_grblstate_moving();
break;
default:
break;
}
}
next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval);
next_busy_signal_ms = ms + SEC_TO_MS(host_keepalive_interval) / (KEEPALIVE_INTERVAL_DIVIDER);
}

#endif // HOST_KEEPALIVE_FEATURE
Loading

0 comments on commit 56747e9

Please sign in to comment.