1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-13 19:29:10 +08:00
hybridgroup.gobot/platforms/neurosky/neurosky_adaptor.go

43 lines
780 B
Go
Raw Normal View History

2014-04-27 17:17:05 -07:00
package neurosky
import (
"github.com/hybridgroup/gobot"
"github.com/tarm/goserial"
"io"
)
type NeuroskyAdaptor struct {
gobot.Adaptor
2014-04-27 17:17:05 -07:00
sp io.ReadWriteCloser
connect func(string) io.ReadWriteCloser
}
2014-05-22 20:43:00 -07:00
func NewNeuroskyAdaptor(name string, port string) *NeuroskyAdaptor {
2014-04-27 17:17:05 -07:00
return &NeuroskyAdaptor{
2014-07-07 17:27:10 -07:00
Adaptor: *gobot.NewAdaptor(
name,
"NeuroskyAdaptor",
port,
),
2014-04-27 17:17:05 -07:00
connect: func(port string) io.ReadWriteCloser {
sp, err := serial.OpenPort(&serial.Config{Name: port, Baud: 57600})
if err != nil {
panic(err)
}
return sp
},
}
}
2014-04-27 17:17:05 -07:00
func (n *NeuroskyAdaptor) Connect() bool {
2014-07-07 17:27:10 -07:00
n.sp = n.connect(n.Adaptor.Port())
n.SetConnected(true)
return true
}
2014-04-27 17:17:05 -07:00
func (n *NeuroskyAdaptor) Finalize() bool {
n.sp.Close()
2014-07-07 17:27:10 -07:00
n.SetConnected(false)
return true
}