Fix neurosky runtime error
This commit is contained in:
parent
8e68601cfe
commit
b71e8864ff
|
@ -103,7 +103,12 @@ func (d *Driver) Events() map[string]*Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Event(name string) *Event {
|
func (d *Driver) Event(name string) *Event {
|
||||||
return d.events[name]
|
e, ok := d.events[name]
|
||||||
|
if ok {
|
||||||
|
return e
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("Unknown Driver Event: %v", name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) AddEvent(name string) {
|
func (d *Driver) AddEvent(name string) {
|
||||||
|
|
|
@ -90,29 +90,29 @@ func (n *NeuroskyDriver) parsePacket(data []byte) {
|
||||||
b, _ := buf.ReadByte()
|
b, _ := buf.ReadByte()
|
||||||
switch b {
|
switch b {
|
||||||
case CodeEx:
|
case CodeEx:
|
||||||
gobot.Publish(n.Event("Extended"), nil)
|
gobot.Publish(n.Event("extended"), nil)
|
||||||
case CodeSignalQuality:
|
case CodeSignalQuality:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Event("Signal"), ret)
|
gobot.Publish(n.Event("signal"), ret)
|
||||||
case CodeAttention:
|
case CodeAttention:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Event("Attention"), ret)
|
gobot.Publish(n.Event("attention"), ret)
|
||||||
case CodeMeditation:
|
case CodeMeditation:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Event("Meditation"), ret)
|
gobot.Publish(n.Event("meditation"), ret)
|
||||||
case CodeBlink:
|
case CodeBlink:
|
||||||
ret, _ := buf.ReadByte()
|
ret, _ := buf.ReadByte()
|
||||||
gobot.Publish(n.Event("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.Event("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.Event("EEG"), n.parseEEG(ret))
|
gobot.Publish(n.Event("eeg"), n.parseEEG(ret))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue