Class: Denko::Sensor::RCWL9620
- Inherits:
-
Object
- Object
- Denko::Sensor::RCWL9620
- Includes:
- Behaviors::Poller, I2C::Peripheral
- Defined in:
- lib/denko/sensor/rcwl9620.rb
Instance Attribute Summary
Attributes included from Behaviors::Threaded
Attributes included from Behaviors::Callbacks
Attributes included from I2C::Peripheral
#i2c_frequency, #i2c_repeated_start
Attributes included from Behaviors::BusPeripheral
Attributes included from Behaviors::Component
Instance Method Summary collapse
Methods included from Behaviors::Poller
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
Methods included from I2C::Peripheral
Methods included from Behaviors::BusPeripheral
Methods included from Behaviors::Component
Instance Method Details
#_read ⇒ Object
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(={}) @i2c_address = 0x57 super() 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 |