Class: Denko::Sensor::RCWL9620

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

Constant Summary collapse

I2C_ADDRESS =
0x57

Constants included from Behaviors::Reader

Behaviors::Reader::READ_WAIT_TIME

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Constants included from I2C::Peripheral

I2C::Peripheral::I2C_FREQUENCY, I2C::Peripheral::I2C_REPEATED_START

Instance Attribute Summary

Attributes included from Behaviors::Threaded

#interrupts_enabled, #thread

Attributes included from Behaviors::State

#state

Attributes included from I2C::Peripheral

#i2c_frequency, #i2c_repeated_start

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 I2C::Peripheral

#address, #i2c_default, #i2c_read, #i2c_read_raw, #i2c_write

Methods included from Behaviors::BusPeripheralAddressed

#address

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Method Details

#_readObject



9
10
11
12
13
14
# File 'lib/denko/sensor/rcwl9620.rb', line 9

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

#pre_callback_filter(bytes) ⇒ Object



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

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