Class: Artoo::Adaptors::Neurosky

Inherits:
Adaptor
  • Object
show all
Defined in:
lib/artoo/adaptors/neurosky.rb

Overview

Connect to a neurosky device

See Also:

  • documentation for more information

Constant Summary collapse

RETRY_COUNT =

Number of retries when connecting

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

Uses method missing to call device actions

See Also:

  • documentation


54
55
56
# File 'lib/artoo/adaptors/neurosky.rb', line 54

def method_missing(method_name, *arguments, &block)
  neurosky.send(method_name, *arguments, &block)
end

Instance Attribute Details

#neuroskyObject (readonly)

Returns the value of attribute neurosky.



8
9
10
# File 'lib/artoo/adaptors/neurosky.rb', line 8

def neurosky
  @neurosky
end

Instance Method Details

#connectBoolean

Creates a connection with device

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/artoo/adaptors/neurosky.rb', line 15

def connect
  @retries_left = RETRY_COUNT
  require 'mindset' unless defined?(::Mindset)
  begin
    @neurosky = ::Mindset.connect(connect_to)
    super
    return true
  rescue Errno::EBUSY, Errno::ECONNREFUSED => e
    @retries_left -= 1
    if @retries_left > 0
      retry
    else
      Logger.error e.message
      Logger.error e.backtrace.inspect
      return false
    end
  end
end

#disconnectBoolean

Closes connection with device

Returns:

  • (Boolean)


36
37
38
# File 'lib/artoo/adaptors/neurosky.rb', line 36

def disconnect
  neurosky.disconnect if connected?
end

#nameString

Name of device

Returns:

  • (String)


42
43
44
# File 'lib/artoo/adaptors/neurosky.rb', line 42

def name
  "neurosky"
end

#versionString

Version of device

Returns:

  • (String)


48
49
50
# File 'lib/artoo/adaptors/neurosky.rb', line 48

def version
  Artoo::Neurosky::VERSION
end