Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket committed Dec 2, 2017
1 parent 0fa30ae commit 1092580
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/gpio/stepper_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,18 @@ func (s *StepperDriver) Move(stepsToMove int) error {
if stepsToMove < 0 {
s.direction = "backward"
}
defer s.mutex.Unlock()
s.mutex.Unlock()

stepsLeft := int64(math.Abs(float64(stepsToMove)))
//Do not remove *1000 and change duration to time.Millisecond. It has been done for a reason
delay := time.Duration(60000*1000/(s.stepsPerRev*s.speed)) * time.Microsecond

for stepsLeft > 0 {
if err := s.step(); err != nil {
return err
}
stepsLeft--
time.Sleep(delay) //adjust accordingly
time.Sleep(delay)
}

s.moving = false
Expand All @@ -217,7 +218,7 @@ func (s *StepperDriver) GetMaxSpeed() uint {
// SetSpeed sets the rpm
func (s *StepperDriver) SetSpeed(rpm uint) error {
if rpm <= 0 {
return errors.New("RPM cannot be a negative value")
return errors.New("RPM cannot be a zero or negative value")
}

m := s.GetMaxSpeed()
Expand Down

0 comments on commit 1092580

Please sign in to comment.