Skip to content

Commit c733673

Browse files
committed
add start parameter to moveTimed
1 parent 160eb82 commit c733673

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/FastAccelStepper.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,14 @@ int32_t FastAccelStepper::getCurrentPosition() {
912912
return fas_queue[_queue_num].getCurrentPosition();
913913
}
914914
int8_t FastAccelStepper::moveTimed(int16_t steps, uint32_t duration,
915-
uint32_t& actual_duration) {
916-
// For now only a very crude implementation
915+
uint32_t& actual_duration,
916+
bool start) {
917+
if ((steps == 0) && (duration == 0)) {
918+
if (start) {
919+
addQueueEntry(NULL, true); // start the queue
920+
}
921+
return MOVE_TIMED_OK;
922+
}
917923
uint8_t freeEntries = QUEUE_LEN - queueEntries();
918924
actual_duration = 0;
919925
struct stepper_command_s cmd = {.ticks = 0, .steps = 0, .count_up = true};
@@ -937,7 +943,7 @@ int8_t FastAccelStepper::moveTimed(int16_t steps, uint32_t duration,
937943
// cmd.
938944
cmd.ticks = duration >> 1;
939945
}
940-
uint8_t ret = addQueueEntry(&cmd);
946+
uint8_t ret = addQueueEntry(&cmd,start);
941947
if (ret != 0) {
942948
// unexpected
943949
return ret;
@@ -988,7 +994,7 @@ int8_t FastAccelStepper::moveTimed(int16_t steps, uint32_t duration,
988994
}
989995
this_duration -= cmd.ticks;
990996

991-
uint8_t ret = addQueueEntry(&cmd);
997+
uint8_t ret = addQueueEntry(&cmd,start);
992998
if (ret != 0) {
993999
// unexpected
9941000
return ret;
@@ -1032,7 +1038,7 @@ int8_t FastAccelStepper::moveTimed(int16_t steps, uint32_t duration,
10321038
printf("increase ticks for %d steps\n", steps);
10331039
#endif
10341040
}
1035-
uint8_t ret = addQueueEntry(&cmd);
1041+
uint8_t ret = addQueueEntry(&cmd,start);
10361042
if (ret != 0) {
10371043
// unexpected
10381044
return ret;

src/FastAccelStepper.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,18 @@ class FastAccelStepper {
622622
// The main purpose is to bypass the ramp generator as mentioned in
623623
// [#299](https://github.com/gin66/FastAccelStepper/issues/299).
624624
// This shall allow to run consecutive small moves with fixed speed.
625-
// The parameters are distance (which can be 0) and duration in ticks.
626-
// Distance 0 makes sense in order to keep the time running and not
625+
// The parameters are steps (which can be 0) and duration in ticks.
626+
// steps=0 makes sense in order to keep the time running and not
627627
// getting out of sync.
628628
// Due to integer arithmetics the actual duration may be off by a small value.
629629
// That's why the actual_duration in TICKS is returned.
630630
// The application should consider this for the next runTimed move.
631631
//
632+
// The optional parameter is a boolean called start. This allows for the first
633+
// invocation to not start the queue yet. This is for managing steppers in parallel.
634+
// It allows to fill all steppers' queues and then kick it off by a call to
635+
// `moveTimed(0,0,true)`. Successive invocations can keep true.
636+
//
632637
// In order to not have another lightweight ramp generator running in
633638
// background interrupt, the expecation to the application is, that this
634639
// function is frequently enough called without the queue being emptied.
@@ -656,7 +661,7 @@ class FastAccelStepper {
656661
#define MOVE_TIMED_BUSY ((int8_t)5)
657662
#define MOVE_TIMED_EMPTY ((int8_t)6)
658663
#define MOVE_TIMED_TOO_LARGE_ERROR ((int8_t)-4)
659-
int8_t moveTimed(int16_t steps, uint32_t duration, uint32_t& actual_duration);
664+
int8_t moveTimed(int16_t steps, uint32_t duration, uint32_t& actual_duration, bool start = true);
660665

661666
// ## Low Level Stepper Queue Management (low level access)
662667
//

0 commit comments

Comments
 (0)