Class: Tamashii::Agent::Device::DeviceBase

Inherits:
Object
  • Object
show all
Includes:
Common::Loggable
Defined in:
lib/tamashii/agent/device/device_base.rb

Defined Under Namespace

Classes: OptionNotFoundError

Instance Method Summary collapse

Methods included from Common::Loggable

#display_name, #logger, #progname

Constructor Details

#initialize(component, options = {}) ⇒ DeviceBase

Returns a new instance of DeviceBase.



12
13
14
15
# File 'lib/tamashii/agent/device/device_base.rb', line 12

def initialize(component, options = {})
  @component = component
  @options = options
end

Instance Method Details

#fetch_option(name, default_value) ⇒ Object



21
22
23
24
25
26
# File 'lib/tamashii/agent/device/device_base.rb', line 21

def fetch_option(name, default_value)
  fetch_option!(name)
rescue OptionNotFoundError => e
  logger.warn "No #{name} specified in options. Use default #{name}: #{default_value}"
  return default_value
end

#fetch_option!(name) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/tamashii/agent/device/device_base.rb', line 28

def fetch_option!(name)
  if @options.has_key?(name)
    return @options[name]
  else
    raise OptionNotFoundError, "#{name} not found in option"
  end
end

#shutdownObject



17
18
19
# File 'lib/tamashii/agent/device/device_base.rb', line 17

def shutdown
  logger.warn "Device '#{self.class}' does not implement a shutdown method"
end

#unexport_pin(pin_number) ⇒ Object

Raises:

  • (ArgumentErrorm)


36
37
38
39
40
41
42
43
# File 'lib/tamashii/agent/device/device_base.rb', line 36

def unexport_pin(pin_number)
  raise ArgumentErrorm, "pin number must be a integer" unless pin_number.is_a? Integer
  if PiPiper::Platform.driver == PiPiper::Bcm2835
    PiPiper::Platform.driver.unexport_pin(pin_number)
  else
    logger.warn "Underlying driver #{PiPiper::Platform.driver} does not support unexporting"
  end
end