Module: Denko::I2C::BusCommon
- Defined in:
- lib/denko/i2c/bus_common.rb
Constant Summary
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Constants included from Behaviors::Reader
Behaviors::Reader::READ_WAIT_TIME
Instance Attribute Summary
Attributes included from Behaviors::State
Attributes included from Behaviors::Component
Instance Method Summary collapse
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::Reader
#_read, #read, #read_busy?, #read_nb, #read_raw, #read_using, #update
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #pre_callback_filter, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::BusControllerAddressed
Methods included from Behaviors::BusController
Methods included from Behaviors::Subcomponents
#add_component, #add_hw_i2c, #add_hw_spi, #add_single_pin, #components, #hw_i2c_comps, #hw_spi_comps, #remove_component, #remove_hw_i2c, #remove_hw_spi, #remove_single_pin, #single_pin_components
Methods included from Behaviors::Component
Instance Method Details
#bubble_callbacks ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/denko/i2c/bus_common.rb', line 27 def bubble_callbacks add_callback(:bus_controller) do |data| bytes = nil # Array data from PiBoard. if data.class == Array address = data[0] bytes = data[1..-1] # String data from microcontroller. elsif (data.class == String) && (data.match /\A\d+-/) address, bytes = data.split("-", 2) address = address.to_i bytes = bytes.split(",").map(&:to_i) bytes = nil if bytes.empty? end # Update components. components.each { |c| c.update(bytes) if c.address == address } if bytes end end |
#found_devices ⇒ Object
12 13 14 |
# File 'lib/denko/i2c/bus_common.rb', line 12 def found_devices @found_devices ||= [] end |
#search ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/denko/i2c/bus_common.rb', line 16 def search addresses = read_using -> { _search } if addresses.class == String @found_devices = addresses.split(":").map(&:to_i).reject{ |e| e==0 } elsif addresses.class == Array # 0th element being 0 (invalid address) means the array contains search results, # instead of bytes read from a peripheral. Remove it. @found_devices = addresses - [0] end end |