Cleanup gopigo adapter, update examples

This commit is contained in:
Ulises Flynn 2017-09-12 14:19:39 -06:00
parent d362e47874
commit afbae9f697
3 changed files with 19 additions and 32 deletions

View File

@ -13,7 +13,7 @@ import (
)
func main() {
gopigo3Adaptor := g.NewAdaptor("/dev/spidev0.1", 0, 500000)
gopigo3Adaptor := g.NewAdaptor()
gopigo3 := g.NewGoPiGo3Driver(gopigo3Adaptor)
work := func() {

View File

@ -23,7 +23,7 @@ import (
)
func main() {
gopigo3Adaptor := g.NewAdaptor("/dev/spidev0.1", 0, 500000)
gopigo3Adaptor := g.NewAdaptor()
gopigo3 := g.NewGoPiGo3Driver(gopigo3Adaptor)
work := func() {

View File

@ -13,32 +13,19 @@ var _ gobot.Adaptor = (*Adaptor)(nil)
type Adaptor struct {
name string
port string
spiMode xspi.Mode
maxSpeed int64
spiDefaultMode xspi.Mode
spiDefaultMaxSpeed int64
connection spi.SPIDevice
writeBytesChannel chan []byte
finalizeChannel chan struct{}
}
func NewAdaptor(port string, mode int, maxSpeed int64) *Adaptor {
var spiMode xspi.Mode
switch mode {
case 0:
spiMode = xspi.Mode0
case 1:
spiMode = xspi.Mode1
case 2:
spiMode = xspi.Mode2
case 3:
spiMode = xspi.Mode3
default:
spiMode = xspi.Mode0
}
func NewAdaptor() *Adaptor {
return &Adaptor{
name: "GoPiGo3",
port: port,
spiMode: spiMode,
maxSpeed: maxSpeed,
port: "/dev/spidev0.1", //gopigo3 uses chip select CE1 on raspberry pi
spiDefaultMode: xspi.Mode0,
spiDefaultMaxSpeed: 500000,
connection: nil,
writeBytesChannel: make(chan []byte),
finalizeChannel: make(chan struct{}),
@ -57,8 +44,8 @@ func (a *Adaptor) Connect() error {
if a.connection == nil {
devfs := &xspi.Devfs{
Dev: a.port,
Mode: a.spiMode,
MaxSpeed: a.maxSpeed,
Mode: a.spiDefaultMode,
MaxSpeed: a.spiDefaultMaxSpeed,
}
con, err := xspi.Open(devfs)
if err != nil {