1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/platforms/neurosky/neurosky_adaptor.go

54 lines
1.2 KiB
Go
Raw Normal View History

// Package neurosky is the Gobot platform for the Neurosky Mindwave EEG
2014-04-27 17:17:05 -07:00
package neurosky
import (
2014-07-22 18:00:54 -07:00
"io"
"go.bug.st/serial"
)
// Adaptor is the Gobot Adaptor for the Neurosky Mindwave
type Adaptor struct {
name string
port string
2014-04-27 17:17:05 -07:00
sp io.ReadWriteCloser
connect func(*Adaptor) (io.ReadWriteCloser, error)
}
// NewAdaptor creates a neurosky adaptor with specified port
func NewAdaptor(port string) *Adaptor {
return &Adaptor{
name: "Neurosky",
port: port,
connect: func(n *Adaptor) (io.ReadWriteCloser, error) {
return serial.Open(n.Port(), &serial.Mode{BaudRate: 57600})
2014-04-27 17:17:05 -07:00
},
}
}
// Name returns the Adaptor Name
func (n *Adaptor) Name() string { return n.name }
// SetName sets the Adaptor Name
func (n *Adaptor) SetName(name string) { n.name = name }
// Port returns the Adaptor port
func (n *Adaptor) Port() string { return n.port }
// Connect returns true if connection to device is successful
func (n *Adaptor) Connect() error {
sp, err := n.connect(n)
if err != nil {
return err
}
n.sp = sp
return nil
}
// Finalize returns true if device finalization is successful
func (n *Adaptor) Finalize() (err error) {
err = n.sp.Close()
return
}