Class: Artoo::Drivers::Driver

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Notifications
Defined in:
lib/artoo/drivers/driver.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Celluloid

#timers

Constructor Details

#initialize(params = {}) ⇒ Driver

Returns a new instance of Driver.



15
16
17
# File 'lib/artoo/drivers/driver.rb', line 15

def initialize(params={})
  @parent = params[:parent]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



39
40
41
42
43
44
45
# File 'lib/artoo/drivers/driver.rb', line 39

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



13
14
15
# File 'lib/artoo/drivers/driver.rb', line 13

def parent
  @parent
end

Instance Method Details

#connectionObject



19
20
21
# File 'lib/artoo/drivers/driver.rb', line 19

def connection
  parent.connection
end

#event_topic_name(event) ⇒ Object



35
36
37
# File 'lib/artoo/drivers/driver.rb', line 35

def event_topic_name(event)
  parent.event_topic_name(event)
end

#intervalObject



27
28
29
# File 'lib/artoo/drivers/driver.rb', line 27

def interval
  parent.interval
end

#pinObject



23
24
25
# File 'lib/artoo/drivers/driver.rb', line 23

def pin
  parent.pin
end

#start_driverObject



31
32
33
# File 'lib/artoo/drivers/driver.rb', line 31

def start_driver
  Logger.info "Starting driver '#{self.class.name}'..."
end