From 5322ef1fac5887de729a5b174464a490ae6bbc2d Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Mon, 12 Feb 2018 22:01:40 -0800 Subject: [PATCH] Fixed dwell and report dwell time --- src/avr/src/command.c | 2 +- src/avr/src/commands.c | 14 +++++++++++++- src/avr/src/stepper.c | 11 ++++++++++- src/avr/src/vars.def | 3 ++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/avr/src/command.c b/src/avr/src/command.c index 2ad1a95..4fcea2c 100644 --- a/src/avr/src/command.c +++ b/src/avr/src/command.c @@ -258,7 +258,7 @@ bool command_exec() { unsigned size = _size(code); static uint8_t data[INPUT_BUFFER_LEN]; - for (int i = 0; i < size; i++) + for (unsigned i = 0; i < size; i++) data[i] = sync_q_next(); cmd.count--; diff --git a/src/avr/src/commands.c b/src/avr/src/commands.c index ee10a8f..aa6670c 100644 --- a/src/avr/src/commands.c +++ b/src/avr/src/commands.c @@ -34,6 +34,7 @@ #include "hardware.h" #include "report.h" #include "state.h" +#include "exec.h" #include "util.h" #include @@ -48,8 +49,19 @@ stat_t command_dwell(char *cmd) { } +static stat_t _dwell_exec() { + exec_set_cb(0); + return STAT_OK; +} + + unsigned command_dwell_size() {return sizeof(float);} -void command_dwell_exec(float *seconds) {st_prep_dwell(*seconds);} + + +void command_dwell_exec(float *seconds) { + st_prep_dwell(*seconds); + exec_set_cb(_dwell_exec); // Necessary evil +} // TODO diff --git a/src/avr/src/stepper.c b/src/avr/src/stepper.c index a337c1b..11b8677 100644 --- a/src/avr/src/stepper.c +++ b/src/avr/src/stepper.c @@ -64,7 +64,7 @@ typedef struct { } stepper_t; -static stepper_t st = {0}; +static volatile stepper_t st = {0}; void stepper_init() { @@ -233,3 +233,12 @@ void st_prep_dwell(float seconds) { // Var callbacks uint32_t get_underflow() {return st.underflow;} + + +float get_dwell_time() { + float dwell; + cli(); + dwell = st.dwell; + sei(); + return dwell; +} diff --git a/src/avr/src/vars.def b/src/avr/src/vars.def index 15b79a5..2a12f8b 100644 --- a/src/avr/src/vars.def +++ b/src/avr/src/vars.def @@ -113,6 +113,7 @@ VAR(hw_id, hid, str, 0, 0, 1, "Hardware ID") VAR(echo, ec, bool, 0, 1, 1, "Enable or disable echo") VAR(estop, es, bool, 0, 1, 1, "Emergency stop") VAR(estop_reason, er, pstr, 0, 0, 1, "Emergency stop reason") -VAR(state, x, pstr, 0, 0, 1, "Machine state") +VAR(state, xx, pstr, 0, 0, 1, "Machine state") VAR(hold_reason, pr, pstr, 0, 0, 1, "Machine pause reason") VAR(underflow, un, u32, 0, 0, 1, "Stepper underflow count") +VAR(dwell_time, dt, f32, 0, 0, 1, "Dwell timer") -- 2.27.0