Skip to content

Commit

Permalink
Issue #32 change brakePin and limitSwich type to signed char
Browse files Browse the repository at this point in the history
  • Loading branch information
pkerspe committed Jan 21, 2023
1 parent c9560fc commit 3a88b9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/pkerspe/ESP-FlexyStepper.git"
},
"version": "1.4.5",
"version": "1.4.6",
"license": "MIT",
"frameworks": "arduino",
"platforms": [
Expand Down
16 changes: 8 additions & 8 deletions src/ESP_FlexyStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void ESP_FlexyStepper::setDirectionToHome(signed char directionTowardHome)
* whether the limit switch near the begin (direction of home position) or at the end of the movement has ben triggered.
* It is strongly recommended to perform debouncing before calling this function to prevent issues when button is released and retriggering the limit switch function
*/
void ESP_FlexyStepper::setLimitSwitchActive(byte limitSwitchType)
void ESP_FlexyStepper::setLimitSwitchActive(signed char limitSwitchType)
{
if (limitSwitchType == LIMIT_SWITCH_BEGIN || limitSwitchType == LIMIT_SWITCH_END || limitSwitchType == LIMIT_SWITCH_COMBINED_BEGIN_AND_END)
{
Expand Down Expand Up @@ -279,7 +279,7 @@ void ESP_FlexyStepper::connectToPins(byte stepPinNumber, byte directionPinNumber
* active high = 1, active low = 2
* Will be set to ative high by default or if an invalid value is given
*/
void ESP_FlexyStepper::setBrakePin(byte brakePin, byte activeState)
void ESP_FlexyStepper::setBrakePin(signed char brakePin, byte activeState)
{
this->brakePin = brakePin;
if (activeState == ESP_FlexyStepper::ACTIVE_HIGH || activeState == ESP_FlexyStepper::ACTIVE_LOW)
Expand All @@ -294,7 +294,7 @@ void ESP_FlexyStepper::setBrakePin(byte brakePin, byte activeState)
if (this->brakePin >= 0)
{
// configure the IO pins
pinMode(this->brakePin, OUTPUT);
pinMode((uint8_t)this->brakePin, OUTPUT);
this->deactivateBrake();
_isBrakeConfigured = true;
}
Expand All @@ -315,7 +315,7 @@ void ESP_FlexyStepper::setBrakeEngageDelayMs(unsigned long delay)
}

/**
* set a timeout in milliseconds after which the brake shall be released once triggered and no motion is performed by the stpper motor.
* set a timeout in milliseconds after which the brake shall be released once triggered and no motion is performed by the stepper motor.
* By default the value is -1 indicating, that the brake shall never be automatically released, as long as the stepper motor is not moving to a new position.
* Value must be larger than 1 (Even though 1ms delay does probably not make any sense since physical brakes have a delay that is most likely higher than that just to engange)
*/
Expand All @@ -338,7 +338,7 @@ void ESP_FlexyStepper::activateBrake()
{
if (this->_isBrakeConfigured)
{
digitalWrite(this->brakePin, (this->brakePinActiveState == ESP_FlexyStepper::ACTIVE_HIGH) ? 1 : 0);
digitalWrite((uint8_t)this->brakePin, (this->brakePinActiveState == ESP_FlexyStepper::ACTIVE_HIGH) ? 1 : 0);
this->_isBrakeActive = true;
this->_timeToEngangeBrake = LONG_MAX;
}
Expand All @@ -351,7 +351,7 @@ void ESP_FlexyStepper::deactivateBrake()
{
if (this->_isBrakeConfigured)
{
digitalWrite(this->brakePin, (this->brakePinActiveState == ESP_FlexyStepper::ACTIVE_HIGH) ? 0 : 1);
digitalWrite((uint8_t)this->brakePin, (this->brakePinActiveState == ESP_FlexyStepper::ACTIVE_HIGH) ? 0 : 1);
this->_isBrakeActive = false;
this->_timeToReleaseBrake = LONG_MAX;
this->_hasMovementOccuredSinceLastBrakeRelease = false;
Expand Down Expand Up @@ -1255,6 +1255,7 @@ bool ESP_FlexyStepper::processMovement(void)
if (this->_isBrakeConfigured && this->_isBrakeActive)
{
this->deactivateBrake();
//TODO: For Feature Request https://github.com/pkerspe/ESP-StepperMotor-Server/issues/16 we might need to set a timer and return here to prevent issuing the stepPin singal before the break is released
}

// execute the step on the rising edge
Expand All @@ -1270,11 +1271,10 @@ bool ESP_FlexyStepper::processMovement(void)
// figure out how long before the next step
DeterminePeriodOfNextStep();

this->_hasMovementOccuredSinceLastBrakeRelease = true;
// return the step line low
digitalWrite(stepPin, LOW);

this->_hasMovementOccuredSinceLastBrakeRelease = true;

// check if the move has reached its final target position, return true if all
// done
if (currentPosition_InSteps == targetPosition_InSteps)
Expand Down
6 changes: 3 additions & 3 deletions src/ESP_FlexyStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ESP_FlexyStepper

//IO setup and helper / debugging functions
void connectToPins(byte stepPinNumber, byte directionPinNumber=255);
void setBrakePin(byte brakePin, byte activeState = ESP_FlexyStepper::ACTIVE_HIGH);
void setBrakePin(signed char brakePin, byte activeState = ESP_FlexyStepper::ACTIVE_HIGH);
long getTaskStackHighWaterMark(void);
void clearLimitSwitchActive(void);
bool motionComplete();
Expand Down Expand Up @@ -97,7 +97,7 @@ class ESP_FlexyStepper
void setAccelerationInStepsPerSecondPerSecond(float accelerationInStepsPerSecondPerSecond);
void setDecelerationInStepsPerSecondPerSecond(float decelerationInStepsPerSecondPerSecond);
void setDirectionToHome(signed char directionTowardHome);
void setLimitSwitchActive(byte limitSwitchType);
void setLimitSwitchActive(signed char limitSwitchType);

void setBrakeEngageDelayMs(unsigned long);
void setBrakeReleaseDelayMs(signed long);
Expand Down Expand Up @@ -168,7 +168,7 @@ class ESP_FlexyStepper
void triggerBrakeIfNeededOrSetTimeout(void);

byte stepPin;
byte brakePin = -1;
signed char brakePin = -1;
byte brakePinActiveState = ACTIVE_HIGH;
unsigned long _brakeEngageDelayMs = 0;
signed long _brakeReleaseDelayMs = -1;
Expand Down

0 comments on commit 3a88b9e

Please sign in to comment.