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