Skip to content

Commit

Permalink
Cleanup gopigo adapter, update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesflynn committed Sep 12, 2017
1 parent d362e47 commit afbae9f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/gopigo3.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
gopigo3Adaptor := g.NewAdaptor("/dev/spidev0.1", 0, 500000)
gopigo3Adaptor := g.NewAdaptor()
gopigo3 := g.NewGoPiGo3Driver(gopigo3Adaptor)

work := func() {
Expand Down
2 changes: 1 addition & 1 deletion platforms/gopigo3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func main() {
gopigo3Adaptor := g.NewAdaptor("/dev/spidev0.1", 0, 500000)
gopigo3Adaptor := g.NewAdaptor()
gopigo3 := g.NewGoPiGo3Driver(gopigo3Adaptor)

work := func() {
Expand Down
47 changes: 17 additions & 30 deletions platforms/gopigo3/gopigo3_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,24 @@ import (
var _ gobot.Adaptor = (*Adaptor)(nil)

type Adaptor struct {
name string
port string
spiMode xspi.Mode
maxSpeed int64
connection spi.SPIDevice
writeBytesChannel chan []byte
finalizeChannel chan struct{}
name string
port string
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,
connection: nil,
writeBytesChannel: make(chan []byte),
finalizeChannel: make(chan struct{}),
name: "GoPiGo3",
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{}),
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit afbae9f

Please sign in to comment.