diff --git a/src/Config.cpp b/src/Config.cpp index 86cf15dc..97dc2c3b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -387,7 +387,7 @@ void readConfig() params[6] = (uint8_t)0; // backlash params[7] = false; // deactivate output - if (command == kTypeStepperDeprecated2) { + if (command == kTypeStepperDeprecated2 || command == kTypeStepper) { params[4] = readUintFromEEPROM(&addreeprom); // Button number } diff --git a/src/MF_Stepper/MFStepper.cpp b/src/MF_Stepper/MFStepper.cpp index b894866e..e29b7687 100644 --- a/src/MF_Stepper/MFStepper.cpp +++ b/src/MF_Stepper/MFStepper.cpp @@ -82,6 +82,9 @@ void MFStepper::detach() void MFStepper::moveTo(long newPosition) { + if (!_initialized) + return; + _resetting = false; long currentPosition = _stepper->currentPosition(); @@ -100,13 +103,11 @@ void MFStepper::moveTo(long newPosition) } } -uint8_t MFStepper::getZeroPin() -{ - return _zeroPin; -} - void MFStepper::setZero() { + if (!_initialized) + return; + _stepper->setCurrentPosition(0); if (_inMove == MOVE_CW) { _stepper->moveTo(-_backlash); @@ -115,6 +116,9 @@ void MFStepper::setZero() void MFStepper::setZeroInReset() { + if (!_initialized) + return; + if (_resetting) { _stepper->setCurrentPosition(0); _resetting = false; @@ -123,6 +127,9 @@ void MFStepper::setZeroInReset() void MFStepper::checkZeroPin() { + if (!_initialized) + return; + uint8_t newState = (uint8_t)digitalRead(_zeroPin); if (newState != _zeroPinState) { _zeroPinState = newState; @@ -132,6 +139,9 @@ void MFStepper::checkZeroPin() void MFStepper::update() { + if (!_initialized) + return; + _stepper->run(); checkZeroPin(); if (_stepper->currentPosition() == (_targetPos + _backlash * _inMove) && _deactivateOutput) { @@ -142,6 +152,9 @@ void MFStepper::update() void MFStepper::reset() { + if (!_initialized) + return; + // we are not a auto reset stepper if this pin is 0 if (_zeroPin == 0) return; @@ -159,16 +172,24 @@ void MFStepper::reset() void MFStepper::setMaxSpeed(uint16_t speed) { + if (!_initialized) + return; + _stepper->setMaxSpeed(speed); } void MFStepper::setAcceleration(uint16_t acceleration) { + if (!_initialized) + return; + _stepper->setAcceleration(acceleration); } void MFStepper::powerSavingMode(bool state) { + if (!_initialized) + return; if (state) _stepper->disableOutputs(); else diff --git a/src/MF_Stepper/MFStepper.h b/src/MF_Stepper/MFStepper.h index 2e914e16..2110472c 100644 --- a/src/MF_Stepper/MFStepper.h +++ b/src/MF_Stepper/MFStepper.h @@ -24,7 +24,6 @@ class MFStepper void setMaxSpeed(uint16_t speed); void setAcceleration(uint16_t acceleration); void setZero(); - uint8_t getZeroPin(); void powerSavingMode(bool state); private: