Class: Denko::SPI::Bus

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Behaviors::BusController, Behaviors::Component, Behaviors::Reader
Defined in:
lib/denko/spi/bus.rb

Instance Attribute Summary collapse

Attributes included from Behaviors::Callbacks

#callback_mutex

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::Reader

#_read, #read, #read_using, #wait_for_read

Methods included from Behaviors::Callbacks

#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update

Methods included from Behaviors::State

#initialize, #state

Methods included from Behaviors::BusController

#mutex

Methods included from Behaviors::Subcomponents

#components, #single_pin_components

Methods included from Behaviors::Component

#initialize, #micro_delay

Instance Attribute Details

#pinObject (readonly)

Board expects all components to have #pin.



9
10
11
# File 'lib/denko/spi/bus.rb', line 9

def pin
  @pin
end

Instance Method Details

#add_component(component) ⇒ Object

Add peripheral to self and the board. It gets callbacks directly from the board.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/denko/spi/bus.rb', line 24

def add_component(component)
  # Treat pin 255 as the component having no select pin. Mostly for APA102.
  return if component.pin == 255

  pins = components.map { |c| c.pin }
  if pins.include? component.pin
    raise ArgumentError, "duplicate select pin for #{component}"
  end

  components << component
  board.add_component(component)
end

#remove_component(component) ⇒ Object

Remove peripheral from self and the board.



38
39
40
41
# File 'lib/denko/spi/bus.rb', line 38

def remove_component(component)
  components.delete(component)
  board.remove_component(component)
end