Class: Artoo::Adaptors::Sphero
- Defined in:
- lib/artoo/adaptors/sphero.rb
Overview
Connect to a Sphero device
Constant Summary collapse
- RETRY_COUNT =
Number of retries when connecting
5
Instance Attribute Summary collapse
-
#sphero ⇒ Object
readonly
Returns the value of attribute sphero.
Attributes inherited from Adaptor
Instance Method Summary collapse
-
#connect ⇒ Boolean
Creates a connection with Sphero object with retries.
-
#disconnect ⇒ Boolean
Closes connection with device.
-
#finalize ⇒ Boolean
Closes connection with device if connected.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Uses method missing to call sphero actions.
Methods inherited from Adaptor
#connect_to, #connect_to_serial, #connect_to_tcp, #connect_to_udp, #connected?, #initialize, #reconnect
Constructor Details
This class inherits a constructor from Artoo::Adaptors::Adaptor
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 sphero actions
53 54 55 |
# File 'lib/artoo/adaptors/sphero.rb', line 53 def method_missing(method_name, *arguments, &block) sphero.send(method_name, *arguments, &block) end |
Instance Attribute Details
#sphero ⇒ Object (readonly)
Returns the value of attribute sphero.
10 11 12 |
# File 'lib/artoo/adaptors/sphero.rb', line 10 def sphero @sphero end |
Instance Method Details
#connect ⇒ Boolean
Creates a connection with Sphero object with retries
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/artoo/adaptors/sphero.rb', line 25 def connect @retries_left = RETRY_COUNT require 'sphero' unless defined?(::Sphero) begin @sphero = ::Sphero.new(connect_to) super return true rescue Errno::EBUSY => e @retries_left -= 1 if @retries_left > 0 retry else Logger.error e. Logger.error e.backtrace.inspect return false end end end |
#disconnect ⇒ Boolean
Closes connection with device
46 47 48 49 |
# File 'lib/artoo/adaptors/sphero.rb', line 46 def disconnect sphero.close super end |
#finalize ⇒ Boolean
Closes connection with device if connected
17 18 19 20 21 |
# File 'lib/artoo/adaptors/sphero.rb', line 17 def finalize if connected? sphero.close end end |