Merge pull request #557 from dhruvasagar/dev

Improve Stepper Driver
This commit is contained in:
Ron Evans 2018-05-30 13:33:01 +02:00 committed by GitHub
commit 180a4b5659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package gpio
import (
"errors"
"math"
"strconv"
"strings"
"sync"
"time"
@ -57,6 +58,7 @@ type StepperDriver struct {
stepNum int
speed uint
mutex *sync.Mutex
gobot.Commander
}
// NewStepperDriver returns a new StepperDriver given a
@ -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
}