From e24b7ce06ac1427b6e69d7d0fc9e84278ed61adc Mon Sep 17 00:00:00 2001 From: Petr Krejci Date: Wed, 2 Nov 2022 22:08:47 +0100 Subject: [PATCH] Auto sleep stepper --- grbl/defaults.h | 13 +++++++++++++ grbl/protocol.c | 30 ++++++++++++++++++++++++++++++ grbl/report.c | 1 + grbl/settings.c | 4 +++- grbl/settings.h | 3 ++- grbl/stepper.c | 15 ++++++++++++--- grbl/stepper.h | 3 +++ 7 files changed, 64 insertions(+), 5 deletions(-) diff --git a/grbl/defaults.h b/grbl/defaults.h index 2e461300..a57b4b77 100644 --- a/grbl/defaults.h +++ b/grbl/defaults.h @@ -47,6 +47,7 @@ #define DEFAULT_STEPPING_INVERT_MASK 0 #define DEFAULT_DIRECTION_INVERT_MASK 0 #define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled) + #define DEFAULT_AUTOSLEEP 10 // minutes #define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm #define DEFAULT_ARC_TOLERANCE 0.002 // mm @@ -89,6 +90,7 @@ #define DEFAULT_STEPPING_INVERT_MASK 0 #define DEFAULT_DIRECTION_INVERT_MASK ((1< 0) { + stepper_sleep--; + _delay_ms(1); + } + } else { + // I will do something, so don't sleep + stepper_sleep = stepper_sleep_counts; + } + } } return; /* Never reached */ diff --git a/grbl/report.c b/grbl/report.c index 000836fa..f7b11630 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -208,6 +208,7 @@ void report_grbl_settings() { #else report_util_uint8_setting(32,0); #endif + report_util_uint8_setting(33,settings.auto_sleep); // Print axis settings uint8_t idx, set_idx; uint8_t val = AXIS_SETTINGS_START_VAL; diff --git a/grbl/settings.c b/grbl/settings.c index a9c830e7..1f3dfe60 100644 --- a/grbl/settings.c +++ b/grbl/settings.c @@ -57,7 +57,8 @@ const __flash settings_t defaults = {\ .acceleration[Z_AXIS] = DEFAULT_Z_ACCELERATION, .max_travel[X_AXIS] = (-DEFAULT_X_MAX_TRAVEL), .max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL), - .max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL)}; + .max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL), + .auto_sleep = DEFAULT_AUTOSLEEP }; // Method to store startup lines into EEPROM @@ -286,6 +287,7 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { case 27: settings.homing_pulloff = value; break; case 30: settings.rpm_max = value; spindle_init(); break; // Re-initialize spindle rpm calibration case 31: settings.rpm_min = value; spindle_init(); break; // Re-initialize spindle rpm calibration + case 33: settings.auto_sleep = int_value; break; // autosleep sec case 32: #ifdef VARIABLE_SPINDLE if (int_value) { settings.flags |= BITFLAG_LASER_MODE; } diff --git a/grbl/settings.h b/grbl/settings.h index 2d83ba9f..601f25a6 100644 --- a/grbl/settings.h +++ b/grbl/settings.h @@ -27,7 +27,7 @@ // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl // when firmware is upgraded. Always stored in byte 0 of eeprom -#define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version. +#define SETTINGS_VERSION 11 // NOTE: Check settings_reset() when moving to next version. // Define bit flag masks for the boolean settings in settings.flag. #define BIT_REPORT_INCHES 0 @@ -110,6 +110,7 @@ typedef struct { float homing_seek_rate; uint16_t homing_debounce_delay; float homing_pulloff; + uint8_t auto_sleep; } settings_t; extern settings_t settings; diff --git a/grbl/stepper.c b/grbl/stepper.c index 8e0b151d..328217a8 100644 --- a/grbl/stepper.c +++ b/grbl/stepper.c @@ -262,11 +262,20 @@ void st_go_idle() delay_ms(settings.stepper_idle_lock_time); pin_state = true; // Override. Disable steppers. } - if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { pin_state = !pin_state; } // Apply pin invert. - if (pin_state) { STEPPERS_DISABLE_PORT |= (1<