From 832c8b6012e7db029d323ec36bd4a64309fb557f Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Wed, 23 Mar 2016 14:28:13 -0700 Subject: [PATCH] dwell.{c,h} cleanup --- src/canonical_machine.c | 3 ++- src/plan/dwell.c | 12 +++++++----- src/plan/dwell.h | 32 ++++++++++++++++++++++++++++++++ src/plan/planner.h | 3 --- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/plan/dwell.h diff --git a/src/canonical_machine.c b/src/canonical_machine.c index 55f4058..acc4d56 100644 --- a/src/canonical_machine.c +++ b/src/canonical_machine.c @@ -110,8 +110,9 @@ #include "usart.h" // for serial queue flush #include "plan/planner.h" -#include "plan/arc.h" +#include "plan/dwell.h" #include "plan/command.h" +#include "plan/arc.h" #include #include diff --git a/src/plan/dwell.c b/src/plan/dwell.c index df28f67..4fa2621 100644 --- a/src/plan/dwell.c +++ b/src/plan/dwell.c @@ -27,19 +27,20 @@ \******************************************************************************/ +#include "dwell.h" + #include "planner.h" #include "canonical_machine.h" #include "stepper.h" // Dwells are performed by passing a dwell move to the stepper drivers. -// When the stepper driver sees a dwell it times the dwell on a separate -// timer than the stepper pulse timer. /// Dwell execution static stat_t _exec_dwell(mpBuf_t *bf) { st_prep_dwell(bf->gm.move_time); // in seconds + // free buffer & perform cycle_end if planner is empty if (mp_free_run_buffer()) cm_cycle_end(); @@ -49,14 +50,15 @@ static stat_t _exec_dwell(mpBuf_t *bf) { /// Queue a dwell stat_t mp_dwell(float seconds) { - mpBuf_t *bf; + mpBuf_t *bf = mp_get_write_buffer(); - if (!(bf = mp_get_write_buffer())) // get write buffer - return cm_hard_alarm(STAT_BUFFER_FULL_FATAL); // never supposed to fail + // never supposed to fail + if (!bf) return cm_hard_alarm(STAT_BUFFER_FULL_FATAL); bf->bf_func = _exec_dwell; // register callback to dwell start bf->gm.move_time = seconds; // in seconds, not minutes bf->move_state = MOVE_NEW; + // must be final operation before exit mp_commit_write_buffer(MOVE_TYPE_DWELL); diff --git a/src/plan/dwell.h b/src/plan/dwell.h new file mode 100644 index 0000000..36ea82d --- /dev/null +++ b/src/plan/dwell.h @@ -0,0 +1,32 @@ +/******************************************************************************\ + + This file is part of the Buildbotics firmware. + + Copyright (c) 2015 - 2016 Buildbotics LLC + All rights reserved. + + This file ("the software") is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License, + version 2 as published by the Free Software Foundation. You should + have received a copy of the GNU General Public License, version 2 + along with the software. If not, see . + + The software is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the software. If not, see + . + + For information regarding this software email: + "Joseph Coffland" + +\******************************************************************************/ + +#pragma once + +#include "status.h" + +stat_t mp_dwell(const float seconds); diff --git a/src/plan/planner.h b/src/plan/planner.h index cf9ee0b..a5eb65a 100644 --- a/src/plan/planner.h +++ b/src/plan/planner.h @@ -304,6 +304,3 @@ mpBuf_t *mp_get_last_buffer(); #define mp_get_next_buffer(b) ((mpBuf_t *)(b->nx)) void mp_clear_buffer(mpBuf_t *bf); void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp); - -// dwell.c functions -stat_t mp_dwell(const float seconds); -- 2.27.0