Sha256: 8d034a4bff566d37836d7cf6a296cfe0969b0800ffd9a5d5a2a41f5216d90d72

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

require 'pi_piper'
require 'tamashii/agent/common'

module Tamashii
  module Agent
    module Device
      class DeviceBase
        include Common::Loggable

        class OptionNotFoundError < RuntimeError; end

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

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

        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

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

        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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tamashii-agent-0.4.0 lib/tamashii/agent/device/device_base.rb
tamashii-agent-0.3.4 lib/tamashii/agent/device/device_base.rb
tamashii-agent-0.3.3 lib/tamashii/agent/device/device_base.rb