Class: Denko::I2C::Bus
Instance Attribute Summary collapse
#callback_mutex
#mode, #pin
#board
Instance Method Summary
collapse
#read, #read_using, #wait_for_read
#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update
#initialize, #state
#add_component
#mutex
#add_component, #components, #remove_component, #single_pin_components
#initialize, #micro_delay
Instance Attribute Details
#found_devices ⇒ Object
Returns the value of attribute found_devices.
8
9
10
|
# File 'lib/denko/i2c/bus.rb', line 8
def found_devices
@found_devices
end
|
Instance Method Details
#_read(address, register, num_bytes, frequency = 100000, repeated_start = false) ⇒ Object
25
26
27
|
# File 'lib/denko/i2c/bus.rb', line 25
def _read(address, register, num_bytes, frequency=100000, repeated_start=false)
board.i2c_read(address, register, num_bytes, frequency, repeated_start)
end
|
#after_initialize(options = {}) ⇒ Object
10
11
12
13
14
|
# File 'lib/denko/i2c/bus.rb', line 10
def after_initialize(options={})
super(options)
@found_devices = []
bubble_callbacks
end
|
#bubble_callbacks ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/denko/i2c/bus.rb', line 29
def bubble_callbacks
add_callback(:bus_controller) do |str|
if str && str.match(/\A\d+-/)
address, data = str.split("-", 2)
address = address.to_i
data = data.split(",").map(&:to_i)
data = nil if data.empty?
update_component(address, data)
end
end
end
|
#search ⇒ Object
16
17
18
19
|
# File 'lib/denko/i2c/bus.rb', line 16
def search
addresses = read_using -> { board.i2c_search }
@found_devices = addresses.split(":").map(&:to_i) if addresses
end
|
#update_component(address, data) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/denko/i2c/bus.rb', line 43
def update_component(address, data)
components.each do |component|
if component.address == address
component.update(data)
end
end
end
|
#write(address, bytes, frequency = 100000, repeated_start = false) ⇒ Object
21
22
23
|
# File 'lib/denko/i2c/bus.rb', line 21
def write(address, bytes, frequency=100000, repeated_start=false)
board.i2c_write(address, bytes, frequency, repeated_start)
end
|