mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-24 13:48:49 +08:00
docs: Add missing godocs for Neurosky platform
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
e8b28a0df1
commit
8d924d9546
@ -1,3 +1,4 @@
|
||||
// Package neurosky is the Gobot platform for the Neurosky Mindwave EEG
|
||||
package neurosky
|
||||
|
||||
import (
|
||||
@ -6,6 +7,7 @@ import (
|
||||
"github.com/tarm/serial"
|
||||
)
|
||||
|
||||
// Adaptor is the Gobot Adaptor for the Neurosky Mindwave
|
||||
type Adaptor struct {
|
||||
name 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) 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
|
||||
func (n *Adaptor) Connect() error {
|
||||
if sp, err := n.connect(n); err != nil {
|
||||
sp, err := n.connect(n)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
n.sp = sp
|
||||
}
|
||||
|
||||
n.sp = sp
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -6,36 +6,65 @@ import (
|
||||
"github.com/hybridgroup/gobot"
|
||||
)
|
||||
|
||||
const BTSync byte = 0xAA
|
||||
const (
|
||||
// BTSync is the sync code
|
||||
BTSync byte = 0xAA
|
||||
|
||||
// CodeEx Extended code
|
||||
const CodeEx byte = 0x55
|
||||
// CodeEx Extended code
|
||||
CodeEx byte = 0x55
|
||||
|
||||
// CodeSignalQuality POOR_SIGNAL quality 0-255
|
||||
const CodeSignalQuality byte = 0x02
|
||||
// CodeSignalQuality POOR_SIGNAL quality 0-255
|
||||
CodeSignalQuality byte = 0x02
|
||||
|
||||
// CodeAttention ATTENTION eSense 0-100
|
||||
const CodeAttention byte = 0x04
|
||||
// CodeAttention ATTENTION eSense 0-100
|
||||
CodeAttention byte = 0x04
|
||||
|
||||
// CodeMeditation MEDITATION eSense 0-100
|
||||
const CodeMeditation byte = 0x05
|
||||
// CodeMeditation MEDITATION eSense 0-100
|
||||
CodeMeditation byte = 0x05
|
||||
|
||||
// CodeBlink BLINK strength 0-255
|
||||
const CodeBlink byte = 0x16
|
||||
// CodeBlink BLINK strength 0-255
|
||||
CodeBlink byte = 0x16
|
||||
|
||||
// CodeWave RAW wave value: 2-byte big-endian 2s-complement
|
||||
const CodeWave byte = 0x80
|
||||
// CodeWave RAW wave value: 2-byte big-endian 2s-complement
|
||||
CodeWave byte = 0x80
|
||||
|
||||
// CodeAsicEEG ASIC EEG POWER 8 3-byte big-endian integers
|
||||
const CodeAsicEEG byte = 0x83
|
||||
// CodeAsicEEG ASIC EEG POWER 8 3-byte big-endian integers
|
||||
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 {
|
||||
name string
|
||||
connection gobot.Connection
|
||||
gobot.Eventer
|
||||
}
|
||||
|
||||
type EEG struct {
|
||||
// EEGData is the EEG raw data returned from the Mindwave
|
||||
type EEGData struct {
|
||||
Delta int
|
||||
Theta int
|
||||
LoAlpha int
|
||||
@ -63,20 +92,26 @@ func NewDriver(a *Adaptor) *Driver {
|
||||
Eventer: gobot.NewEventer(),
|
||||
}
|
||||
|
||||
n.AddEvent("extended")
|
||||
n.AddEvent("signal")
|
||||
n.AddEvent("attention")
|
||||
n.AddEvent("meditation")
|
||||
n.AddEvent("blink")
|
||||
n.AddEvent("wave")
|
||||
n.AddEvent("eeg")
|
||||
n.AddEvent("error")
|
||||
n.AddEvent(Extended)
|
||||
n.AddEvent(Signal)
|
||||
n.AddEvent(Attention)
|
||||
n.AddEvent(Meditation)
|
||||
n.AddEvent(Blink)
|
||||
n.AddEvent(Wave)
|
||||
n.AddEvent(EEG)
|
||||
n.AddEvent(Error)
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// Connection returns the Driver's 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
|
||||
func (n *Driver) adaptor() *Adaptor {
|
||||
@ -154,8 +189,8 @@ func (n *Driver) parsePacket(buf *bytes.Buffer) {
|
||||
}
|
||||
|
||||
// parseEEG returns data converted into EEG map
|
||||
func (n *Driver) parseEEG(data []byte) EEG {
|
||||
return EEG{
|
||||
func (n *Driver) parseEEG(data []byte) EEGData {
|
||||
return EEGData{
|
||||
Delta: n.parse3ByteInteger(data[0:3]),
|
||||
Theta: n.parse3ByteInteger(data[3:6]),
|
||||
LoAlpha: n.parse3ByteInteger(data[6:9]),
|
||||
|
@ -29,7 +29,7 @@ func TestNeuroskyDriver(t *testing.T) {
|
||||
func TestNeuroskyDriverStart(t *testing.T) {
|
||||
sem := make(chan bool, 0)
|
||||
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"))
|
||||
sem <- true
|
||||
})
|
||||
@ -64,7 +64,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
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
|
||||
})
|
||||
|
||||
@ -80,7 +80,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
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))
|
||||
sem <- true
|
||||
})
|
||||
@ -93,7 +93,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
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))
|
||||
sem <- true
|
||||
})
|
||||
@ -106,7 +106,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
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))
|
||||
sem <- true
|
||||
})
|
||||
@ -119,7 +119,7 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
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))
|
||||
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.On(d.Event("wave"), func(data interface{}) {
|
||||
d.On(d.Event(Wave), func(data interface{}) {
|
||||
gobottest.Assert(t, data.(int16), int16(16401))
|
||||
sem <- true
|
||||
})
|
||||
@ -147,10 +147,10 @@ func TestNeuroskyDriverParse(t *testing.T) {
|
||||
108, 0x00}))
|
||||
}()
|
||||
|
||||
d.On(d.Event("eeg"), func(data interface{}) {
|
||||
d.On(d.Event(EEG), func(data interface{}) {
|
||||
gobottest.Assert(t,
|
||||
data.(EEG),
|
||||
EEG{
|
||||
data.(EEGData),
|
||||
EEGData{
|
||||
Delta: 1573241,
|
||||
Theta: 5832801,
|
||||
LoAlpha: 1703966,
|
||||
|
Loading…
x
Reference in New Issue
Block a user