Module: Denko::Behaviors::Subcomponents
- Included in:
- BoardProxy, BusController, Denko::Board
- Defined in:
- lib/denko/behaviors/subcomponents.rb
Instance Method Summary collapse
-
#add_component(component) ⇒ Object
Main Methods.
-
#add_hw_i2c(component) ⇒ Object
I2C.
-
#add_hw_spi(component) ⇒ Object
SPI.
-
#add_single_pin(component) ⇒ Object
Single Pin.
- #components ⇒ Object
- #hw_i2c_comps ⇒ Object
- #hw_spi_comps ⇒ Object
- #remove_component(component) ⇒ Object
- #remove_hw_i2c(component) ⇒ Object
- #remove_hw_spi(component) ⇒ Object
- #remove_single_pin(component) ⇒ Object
- #single_pin_components ⇒ Object
Instance Method Details
#add_component(component) ⇒ Object
Main Methods
7 8 9 10 11 12 |
# File 'lib/denko/behaviors/subcomponents.rb', line 7 def add_component(component) add_single_pin(component) add_hw_i2c(component) add_hw_spi(component) components << component end |
#add_hw_i2c(component) ⇒ Object
I2C
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/denko/behaviors/subcomponents.rb', line 53 def add_hw_i2c(component) if component.respond_to?(:i2c_index) unless hw_i2c_comps[component.i2c_index] hw_i2c_comps[component.i2c_index] = component else raise StandardError, "Error adding #{component} to #{self}. I2C dev: #{component.i2c_index} " \ "already in use by: #{hw_i2c_comps[component.i2c_index]}" end end end |
#add_hw_spi(component) ⇒ Object
SPI
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/denko/behaviors/subcomponents.rb', line 75 def add_hw_spi(component) if component.respond_to?(:spi_index) unless hw_spi_comps[component.spi_index] hw_spi_comps[component.spi_index] = component else raise StandardError, "Error adding #{component} to #{self}. SPI dev: #{component.spi_index} " \ "already in use by: #{hw_spi_comps[component.spi_index]}" end end end |
#add_single_pin(component) ⇒ Object
Single Pin
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/denko/behaviors/subcomponents.rb', line 29 def add_single_pin(component) if component.respond_to?(:pin) && component.pin.class == Integer unless single_pin_components[component.pin] single_pin_components[component.pin] = component else raise StandardError, "Error adding #{component} to #{self}. Pin: #{component.pin} " \ "already in use by: #{single_pin_components[component.pin]}" end end end |
#components ⇒ Object
22 23 24 |
# File 'lib/denko/behaviors/subcomponents.rb', line 22 def components @components ||= [] end |
#hw_i2c_comps ⇒ Object
68 69 70 |
# File 'lib/denko/behaviors/subcomponents.rb', line 68 def hw_i2c_comps @hw_i2c_comps ||= {} end |
#hw_spi_comps ⇒ Object
90 91 92 |
# File 'lib/denko/behaviors/subcomponents.rb', line 90 def hw_spi_comps @hw_spi_comps ||= {} end |
#remove_component(component) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/denko/behaviors/subcomponents.rb', line 14 def remove_component(component) remove_single_pin(component) remove_hw_i2c(component) remove_hw_spi(component) deleted = components.delete(component) component.stop if deleted && component.respond_to?(:stop) end |
#remove_hw_i2c(component) ⇒ Object
64 65 66 |
# File 'lib/denko/behaviors/subcomponents.rb', line 64 def remove_hw_i2c(component) hw_i2c_comps.delete(component.i2c_index) if component.respond_to?(:i2c_index) end |
#remove_hw_spi(component) ⇒ Object
86 87 88 |
# File 'lib/denko/behaviors/subcomponents.rb', line 86 def remove_hw_spi(component) hw_spi_comps.delete(component.spi_index) if component.respond_to?(:spi_index) end |
#remove_single_pin(component) ⇒ Object
40 41 42 43 44 |
# File 'lib/denko/behaviors/subcomponents.rb', line 40 def remove_single_pin(component) if component.respond_to?(:pin) && component.pin.class == Integer single_pin_components.delete(component.pin) end end |
#single_pin_components ⇒ Object
46 47 48 |
# File 'lib/denko/behaviors/subcomponents.rb', line 46 def single_pin_components @single_pin_components ||= {} end |