Class: Artoo::Drivers::AnalogSensor

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/analog_sensor.rb

Overview

AnalogSensors driver behaviors

Constant Summary collapse

COMMANDS =
[:analog_read, :lower, :upper, :previous_read].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lowerObject (readonly)

Returns the value of attribute lower.



9
10
11
# File 'lib/artoo/drivers/analog_sensor.rb', line 9

def lower
  @lower
end

#previous_readObject (readonly)

Returns the value of attribute previous_read.



9
10
11
# File 'lib/artoo/drivers/analog_sensor.rb', line 9

def previous_read
  @previous_read
end

#upperObject (readonly)

Returns the value of attribute upper.



9
10
11
# File 'lib/artoo/drivers/analog_sensor.rb', line 9

def upper
  @upper
end

Instance Method Details

#analog_read(pin) ⇒ Object



11
12
13
# File 'lib/artoo/drivers/analog_sensor.rb', line 11

def analog_read(pin)
  connection.analog_read(pin)
end

#start_driverObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/artoo/drivers/analog_sensor.rb', line 15

def start_driver
  @previous_read = 0
  @upper = additional_params[:upper].nil? ? 1023 : additional_params[:upper]
  @lower = additional_params[:lower].nil? ? 0 : additional_params[:lower]

  every(interval) do
    new_value = connection.analog_read(pin)
    update(new_value) unless new_value.nil?
  end if !interval.nil? and interval > 0

  super
end