From bd01ee779b04e4202eb229e051389ec09e0fc6ff Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Sun, 18 Sep 2016 12:15:13 -0400 Subject: [PATCH] Consolidated some power management functions; fixed a bug in status reports where SR_VERBOSE mode created filtered reports --- g2core/report.cpp | 3 ++- g2core/stepper.cpp | 41 ++++++++++++----------------------------- g2core/stepper.h | 8 +++++--- 3 files changed, 19 insertions(+), 33 deletions(-) mode change 100755 => 100644 g2core/report.cpp diff --git a/g2core/report.cpp b/g2core/report.cpp old mode 100755 new mode 100644 index 0058a5a5..e7fca4eb --- a/g2core/report.cpp +++ b/g2core/report.cpp @@ -296,7 +296,8 @@ stat_t sr_status_report_callback() // called by controller dispatcher } sr.status_report_request = SR_OFF; - if (sr.status_report_request == SR_VERBOSE) { + if ((sr.status_report_request == SR_VERBOSE) || + (sr.status_report_verbosity == SR_VERBOSE)) { _populate_unfiltered_status_report(); } else { if (_populate_filtered_status_report() == false) { // no new data diff --git a/g2core/stepper.cpp b/g2core/stepper.cpp index d60b5a0d..e3017a6c 100644 --- a/g2core/stepper.cpp +++ b/g2core/stepper.cpp @@ -192,28 +192,6 @@ stat_t st_clc(nvObj_t *nv) // clear diagnostic counters, reset stepper prep return(STAT_OK); } -/* - * Motor power management functions - * - * st_energize_motors() - apply power to all motors - * st_deenergize_motors() - remove power from all motors - * st_motor_power_callback() - callback to manage motor power sequencing - */ - -void st_energize_motors(float timeout_seconds) -{ - for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) { - Motors[motor]->enable(timeout_seconds); - } -} - -void st_deenergize_motors() -{ - for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) { - Motors[motor]->disable(); - } -} - /* * st_motor_power_callback() - callback to manage motor power sequencing * @@ -977,18 +955,23 @@ stat_t st_set_mt(nvObj_t *nv) return (STAT_OK); } -stat_t st_set_md(nvObj_t *nv) // Make sure this function is not part of initialization --> f00 +stat_t st_set_me(nvObj_t *nv) // Make sure this function is not part of initialization --> f00 { - st_deenergize_motors(); + for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) { + Motors[motor]->enable(nv->value); // nv->value is the timeout or 0 for default + } return (STAT_OK); } -stat_t st_set_me(nvObj_t *nv) // Make sure this function is not part of initialization --> f00 +stat_t st_set_md(nvObj_t *nv) // Make sure this function is not part of initialization --> f00 { - if (((uint8_t)nv->value == 0) || (nv->valuetype == TYPE_NULL)) { - st_energize_motors(st_cfg.motor_power_timeout); - } else { - st_energize_motors(nv->value); + // de-energize all motors + if ((uint8_t)nv->value == 0) { // 0 means all motors + for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) { + Motors[motor]->disable(); + } + } else { // otherwise it's just one motor + Motors[(uint8_t)nv->value -1]->disable(); } return (STAT_OK); } diff --git a/g2core/stepper.h b/g2core/stepper.h index 2bb1d36f..f0bea198 100644 --- a/g2core/stepper.h +++ b/g2core/stepper.h @@ -478,6 +478,7 @@ struct Stepper { // }; // turn on motor in all cases unless it's disabled + // NOTE: in the future the default assigned timeout will be the motor's default value void enable(float timeout = st_cfg.motor_power_timeout) { if (_power_mode == MOTOR_DISABLED) { @@ -485,6 +486,10 @@ struct Stepper { } this->_enableImpl(); _power_state = MOTOR_RUNNING; + + if ((uint8_t)timeout == 0) { + timeout = st_cfg.motor_power_timeout; + } _motor_disable_timeout_ms = timeout * 1000.0; }; @@ -554,9 +559,6 @@ stat_t stepper_test_assertions(void); bool st_runtime_isbusy(void); stat_t st_clc(nvObj_t *nv); - -void st_energize_motors(float timeout_seconds); -void st_deenergize_motors(void); void st_set_motor_power(const uint8_t motor); stat_t st_motor_power_callback(void);