core: update Neurosky platform to simply return error

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-11-07 20:00:26 +01:00
parent c327fe1650
commit 1ec2497c64
4 changed files with 19 additions and 21 deletions

View File

@ -29,19 +29,17 @@ func (n *Adaptor) SetName(name string) { n.name = name }
func (n *Adaptor) Port() string { return n.port }
// Connect returns true if connection to device is successful
func (n *Adaptor) Connect() (errs []error) {
func (n *Adaptor) Connect() error {
if sp, err := n.connect(n); err != nil {
return []error{err}
return err
} else {
n.sp = sp
}
return
return nil
}
// Finalize returns true if device finalization is successful
func (n *Adaptor) Finalize() (errs []error) {
if err := n.sp.Close(); err != nil {
return []error{err}
}
func (n *Adaptor) Finalize() (err error) {
err = n.sp.Close()
return
}

View File

@ -23,7 +23,7 @@ func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), readError
}
var closeError error = nil
var closeError error
func (NullReadWriteCloser) Close() error {
return closeError
@ -44,20 +44,20 @@ func TestNeuroskyAdaptor(t *testing.T) {
func TestNeuroskyAdaptorConnect(t *testing.T) {
a := initTestNeuroskyAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
gobottest.Assert(t, a.Connect(), nil)
a.connect = func(n *Adaptor) (io.ReadWriteCloser, error) {
return nil, errors.New("connection error")
}
gobottest.Assert(t, a.Connect()[0], errors.New("connection error"))
gobottest.Assert(t, a.Connect(), errors.New("connection error"))
}
func TestNeuroskyAdaptorFinalize(t *testing.T) {
a := initTestNeuroskyAdaptor()
a.Connect()
gobottest.Assert(t, len(a.Finalize()), 0)
gobottest.Assert(t, a.Finalize(), nil)
closeError = errors.New("close error")
a.Connect()
gobottest.Assert(t, a.Finalize()[0], errors.New("close error"))
gobottest.Assert(t, a.Finalize(), errors.New("close error"))
}

View File

@ -8,25 +8,25 @@ import (
const BTSync byte = 0xAA
// Extended code
// CodeEx Extended code
const CodeEx byte = 0x55
// POOR_SIGNAL quality 0-255
// CodeSignalQuality POOR_SIGNAL quality 0-255
const CodeSignalQuality byte = 0x02
// ATTENTION eSense 0-100
// CodeAttention ATTENTION eSense 0-100
const CodeAttention byte = 0x04
// MEDITATION eSense 0-100
// CodeMeditation MEDITATION eSense 0-100
const CodeMeditation byte = 0x05
// BLINK strength 0-255
// CodeBlink BLINK strength 0-255
const CodeBlink byte = 0x16
// RAW wave value: 2-byte big-endian 2s-complement
// CodeWave RAW wave value: 2-byte big-endian 2s-complement
const CodeWave byte = 0x80
// ASIC EEG POWER 8 3-byte big-endian integers
// CodeAsicEEG ASIC EEG POWER 8 3-byte big-endian integers
const CodeAsicEEG byte = 0x83
type Driver struct {

View File

@ -34,7 +34,7 @@ func TestNeuroskyDriverStart(t *testing.T) {
sem <- true
})
gobottest.Assert(t, len(d.Start()), 0)
gobottest.Assert(t, d.Start(), nil)
time.Sleep(50 * time.Millisecond)
readError = errors.New("read error")
@ -51,7 +51,7 @@ func TestNeuroskyDriverStart(t *testing.T) {
func TestNeuroskyDriverHalt(t *testing.T) {
d := initTestNeuroskyDriver()
gobottest.Assert(t, len(d.Halt()), 0)
gobottest.Assert(t, d.Halt(), nil)
}
func TestNeuroskyDriverParse(t *testing.T) {