Skip to content

Commit

Permalink
Improve Stepper Driver
Browse files Browse the repository at this point in the history
* Ensure StepperDriver embeds gobot.Commander to allow for command
  driven workflow
* Add a few core commands available out of the box for control via
  command workflow
  • Loading branch information
dhruvasagar committed May 28, 2018
1 parent e7e5fca commit 24de9c0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion drivers/gpio/stepper_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gpio
import (
"errors"
"math"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -57,6 +58,7 @@ type StepperDriver struct {
stepNum int
speed uint
mutex *sync.Mutex
gobot.Commander
}

// NewStepperDriver returns a new StepperDriver given a
Expand All @@ -76,9 +78,21 @@ func NewStepperDriver(a DigitalWriter, pins [4]string, phase phase, stepsPerRev
stepNum: 0,
speed: 1,
mutex: &sync.Mutex{},
Commander: gobot.NewCommander(),
}

s.speed = s.GetMaxSpeed()

s.AddCommand("Move", func(params map[string]interface{}) interface{} {
steps, _ := strconv.Atoi(params["steps"].(string))
return s.Move(steps)
})
s.AddCommand("Run", func(params map[string]interface{}) interface{} {
return s.Run()
})
s.AddCommand("Halt", func(params map[string]interface{}) interface{} {
return s.Halt()
})

return s
}

Expand Down

0 comments on commit 24de9c0

Please sign in to comment.