Sha256: c8276007bdca9752711b78bff27ccfb064a30e0360cbcf09eaccb6db80debec6

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

module Denko
  module SPI
    class Bus
      include Behaviors::Component
      include Behaviors::BusController
      include Behaviors::Reader

      # Board expects all components to have #pin.
      attr_reader :pin

      # Forward some methods directly to the board.
      extend Forwardable

      # Forward SPI methods with prefixed names.
      def_delegator :board, :spi_transfer,  :transfer
      def_delegator :board, :spi_listen,    :listen
      def_delegator :board, :spi_stop,      :stop

      # Forward pin control methods with same names for board proxying.
      def_delegator :board, :convert_pin
      def_delegator :board, :set_pin_mode

      # Add peripheral to self and the board. It gets callbacks directly from the board.
      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 peripheral from self and the board.
      def remove_component(component)
        components.delete(component)
        board.remove_component(component)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
denko-0.13.6 lib/denko/spi/bus.rb
denko-0.13.5 lib/denko/spi/bus.rb
denko-0.13.4 lib/denko/spi/bus.rb
denko-0.13.3 lib/denko/spi/bus.rb
denko-0.13.2 lib/denko/spi/bus.rb
denko-0.13.1 lib/denko/spi/bus.rb
denko-0.13.0 lib/denko/spi/bus.rb