Update neurosky package
This commit is contained in:
parent
a770ef1020
commit
0bac02539d
|
@ -14,10 +14,11 @@ type NeuroskyAdaptor struct {
|
||||||
|
|
||||||
func NewNeuroskyAdaptor(name string, port string) *NeuroskyAdaptor {
|
func NewNeuroskyAdaptor(name string, port string) *NeuroskyAdaptor {
|
||||||
return &NeuroskyAdaptor{
|
return &NeuroskyAdaptor{
|
||||||
Adaptor: gobot.Adaptor{
|
Adaptor: *gobot.NewAdaptor(
|
||||||
Name: name,
|
name,
|
||||||
Port: port,
|
"NeuroskyAdaptor",
|
||||||
},
|
port,
|
||||||
|
),
|
||||||
connect: func(port string) io.ReadWriteCloser {
|
connect: func(port string) io.ReadWriteCloser {
|
||||||
sp, err := serial.OpenPort(&serial.Config{Name: port, Baud: 57600})
|
sp, err := serial.OpenPort(&serial.Config{Name: port, Baud: 57600})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,13 +30,13 @@ func NewNeuroskyAdaptor(name string, port string) *NeuroskyAdaptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NeuroskyAdaptor) Connect() bool {
|
func (n *NeuroskyAdaptor) Connect() bool {
|
||||||
n.sp = n.connect(n.Adaptor.Port)
|
n.sp = n.connect(n.Adaptor.Port())
|
||||||
n.Connected = true
|
n.SetConnected(true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NeuroskyAdaptor) Finalize() bool {
|
func (n *NeuroskyAdaptor) Finalize() bool {
|
||||||
n.sp.Close()
|
n.sp.Close()
|
||||||
n.Connected = false
|
n.SetConnected(false)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,25 +30,27 @@ type EEG struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNeuroskyDriver(a *NeuroskyAdaptor, name string) *NeuroskyDriver {
|
func NewNeuroskyDriver(a *NeuroskyAdaptor, name string) *NeuroskyDriver {
|
||||||
return &NeuroskyDriver{
|
n := &NeuroskyDriver{
|
||||||
Driver: gobot.Driver{
|
Driver: *gobot.NewDriver(
|
||||||
Name: name,
|
name,
|
||||||
Events: map[string]*gobot.Event{
|
"NeuroskyDriver",
|
||||||
"Extended": gobot.NewEvent(),
|
a,
|
||||||
"Signal": gobot.NewEvent(),
|
),
|
||||||
"Attention": gobot.NewEvent(),
|
|
||||||
"Meditation": gobot.NewEvent(),
|
|
||||||
"Blink": gobot.NewEvent(),
|
|
||||||
"Wave": gobot.NewEvent(),
|
|
||||||
"EEG": gobot.NewEvent(),
|
|
||||||
},
|
|
||||||
Adaptor: a,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n.AddEvent("Extended")
|
||||||
|
n.AddEvent("Signal")
|
||||||
|
n.AddEvent("Attention")
|
||||||
|
n.AddEvent("Meditation")
|
||||||
|
n.AddEvent("Blink")
|
||||||
|
n.AddEvent("Wave")
|
||||||
|
n.AddEvent("EEG")
|
||||||
|
|
||||||
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NeuroskyDriver) adaptor() *NeuroskyAdaptor {
|
func (n *NeuroskyDriver) adaptor() *NeuroskyAdaptor {
|
||||||
return n.Driver.Adaptor.(*NeuroskyAdaptor)
|
return n.Driver.Adaptor().(*NeuroskyAdaptor)
|
||||||
}
|
}
|
||||||
func (n *NeuroskyDriver) Start() bool {
|
func (n *NeuroskyDriver) Start() bool {
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -87,29 +89,29 @@ func (n *NeuroskyDriver) parsePacket(data []byte) {
|
||||||
b, _ := buf.ReadByte()
|
b, _ := buf.ReadByte()
|
||||||
switch b {
|
switch b {
|
||||||
case CodeEx:
|
case CodeEx:
|
||||||
gobot.Publish(n.Events["Extended"], nil)
|
gobot.Publish(n.Event("Extended"), nil)
|
||||||
case CodeSignalQuality:
|
case CodeSignalQuality:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Events["Signal"], ret)
|
gobot.Publish(n.Event("Signal"), ret)
|
||||||
case CodeAttention:
|
case CodeAttention:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Events["Attention"], ret)
|
gobot.Publish(n.Event("Attention"), ret)
|
||||||
case CodeMeditation:
|
case CodeMeditation:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Events["Meditation"], ret)
|
gobot.Publish(n.Event("Meditation"), ret)
|
||||||
case CodeBlink:
|
case CodeBlink:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Events["Blink"], ret)
|
gobot.Publish(n.Event("Blink"), ret)
|
||||||
case CodeWave:
|
case CodeWave:
|
||||||
buf.Next(1)
|
buf.Next(1)
|
||||||
var ret = make([]byte, 2)
|
var ret = make([]byte, 2)
|
||||||
buf.Read(ret)
|
buf.Read(ret)
|
||||||
gobot.Publish(n.Events["Wave"], ret)
|
gobot.Publish(n.Event("Wave"), ret)
|
||||||
case CodeAsicEEG:
|
case CodeAsicEEG:
|
||||||
var ret = make([]byte, 25)
|
var ret = make([]byte, 25)
|
||||||
i, _ := buf.Read(ret)
|
i, _ := buf.Read(ret)
|
||||||
if i == 25 {
|
if i == 25 {
|
||||||
gobot.Publish(n.Events["EEG"], n.parseEEG(ret))
|
gobot.Publish(n.Event("EEG"), n.parseEEG(ret))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue