Skip to content

Commit

Permalink
Beta - Board wont crash if limit switch for steppers is configured (#276
Browse files Browse the repository at this point in the history
)
  • Loading branch information
elral authored Nov 12, 2023
1 parent d874cf8 commit e8d8656
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
31 changes: 26 additions & 5 deletions src/MF_Stepper/MFStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void MFStepper::detach()

void MFStepper::moveTo(long newPosition)
{
if (!_initialized)
return;

_resetting = false;
long currentPosition = _stepper->currentPosition();

Expand All @@ -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);
Expand All @@ -115,6 +116,9 @@ void MFStepper::setZero()

void MFStepper::setZeroInReset()
{
if (!_initialized)
return;

if (_resetting) {
_stepper->setCurrentPosition(0);
_resetting = false;
Expand All @@ -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;
Expand All @@ -132,6 +139,9 @@ void MFStepper::checkZeroPin()

void MFStepper::update()
{
if (!_initialized)
return;

_stepper->run();
checkZeroPin();
if (_stepper->currentPosition() == (_targetPos + _backlash * _inMove) && _deactivateOutput) {
Expand All @@ -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;
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/MF_Stepper/MFStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e8d8656

Please sign in to comment.