Class: Denko::Sensor::HCSR04

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Lifecycle, Behaviors::MultiPin, Behaviors::Poller
Defined in:
lib/denko/sensor/hcsr04.rb

Constant Summary collapse

SPEED_OF_SOUND =

Speed of sound in meters per second.

343.0

Constants included from Behaviors::Reader

Behaviors::Reader::READ_WAIT_TIME

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::Threaded

#interrupts_enabled, #thread

Attributes included from Behaviors::State

#state

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board, #params

Instance Method Summary collapse

Methods included from Behaviors::Poller

#poll, #poll_using, #stop

Methods included from Behaviors::Threaded

#enable_interrupts, included, #mruby_thread_check, #stop, #stop_thread, #threaded, #threaded_loop

Methods included from Behaviors::Reader

#read, #read_busy?, #read_nb, #read_raw, #read_using, #update

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #remove_callback, #update

Methods included from Behaviors::State

#update_state

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::MultiPin

#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Method Details

#_readObject



24
25
26
# File 'lib/denko/sensor/hcsr04.rb', line 24

def _read
  board.hcsr04_read(echo.pin, trigger.pin)
end

#initialize_pins(options = {}) ⇒ Object



11
12
13
14
# File 'lib/denko/sensor/hcsr04.rb', line 11

def initialize_pins(options={})
  proxy_pin :trigger, DigitalIO::Output
  proxy_pin :echo,    DigitalIO::Input
end

#pre_callback_filter(us) ⇒ Object



28
29
30
31
32
# File 'lib/denko/sensor/hcsr04.rb', line 28

def pre_callback_filter(us)
  # Data is microseconds roundtrip time. Convert to mm.
  um = (us/2) * SPEED_OF_SOUND
  mm = um / 1000.0
end