Skip to content

Commit

Permalink
Add isPowered()
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
bblanchon committed May 27, 2024
1 parent e8adfd5 commit 1d6836a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HEAD
----

* Add `acceleration()` getter
* Add `isPowered()` (issue #17)

3.0.2
-----
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public:
// See StepperDriver and FourWireStepper below for details.
void powerOff();

// Tells whether the power is on.
bool isPowered() const;

// Sets the target speed.
// The shaft will smoothly accelerate or decelerate to reach the
// target speed.
Expand Down
3 changes: 2 additions & 1 deletion extras/tests/ContinuousStepperTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_executable(ContinuousStepperTests
acceleration.cpp
begin.cpp
isPowered.cpp
powerOff.cpp
powerOn.cpp
setEnablePin.cpp
Expand Down Expand Up @@ -40,4 +41,4 @@ add_test(
ContinuousStepperTests
COMMAND
ContinuousStepperTests
)
)
58 changes: 58 additions & 0 deletions extras/tests/ContinuousStepperTests/isPowered.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <ContinuousStepper.h>
#include <TestFixtures.hpp>

TEST_CASE("ContinuousStepper<StepperDriver>::isPowered()") {
ContinuousStepper<StepperDriver> stepper;

GIVEN("begin(10, 11) was called") {
stepper.begin(10, 11);

THEN("isPowered() should return true") {
CHECK(stepper.isPowered() == true);
}

AND_GIVEN("powerOff() is called") {
stepper.powerOff();

THEN("isPowered() should return false") {
CHECK(stepper.isPowered() == false);
}

AND_GIVEN("powerOn() is called") {
stepper.powerOn();

THEN("isPowered() should return true") {
CHECK(stepper.isPowered() == true);
}
}
}
}
}

TEST_CASE("ContinuousStepper<FourWireStepper>::isPowered()") {
ContinuousStepper<FourWireStepper> stepper;

GIVEN("begin(2, 3, 4, 5) was called") {
stepper.begin(2, 3, 4, 5);

THEN("isPowered() should return true") {
CHECK(stepper.isPowered() == true);
}

AND_GIVEN("powerOff() is called") {
stepper.powerOff();

THEN("isPowered() should return false") {
CHECK(stepper.isPowered() == false);
}

AND_GIVEN("powerOn() is called") {
stepper.powerOn();

THEN("isPowered() should return true") {
CHECK(stepper.isPowered() == true);
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/ContinuousStepper/ContinuousStepperImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ContinuousStepperImpl : public TTicker, TickListener, public TStepper, Ste
TTicker::setPeriod(0);
}

bool isPowered() const {
return status_ != OFF;
}

void spin(float_t speed) {
if (targetSpeed_ == speed)
return;
Expand Down

0 comments on commit 1d6836a

Please sign in to comment.