From aeb7fea57cd0bc40f741431a879f74ab2fc0ebb1 Mon Sep 17 00:00:00 2001 From: Laurentiu Badea Date: Sun, 27 Jan 2019 20:46:42 -0800 Subject: [PATCH] Added getStepsCompleted(), getStepsRemaining(), getDirection() incorporating changes from #72 by @harrylisby #73 by @tognotommy Addresses #57 and #45 --- src/BasicStepperDriver.cpp | 6 ++++-- src/BasicStepperDriver.h | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/BasicStepperDriver.cpp b/src/BasicStepperDriver.cpp index 8ca9f92..2829b0e 100644 --- a/src/BasicStepperDriver.cpp +++ b/src/BasicStepperDriver.cpp @@ -197,10 +197,12 @@ void BasicStepperDriver::startBrake(void){ } } /* - * Stop movement immediately. + * Stop movement immediately and return remaining steps. */ -void BasicStepperDriver::stop(void){ +long BasicStepperDriver::stop(void){ + long retval = steps_remaining; steps_remaining = 0; + return retval; } /* * Return calculated time to complete the given move diff --git a/src/BasicStepperDriver.h b/src/BasicStepperDriver.h index 3be2370..835a160 100644 --- a/src/BasicStepperDriver.h +++ b/src/BasicStepperDriver.h @@ -204,13 +204,33 @@ class BasicStepperDriver { void startBrake(void); /* * Immediate stop + * Returns the number of steps remaining. */ - void stop(void); + long stop(void); /* * State querying */ enum State getCurrentState(void); - + /* + * Get the number of completed steps so far. + * This is always a positive number + */ + long getStepsCompleted(void){ + return step_count; + } + /* + * Get the number of steps remaining to complete the move + * This is always a positive number + */ + long getStepsRemaining(void){ + return steps_remaining; + } + /* + * Get movement direction: forward +1, back -1 + */ + int getDirection(void){ + return (dir_state == HIGH) ? 1 : -1; + } /* * Return calculated time to complete the given move */