Automatically reset stepper timeout in manage_inactivity

Any code that adds moves to the planner can skip resetting the stepper timeout. We can let `idle` / `manage_inactivity` reset the timer whenever it detects any moves in the planner.
This commit is contained in:
Scott Lahteine 2018-03-21 02:46:04 -05:00
parent 9e987e4971
commit 647c04def8
5 changed files with 37 additions and 53 deletions

View File

@ -207,8 +207,8 @@ void clear_command_queue();
#endif #endif
#endif #endif
extern millis_t previous_cmd_ms; extern millis_t previous_move_ms;
inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); } inline void reset_stepper_timeout() { previous_move_ms = millis(); }
/** /**
* Feedrate scaling and conversion * Feedrate scaling and conversion

View File

@ -522,7 +522,7 @@ const char axis_codes[XYZE] = { 'X', 'Y', 'Z', 'E' };
static int serial_count; // = 0; static int serial_count; // = 0;
// Inactivity shutdown // Inactivity shutdown
millis_t previous_cmd_ms; // = 0; millis_t previous_move_ms; // = 0;
static millis_t max_inactive_time; // = 0; static millis_t max_inactive_time; // = 0;
static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL; static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
@ -1539,8 +1539,6 @@ inline void buffer_line_to_destination(const float &fr_mm_s) {
if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination); if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination);
#endif #endif
refresh_cmd_timeout();
#if UBL_SEGMENTED #if UBL_SEGMENTED
// ubl segmented line will do z-only moves in single segment // ubl segmented line will do z-only moves in single segment
ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s)); ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s));
@ -1705,7 +1703,6 @@ static void setup_for_endstop_or_probe_move() {
saved_feedrate_mm_s = feedrate_mm_s; saved_feedrate_mm_s = feedrate_mm_s;
saved_feedrate_percentage = feedrate_percentage; saved_feedrate_percentage = feedrate_percentage;
feedrate_percentage = 100; feedrate_percentage = 100;
refresh_cmd_timeout();
} }
static void clean_up_after_endstop_or_probe_move() { static void clean_up_after_endstop_or_probe_move() {
@ -1714,7 +1711,6 @@ static void clean_up_after_endstop_or_probe_move() {
#endif #endif
feedrate_mm_s = saved_feedrate_mm_s; feedrate_mm_s = saved_feedrate_mm_s;
feedrate_percentage = saved_feedrate_percentage; feedrate_percentage = saved_feedrate_percentage;
refresh_cmd_timeout();
} }
#if HAS_AXIS_UNHOMED_ERR #if HAS_AXIS_UNHOMED_ERR
@ -2227,9 +2223,6 @@ static void clean_up_after_endstop_or_probe_move() {
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position);
#endif #endif
// Prevent stepper_inactive_time from running out and EXTRUDER_RUNOUT_PREVENT from extruding
refresh_cmd_timeout();
// Double-probing does a fast probe followed by a slow probe // Double-probing does a fast probe followed by a slow probe
#if MULTIPLE_PROBING == 2 #if MULTIPLE_PROBING == 2
@ -3360,7 +3353,6 @@ inline void gcode_G0_G1(
// Send the arc to the planner // Send the arc to the planner
plan_arc(destination, arc_offset, clockwise); plan_arc(destination, arc_offset, clockwise);
refresh_cmd_timeout();
} }
else { else {
// Bad arguments // Bad arguments
@ -3373,8 +3365,7 @@ inline void gcode_G0_G1(
#endif // ARC_SUPPORT #endif // ARC_SUPPORT
void dwell(millis_t time) { void dwell(millis_t time) {
refresh_cmd_timeout(); time += millis();
time += previous_cmd_ms;
while (PENDING(millis(), time)) idle(); while (PENDING(millis(), time)) idle();
} }
@ -6236,10 +6227,9 @@ inline void gcode_G92() {
wait_for_user = true; wait_for_user = true;
stepper.synchronize(); stepper.synchronize();
refresh_cmd_timeout();
if (ms > 0) { if (ms > 0) {
ms += previous_cmd_ms; // wait until this time for a click ms += millis(); // wait until this time for a click
while (PENDING(millis(), ms) && wait_for_user) idle(); while (PENDING(millis(), ms) && wait_for_user) idle();
} }
else { else {
@ -7198,8 +7188,6 @@ inline void gcode_M42() {
} }
if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards"); if (probe_inverting != deploy_state) SERIAL_PROTOCOLLNPGM("WARNING - INVERTING setting probably backwards");
refresh_cmd_timeout();
if (deploy_state != stow_state) { if (deploy_state != stow_state) {
SERIAL_PROTOCOLLNPGM("BLTouch clone detected"); SERIAL_PROTOCOLLNPGM("BLTouch clone detected");
if (deploy_state) { if (deploy_state) {
@ -7226,8 +7214,7 @@ inline void gcode_M42() {
safe_delay(2); safe_delay(2);
if (0 == j % (500 * 1)) // keep cmd_timeout happy if (0 == j % (500 * 1)) reset_stepper_timeout(); // Keep steppers powered
refresh_cmd_timeout();
if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
@ -7921,7 +7908,7 @@ inline void gcode_M109() {
} }
idle(); idle();
refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out reset_stepper_timeout(); // Keep steppers powered
const float temp = thermalManager.degHotend(target_extruder); const float temp = thermalManager.degHotend(target_extruder);
@ -8058,7 +8045,7 @@ inline void gcode_M109() {
} }
idle(); idle();
refresh_cmd_timeout(); // to prevent stepper_inactive_time from running out reset_stepper_timeout(); // Keep steppers powered
const float temp = thermalManager.degBed(); const float temp = thermalManager.degBed();
@ -12199,6 +12186,8 @@ void process_next_command() {
#endif #endif
} }
reset_stepper_timeout(); // Keep steppers powered
// Parse the next command in the queue // Parse the next command in the queue
parser.parse(current_command); parser.parse(current_command);
process_parsed_command(); process_parsed_command();
@ -12226,7 +12215,6 @@ void flush_and_request_resend() {
* B<int> Block queue space remaining * B<int> Block queue space remaining
*/ */
void ok_to_send() { void ok_to_send() {
refresh_cmd_timeout();
if (!send_ok[cmd_queue_index_r]) return; if (!send_ok[cmd_queue_index_r]) return;
SERIAL_PROTOCOLPGM(MSG_OK); SERIAL_PROTOCOLPGM(MSG_OK);
#if ENABLED(ADVANCED_OK) #if ENABLED(ADVANCED_OK)
@ -13074,7 +13062,6 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
*/ */
void prepare_move_to_destination() { void prepare_move_to_destination() {
clamp_to_software_endstops(destination); clamp_to_software_endstops(destination);
refresh_cmd_timeout();
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE) #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
@ -13504,7 +13491,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
const millis_t ms = millis(); const millis_t ms = millis();
if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) { if (max_inactive_time && ELAPSED(ms, previous_move_ms + max_inactive_time)) {
SERIAL_ERROR_START(); SERIAL_ERROR_START();
SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr); SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr);
kill(PSTR(MSG_KILLED)); kill(PSTR(MSG_KILLED));
@ -13517,23 +13504,26 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
#define MOVE_AWAY_TEST true #define MOVE_AWAY_TEST true
#endif #endif
if (MOVE_AWAY_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time) if (stepper_inactive_time) {
&& !ignore_stepper_queue && !planner.blocks_queued()) { if (planner.blocks_queued())
#if ENABLED(DISABLE_INACTIVE_X) previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
disable_X(); else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, previous_move_ms + stepper_inactive_time)) {
#endif #if ENABLED(DISABLE_INACTIVE_X)
#if ENABLED(DISABLE_INACTIVE_Y) disable_X();
disable_Y(); #endif
#endif #if ENABLED(DISABLE_INACTIVE_Y)
#if ENABLED(DISABLE_INACTIVE_Z) disable_Y();
disable_Z(); #endif
#endif #if ENABLED(DISABLE_INACTIVE_Z)
#if ENABLED(DISABLE_INACTIVE_E) disable_Z();
disable_e_steppers(); #endif
#endif #if ENABLED(DISABLE_INACTIVE_E)
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(ULTIPANEL) // Only needed with an LCD disable_e_steppers();
if (ubl.lcd_map_control) ubl.lcd_map_control = defer_return_to_status = false; #endif
#endif #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(ULTIPANEL) // Only needed with an LCD
if (ubl.lcd_map_control) ubl.lcd_map_control = defer_return_to_status = false;
#endif
}
} }
#ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH #ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
@ -13592,7 +13582,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
#if ENABLED(EXTRUDER_RUNOUT_PREVENT) #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
&& ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL) && ELAPSED(ms, previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
&& !planner.blocks_queued() && !planner.blocks_queued()
) { ) {
#if ENABLED(SWITCHING_EXTRUDER) #if ENABLED(SWITCHING_EXTRUDER)
@ -13617,8 +13607,6 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
} }
#endif // !SWITCHING_EXTRUDER #endif // !SWITCHING_EXTRUDER
previous_cmd_ms = ms; // refresh_cmd_timeout()
const float olde = current_position[E_AXIS]; const float olde = current_position[E_AXIS];
current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE; current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
planner.buffer_line_kinematic(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder); planner.buffer_line_kinematic(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
@ -13644,6 +13632,8 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
#endif // E_STEPPERS > 1 #endif // E_STEPPERS > 1
} }
#endif // !SWITCHING_EXTRUDER #endif // !SWITCHING_EXTRUDER
previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
} }
#endif // EXTRUDER_RUNOUT_PREVENT #endif // EXTRUDER_RUNOUT_PREVENT

