2016-12-01 19:02:47 +08:00
|
|
|
// Package neurosky is the Gobot platform for the Neurosky Mindwave EEG
|
2014-04-28 08:17:05 +08:00
|
|
|
package neurosky
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
import (
|
2014-07-23 09:00:54 +08:00
|
|
|
"io"
|
|
|
|
|
2016-10-03 14:38:24 +08:00
|
|
|
"github.com/tarm/serial"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
2016-12-01 19:02:47 +08:00
|
|
|
// Adaptor is the Gobot Adaptor for the Neurosky Mindwave
|
2016-10-01 23:44:12 +08:00
|
|
|
type Adaptor struct {
|
2014-11-29 10:01:31 +08:00
|
|
|
name string
|
|
|
|
port string
|
2014-04-28 08:17:05 +08:00
|
|
|
sp io.ReadWriteCloser
|
2016-10-01 23:44:12 +08:00
|
|
|
connect func(*Adaptor) (io.ReadWriteCloser, error)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 23:44:12 +08:00
|
|
|
// NewAdaptor creates a neurosky adaptor with specified port
|
|
|
|
func NewAdaptor(port string) *Adaptor {
|
|
|
|
return &Adaptor{
|
2016-10-04 01:06:37 +08:00
|
|
|
name: "Neurosky",
|
2014-11-29 10:01:31 +08:00
|
|
|
port: port,
|
2016-10-01 23:44:12 +08:00
|
|
|
connect: func(n *Adaptor) (io.ReadWriteCloser, error) {
|
2014-12-19 06:42:59 +08:00
|
|
|
return serial.OpenPort(&serial.Config{Name: n.Port(), Baud: 57600})
|
2014-04-28 08:17:05 +08:00
|
|
|
},
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-01 23:44:12 +08:00
|
|
|
|
2016-12-01 19:02:47 +08:00
|
|
|
// Name returns the Adaptor Name
|
|
|
|
func (n *Adaptor) Name() string { return n.name }
|
|
|
|
|
|
|
|
// SetName sets the Adaptor Name
|
2016-10-01 23:44:12 +08:00
|
|
|
func (n *Adaptor) SetName(name string) { n.name = name }
|
2016-12-01 19:02:47 +08:00
|
|
|
|
|
|
|
// Port returns the Adaptor port
|
|
|
|
func (n *Adaptor) Port() string { return n.port }
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-10-21 00:00:00 +08:00
|
|
|
// Connect returns true if connection to device is successful
|
2016-11-08 03:00:26 +08:00
|
|
|
func (n *Adaptor) Connect() error {
|
2016-12-01 19:02:47 +08:00
|
|
|
sp, err := n.connect(n)
|
|
|
|
if err != nil {
|
2016-11-08 03:00:26 +08:00
|
|
|
return err
|
2014-11-20 15:21:19 +08:00
|
|
|
}
|
2016-12-01 19:02:47 +08:00
|
|
|
|
|
|
|
n.sp = sp
|
2016-11-08 03:00:26 +08:00
|
|
|
return nil
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-10-21 00:00:00 +08:00
|
|
|
// Finalize returns true if device finalization is successful
|
2016-11-08 03:00:26 +08:00
|
|
|
func (n *Adaptor) Finalize() (err error) {
|
|
|
|
err = n.sp.Close()
|
2014-11-20 15:21:19 +08:00
|
|
|
return
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|