diff --git a/components/step_motor_45/step_motor_45.cpp b/components/step_motor_45/step_motor_45.cpp index faa0f4c..f678283 100644 --- a/components/step_motor_45/step_motor_45.cpp +++ b/components/step_motor_45/step_motor_45.cpp @@ -57,16 +57,20 @@ void StepMotor45::initialize(cfg_t cfg) { return; } -void StepMotor45::rotate(bool direction, int speed) { +void StepMotor45::rotate(int direction, int speed) { CriticalContext cc; - if (direction) { + if (direction == 0) { + stop(); + } + + if (direction > 0) { if (getzeropinstate()) { m_calibration = true; m_pos = 0; } } posmode = false; - m_state = direction ? kforward_rotation : krollback; + m_state = direction > 0 ? kforward_rotation : krollback; ZLOGI(TAG, "rotate %d", direction); } void StepMotor45::stop() { diff --git a/components/step_motor_45/step_motor_45.hpp b/components/step_motor_45/step_motor_45.hpp index 85fb920..36b46a5 100644 --- a/components/step_motor_45/step_motor_45.hpp +++ b/components/step_motor_45/step_motor_45.hpp @@ -61,8 +61,8 @@ class StepMotor45 { public: void initialize(cfg_t cfg); - void rotate(bool direction) { rotate(direction, defaultspeed); } - void rotate(bool direction, int speed); + void rotate(int direction) { rotate(direction, defaultspeed); } + void rotate(int direction, int speed); void moveBy(int pos, int speed); void moveBy(int pos) { moveBy(pos, defaultspeed); } @@ -72,6 +72,7 @@ class StepMotor45 { bool isReachTargetPos(); void stop(); void zeroCalibration(); + void setPos(int pos) { m_pos = pos; } int getPos() { return m_pos; }