class Artoo::Drivers::Driver
The Driver
class is the base class used to implement behavior for a specific kind of hardware devices. Examples would be an Arduino, a Sphero, or an ARDrone.
Derive a class from this class, in order to implement behavior for a new type of hardware device.
Constants
- COMMANDS
Attributes
additional_params[R]
parent[R]
Public Class Methods
new(params={})
click to toggle source
Create new driver @param [Hash] params @option params [Object] :parent @option params [Object] :additional_params
# File lib/artoo/drivers/driver.rb, line 21 def initialize(params={}) @parent = params[:parent] @additional_params = params[:additional_params] end
Public Instance Methods
command(method_name, *arguments)
click to toggle source
Execute command @param [Symbol] method_name @param [Array] arguments
# File lib/artoo/drivers/driver.rb, line 59 def command(method_name, *arguments) known_command?(method_name) if arguments.first self.send(method_name, *arguments) else self.send(method_name) end rescue Exception => e Logger.error e.message Logger.error e.backtrace.inspect return nil end
commands()
click to toggle source
@return [Collection] commands
# File lib/artoo/drivers/driver.rb, line 52 def commands self.class.const_get('COMMANDS') end
connection()
click to toggle source
@return [Connection] parent connection
# File lib/artoo/drivers/driver.rb, line 27 def connection parent.connection end
event_topic_name(event)
click to toggle source
@return [String] parent topic name
# File lib/artoo/drivers/driver.rb, line 47 def event_topic_name(event) parent.event_topic_name(event) end
interval()
click to toggle source
@return [String] parent interval
# File lib/artoo/drivers/driver.rb, line 37 def interval parent.interval end
known_command?(method_name)
click to toggle source
@return [Boolean] True if command exists
# File lib/artoo/drivers/driver.rb, line 73 def known_command?(method_name) return true if commands.include?(method_name.intern) Logger.warn("Calling unknown command '#{method_name}'...") return false end
method_missing(method_name, *arguments, &block)
click to toggle source
Sends missing methods to connection
# File lib/artoo/drivers/driver.rb, line 85 def method_missing(method_name, *arguments, &block) connection.send(method_name, *arguments, &block) rescue Exception => e Logger.error e.message Logger.error e.backtrace.inspect return nil end
pin()
click to toggle source
@return [String] parent pin
# File lib/artoo/drivers/driver.rb, line 32 def pin parent.pin end
require_interface(i)
click to toggle source
# File lib/artoo/drivers/driver.rb, line 80 def require_interface(i) parent.require_interface(i) end
start_driver()
click to toggle source
Generic driver start
# File lib/artoo/drivers/driver.rb, line 42 def start_driver Logger.info "Starting driver '#{self.class.name}'..." end