1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-14 19:29:32 +08:00

docs: Add missing godocs for Neurosky platform

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-12-01 12:02:47 +01:00
parent 1513af3fa6
commit c8eeb08f37
3 changed files with 86 additions and 43 deletions

View File

@ -1,3 +1,4 @@
// Package neurosky is the Gobot platform for the Neurosky Mindwave EEG
package neurosky package neurosky
import ( import (
@ -6,6 +7,7 @@ import (
"github.com/tarm/serial" "github.com/tarm/serial"
) )
// Adaptor is the Gobot Adaptor for the Neurosky Mindwave
type Adaptor struct { type Adaptor struct {
name string name string
port string port string
@ -24,17 +26,23 @@ func NewAdaptor(port string) *Adaptor {
} }
} }
func (n *Adaptor) Name() string { return n.name } // 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 } func (n *Adaptor) SetName(name string) { n.name = name }
func (n *Adaptor) Port() string { return n.port }
// Port returns the Adaptor port
func (n *Adaptor) Port() string { return n.port }
// Connect returns true if connection to device is successful // Connect returns true if connection to device is successful
func (n *Adaptor) Connect() error { func (n *Adaptor) Connect() error {
if sp, err := n.connect(n); err != nil { sp, err := n.connect(n)
if err != nil {
return err return err
} else {
n.sp = sp
} }
n.sp = sp
return nil return nil
} }

View File

