2014-04-27 17:17:05 -07:00
|
|
|
package neurosky
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
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-04-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
|
2014-04-27 17:17:05 -07:00
|
|
|
func NewNeuroskyAdaptor() *NeuroskyAdaptor {
|
|
|
|
return &NeuroskyAdaptor{
|
|
|
|
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-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 17:17:05 -07:00
|
|
|
func (n *NeuroskyAdaptor) Connect() bool {
|
|
|
|
n.sp = n.connect(n.Adaptor.Port)
|
|
|
|
n.Connected = true
|
2014-04-26 03:11:51 -07:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-04-27 17:17:05 -07:00
|
|
|
func (n *NeuroskyAdaptor) Finalize() bool {
|
|
|
|
n.sp.Close()
|
|
|
|
n.Connected = false
|
2014-04-26 03:11:51 -07:00
|
|
|
return true
|
|
|
|
}
|