update button handling
This commit is contained in:
40
stepper.cpp
40
stepper.cpp
@ -4,7 +4,7 @@
|
||||
|
||||
void Stepper::tick()
|
||||
{
|
||||
if(++_tickCounter > UINT8_MAX - (_speed>>8) )
|
||||
if(++_tickCounter > UINT16_MAX - _speed )
|
||||
{
|
||||
if(_targetStep != _currentStep)
|
||||
{
|
||||
@ -13,8 +13,13 @@ void Stepper::tick()
|
||||
else if(endlessMove) step(endlessDriection);
|
||||
_tickCounter = 0;
|
||||
}
|
||||
if(_speed>>8 < _targetSpeed) _speed = _speed + acceleration;
|
||||
else if(_speed>>8 > _targetSpeed)_speed = _speed - acceleration;;
|
||||
/*else if(halfCurrent)
|
||||
{
|
||||
if(_tickCounter % 2 == 0) disableOutputs();
|
||||
else setOutputs();
|
||||
}*/
|
||||
if(_speed < _targetSpeed) _speed = _speed + acceleration;
|
||||
else if(_speed > _targetSpeed)_speed = _speed - acceleration;
|
||||
}
|
||||
|
||||
void Stepper::moveTo(const int32_t step)
|
||||
@ -27,7 +32,7 @@ void Stepper::moveRelative(const int16_t dist)
|
||||
moveTo(_targetStep + dist);
|
||||
}
|
||||
|
||||
void Stepper::setSpeed(const uint8_t speed)
|
||||
void Stepper::setSpeed(const uint16_t speed)
|
||||
{
|
||||
_targetSpeed = speed;
|
||||
if(_targetSpeed < speedFloor) _targetSpeed = speedFloor;
|
||||
@ -53,7 +58,22 @@ bool Stepper::isStoped()
|
||||
return _currentStep == _targetStep;
|
||||
}
|
||||
|
||||
void Stepper::step(bool direction)
|
||||
void Stepper::shutdown()
|
||||
{
|
||||
_currentStep = _targetStep;
|
||||
_speed = 0;
|
||||
disableOutputs();
|
||||
}
|
||||
|
||||
void Stepper::disableOutputs()
|
||||
{
|
||||
writePin(_port, _pinA, false);
|
||||
writePin(_port, _pinB, false);
|
||||
writePin(_port, _pinC, false);
|
||||
writePin(_port, _pinD, false);
|
||||
}
|
||||
|
||||
void Stepper::setOutputs()
|
||||
{
|
||||
switch(_currentStep & 0x03)
|
||||
{
|
||||
@ -87,6 +107,16 @@ void Stepper::step(bool direction)
|
||||
writePin(_port, _pinC, false);
|
||||
writePin(_port, _pinD, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Stepper::setHalfCurrent( bool current)
|
||||
{
|
||||
halfCurrent = current;
|
||||
}
|
||||
|
||||
void Stepper::step(bool direction)
|
||||
{
|
||||
_currentStep = _currentStep + (direction ? 1 : -1);
|
||||
if(endlessMove) _targetStep = _currentStep;
|
||||
setOutputs();
|
||||
}
|
||||
|
Reference in New Issue
Block a user