@ -6,36 +6,65 @@ import (
"github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot"
) )
const BTSync byte = 0xAA const (
// BTSync is the sync code
BTSync byte = 0xAA
// CodeEx Extended code // CodeEx Extended code
const CodeEx byte = 0x55 CodeEx byte = 0x55
// CodeSignalQuality POOR_SIGNAL quality 0-255 // CodeSignalQuality POOR_SIGNAL quality 0-255
const CodeSignalQuality byte = 0x02 CodeSignalQuality byte = 0x02
// CodeAttention ATTENTION eSense 0-100 // CodeAttention ATTENTION eSense 0-100
const CodeAttention byte = 0x04 CodeAttention byte = 0x04
// CodeMeditation MEDITATION eSense 0-100 // CodeMeditation MEDITATION eSense 0-100
const CodeMeditation byte = 0x05 CodeMeditation byte = 0x05
// CodeBlink BLINK strength 0-255 // CodeBlink BLINK strength 0-255
const CodeBlink byte = 0x16 CodeBlink byte = 0x16
// CodeWave RAW wave value: 2-byte big-endian 2s-complement // CodeWave RAW wave value: 2-byte big-endian 2s-complement
const CodeWave byte = 0x80 CodeWave byte = 0x80
// CodeAsicEEG ASIC EEG POWER 8 3-byte big-endian integers // CodeAsicEEG ASIC EEG POWER 8 3-byte big-endian integers
const CodeAsicEEG byte = 0x83 CodeAsicEEG byte = 0x83
// Extended event
Extended = "extended"
// Signal event
Signal = "signal"
// Attention event
Attention = "attention"
// Meditation event
Meditation = "meditation"
// Blink event
Blink = "blink"
// Wave event
Wave = "wave"
// EEG event
EEG = "eeg"
// Error event
Error = "error"
)
// Driver is the Gobot Driver for the Mindwave
type Driver struct { type Driver struct {
name string name string
connection gobot.Connection connection gobot.Connection
gobot.Eventer gobot.Eventer
} }
type EEG struct { // EEGData is the EEG raw data returned from the Mindwave
type EEGData struct {
Delta int Delta int
Theta int Theta int
LoAlpha int LoAlpha int
@ -63,20 +92,26 @@ func NewDriver(a *Adaptor) *Driver {
Eventer: gobot.NewEventer(), Eventer: gobot.NewEventer(),
} }
n.AddEvent("extended") n.AddEvent(Extended)
n.AddEvent("signal") n.AddEvent(Signal)
n.AddEvent("attention") n.AddEvent(Attention)
n.AddEvent("meditation") n.AddEvent(Meditation)
n.AddEvent("blink") n.AddEvent(Blink)
n.AddEvent("wave") n.AddEvent(Wave)
n.AddEvent("eeg") n.AddEvent(EEG)
n.AddEvent("error") n.AddEvent(Error)
return n return n
} }
// Connection returns the Driver's connection
func (n *Driver) Connection() gobot.Connection { return n.connection } func (n *Driver) Connection() gobot.Connection { return n.connection }
func (n *Driver) Name() string { return n.name }
func (n *Driver) SetName(name string) { n.name = name } // Name returns the Driver name
func (n *Driver) Name() string { return n.name }
// SetName sets the Driver name
func (n *Driver) SetName(name string) { n.name = name }
// adaptor returns neurosky adaptor // adaptor returns neurosky adaptor
func (n *Driver) adaptor() *Adaptor { func (n *Driver) adaptor() *Adaptor {
@ -154,8 +189,8 @@ func (n *Driver) parsePacket(buf *bytes.Buffer) {
} }
// parseEEG returns data converted into EEG map // parseEEG returns data converted into EEG map
func (n *Driver) parseEEG(data []byte) EEG { func (n *Driver) parseEEG(data []byte) EEGData {
return EEG{ return EEGData{
Delta: n.parse3ByteInteger(data[0:3]), Delta: n.parse3ByteInteger(data[0:3]),
Theta: n.parse3ByteInteger(data[3:6]), Theta: n.parse3ByteInteger(data[3:6]),
LoAlpha: n.parse3ByteInteger(data[6:9]), LoAlpha: n.parse3ByteInteger(data[6:9]),

View File

@ -29,7 +29,7 @@ func TestNeuroskyDriver(t *testing.T) {
func TestNeuroskyDriverStart(t *testing.T) { func TestNeuroskyDriverStart(t *testing.T) {
sem := make(chan bool, 0) sem := make(chan bool, 0)
d := initTestNeuroskyDriver() d := initTestNeuroskyDriver()
d.Once(d.Event("error"), func(data interface{}) { d.Once(d.Event(Error), func(data interface{}) {
gobottest.Assert(t, data.(error), errors.New("read error")) gobottest.Assert(t, data.(error), errors.New("read error"))
sem <- true sem <- true
}) })
@ -64,7 +64,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 1, 0x55, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 1, 0x55, 0x00}))
}() }()
d.On(d.Event("extended"), func(data interface{}) { d.On(d.Event(Extended), func(data interface{}) {
sem <- true sem <- true
}) })
@ -80,7 +80,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x02, 100, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x02, 100, 0x00}))
}() }()
d.On(d.Event("signal"), func(data interface{}) { d.On(d.Event(Signal), func(data interface{}) {
gobottest.Assert(t, data.(byte), byte(100)) gobottest.Assert(t, data.(byte), byte(100))
sem <- true sem <- true
}) })
@ -93,7 +93,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x04, 40, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x04, 40, 0x00}))
}() }()
d.On(d.Event("attention"), func(data interface{}) { d.On(d.Event(Attention), func(data interface{}) {
gobottest.Assert(t, data.(byte), byte(40)) gobottest.Assert(t, data.(byte), byte(40))
sem <- true sem <- true
}) })
@ -106,7 +106,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x05, 60, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x05, 60, 0x00}))
}() }()
d.On(d.Event("meditation"), func(data interface{}) { d.On(d.Event(Meditation), func(data interface{}) {
gobottest.Assert(t, data.(byte), byte(60)) gobottest.Assert(t, data.(byte), byte(60))
sem <- true sem <- true
}) })
@ -119,7 +119,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x16, 150, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 2, 0x16, 150, 0x00}))
}() }()
d.On(d.Event("blink"), func(data interface{}) { d.On(d.Event(Blink), func(data interface{}) {
gobottest.Assert(t, data.(byte), byte(150)) gobottest.Assert(t, data.(byte), byte(150))
sem <- true sem <- true
}) })
@ -132,7 +132,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 4, 0x80, 0x00, 0x40, 0x11, 0x00})) d.parse(bytes.NewBuffer([]byte{0xAA, 0xAA, 4, 0x80, 0x00, 0x40, 0x11, 0x00}))
}() }()
d.On(d.Event("wave"), func(data interface{}) { d.On(d.Event(Wave), func(data interface{}) {
gobottest.Assert(t, data.(int16), int16(16401)) gobottest.Assert(t, data.(int16), int16(16401))
sem <- true sem <- true
}) })
@ -147,10 +147,10 @@ func TestNeuroskyDriverParse(t *testing.T) {
108, 0x00})) 108, 0x00}))
}() }()
d.On(d.Event("eeg"), func(data interface{}) { d.On(d.Event(EEG), func(data interface{}) {
gobottest.Assert(t, gobottest.Assert(t,
data.(EEG), data.(EEGData),
EEG{ EEGData{
Delta: 1573241, Delta: 1573241,
Theta: 5832801, Theta: 5832801,
LoAlpha: 1703966, LoAlpha: 1703966,