Class: Denko::Sensor::RCWL9620

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Poller, I2C::Peripheral
Defined in:
lib/denko/sensor/rcwl9620.rb

Instance Attribute Summary

Attributes included from Behaviors::Threaded

#interrupts_enabled, #thread

Attributes included from Behaviors::Callbacks

#callback_mutex

Attributes included from I2C::Peripheral

#i2c_frequency, #i2c_repeated_start

Attributes included from Behaviors::BusPeripheral

#address

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::Poller

#poll, #poll_using, #stop

Methods included from Behaviors::Threaded

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

Methods included from Behaviors::Reader

#read, #read_using, #wait_for_read

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #initialize, #remove_callback, #update

Methods included from Behaviors::State

#initialize, #state

Methods included from I2C::Peripheral

#i2c_read, #i2c_write

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Method Details

#_readObject



12
13
14
15
16
# File 'lib/denko/sensor/rcwl9620.rb', line 12

def _read
  i2c_write(0x01)
  sleep(0.120)
  i2c_read(nil, 3)
end

#before_initialize(options = {}) ⇒ Object



7
8
9
10
# File 'lib/denko/sensor/rcwl9620.rb', line 7

def before_initialize(options={})
  @i2c_address = 0x57
  super(options)
end

#pre_callback_filter(bytes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/denko/sensor/rcwl9620.rb', line 18

def pre_callback_filter(bytes)
  # Data is in micrometers, 3 bytes, big-endian.
  um = (bytes[0] << 16) + (bytes[1] << 8) + bytes[2]
  mm = um / 1000.0

  # Limit output between 20 and 4500mm.
  if mm > 4500.0
    return 4500.0
  elsif mm < 20.0
    return 20.0
  else
    return mm
  end
end