View File

@ -508,7 +508,7 @@ class Planner {
/** /**
* Does the buffer have any blocks queued? * Does the buffer have any blocks queued?
*/ */
static bool blocks_queued() { return (block_buffer_head != block_buffer_tail); } static inline bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
/** /**
* "Discard" the block and "release" the memory. * "Discard" the block and "release" the memory.

View File

@ -774,7 +774,7 @@
wait_for_release(); wait_for_release();
while (!is_lcd_clicked()) { while (!is_lcd_clicked()) {
idle(); idle();
refresh_cmd_timeout(); reset_stepper_timeout(); // Keep steppers powered
if (encoder_diff) { if (encoder_diff) {
do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier); do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier);
encoder_diff = 0; encoder_diff = 0;

View File

@ -1880,7 +1880,6 @@ void kill_screen(const char* lcd_msg) {
// Encoder knob or keypad buttons adjust the Z position // Encoder knob or keypad buttons adjust the Z position
// //
if (encoderPosition) { if (encoderPosition) {
refresh_cmd_timeout();
const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP); const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5)); line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
@ -2403,7 +2402,6 @@ void kill_screen(const char* lcd_msg) {
stepper.cleaning_buffer_counter = 0; stepper.cleaning_buffer_counter = 0;
set_current_from_steppers_for_axis(ALL_AXES); set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position(); sync_plan_position();
refresh_cmd_timeout();
} }
void _lcd_ubl_output_map_lcd() { void _lcd_ubl_output_map_lcd() {
@ -2418,10 +2416,7 @@ void kill_screen(const char* lcd_msg) {
if (encoderPosition) { if (encoderPosition) {
step_scaler += (int32_t)encoderPosition; step_scaler += (int32_t)encoderPosition;
x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM); x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
step_scaler = 0;
refresh_cmd_timeout();
encoderPosition = 0; encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_REDRAW_NOW; lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
} }
@ -2903,7 +2898,6 @@ void kill_screen(const char* lcd_msg) {
if (use_click()) { return lcd_goto_previous_menu_no_defer(); } if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
ENCODER_DIRECTION_NORMAL(); ENCODER_DIRECTION_NORMAL();
if (encoderPosition && !processing_manual_move) { if (encoderPosition && !processing_manual_move) {
refresh_cmd_timeout();
// Start with no limits to movement // Start with no limits to movement
float min = current_position[axis] - 1000, float min = current_position[axis] - 1000,