From d76a01194ddc90ea4391e9d96b401bd18aaa9812 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 26 May 2015 20:08:21 -0700 Subject: [PATCH] Slight size reduction by adding idle() --- Marlin/Marlin.h | 2 ++ Marlin/Marlin_main.cpp | 54 ++++++++++++++++-------------------------- Marlin/planner.cpp | 6 +---- Marlin/stepper.cpp | 12 ++++------ 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index fe63dba46..fa6a6cc30 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -116,6 +116,8 @@ FORCE_INLINE void serialprintPGM(const char *str) { void get_command(); +void idle(); // the standard idle routine calls manage_inactivity(false) + void manage_inactivity(bool ignore_stepper_queue=false); #if defined(DUAL_X_CARRIAGE) && HAS_X_ENABLE && HAS_X2_ENABLE diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 2a8d954bc..6e659a71d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -726,11 +726,8 @@ void loop() { commands_in_queue--; cmd_queue_index_r = (cmd_queue_index_r + 1) % BUFSIZE; } - // Check heater every n milliseconds - manage_heater(); - manage_inactivity(); checkHitEndstops(); - lcd_update(); + idle(); } void gcode_line_error(const char *err, bool doFlush=true) { @@ -1998,11 +1995,7 @@ inline void gcode_G4() { if (!lcd_hasstatus()) LCD_MESSAGEPGM(MSG_DWELL); - while (millis() < codenum) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } + while (millis() < codenum) idle(); } #ifdef FWRETRACT @@ -2682,9 +2675,7 @@ inline void gcode_G28() { probePointCounter++; - manage_heater(); - manage_inactivity(); - lcd_update(); + idle(); } //xProbe } //yProbe @@ -2885,21 +2876,13 @@ inline void gcode_G92() { st_synchronize(); refresh_cmd_timeout(); if (codenum > 0) { - codenum += previous_cmd_ms; // keep track of when we started waiting - while(millis() < codenum && !lcd_clicked()) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } + codenum += previous_cmd_ms; // wait until this time for a click + while (millis() < codenum && !lcd_clicked()) idle(); lcd_ignore_click(false); } else { if (!lcd_detected()) return; - while (!lcd_clicked()) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } + while (!lcd_clicked()) idle(); } if (IS_SD_PRINTING) LCD_MESSAGEPGM(MSG_RESUMING); @@ -3525,9 +3508,9 @@ inline void gcode_M109() { #endif temp_ms = millis(); } - manage_heater(); - manage_inactivity(); - lcd_update(); + + idle(); + #ifdef TEMP_RESIDENCY_TIME // start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time // or when current temp falls outside the hysteresis after target temp was reached @@ -3575,9 +3558,7 @@ inline void gcode_M109() { SERIAL_PROTOCOL_F(degBed(), 1); SERIAL_EOL; } - manage_heater(); - manage_inactivity(); - lcd_update(); + idle(); } LCD_MESSAGEPGM(MSG_BED_DONE); refresh_cmd_timeout(); @@ -4262,11 +4243,7 @@ inline void gcode_M226() { break; } - while(digitalRead(pin_number) != target) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } + while (digitalRead(pin_number) != target) idle(); } // pin_number > -1 } // pin_state -1 0 1 @@ -6253,6 +6230,15 @@ void disable_all_steppers() { disable_e3(); } +/** + * Standard idle routine keeps the machine alive + */ +void idle() { + manage_heater(); + manage_inactivity(); + lcd_update(); +} + /** * Manage several activities: * - Check for Filament Runout diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 3cd9894ca..02bde4877 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -478,11 +478,7 @@ float junction_deviation = 0.1; // If the buffer is full: good! That means we are well ahead of the robot. // Rest here until there is room in the buffer. - while(block_buffer_tail == next_buffer_head) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } + while (block_buffer_tail == next_buffer_head) idle(); #ifdef MESH_BED_LEVELING if (mbl.active) z += mbl.get_z(x, y); diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 438120c21..792649f54 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -1046,14 +1046,10 @@ void st_init() { } -// Block until all buffered steps are executed -void st_synchronize() { - while (blocks_queued()) { - manage_heater(); - manage_inactivity(); - lcd_update(); - } -} +/** + * Block until all buffered steps are executed + */ +void st_synchronize() { while (blocks_queued()) idle(); } void st_set_position(const long &x, const long &y, const long &z, const long &e) { CRITICAL_SECTION_START;