Class: SPI

Inherits:
Object
  • Object
show all
Defined in:
lib/spi.rb,
lib/spi/driver.rb,
lib/spi/version.rb,
lib/spi/driver/spidev.rb

Defined Under Namespace

Modules: Driver Classes: SPIException

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SPI

Returns a new instance of SPI.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spi.rb', line 10

def initialize (args={})

  if args[:driver].nil?
    require "spi/driver/spidev"
    @device = args[:device] or raise SPIException, "args[:device] required"
    @driver = SPI::Driver::SPIdev.new(device: @device)
  end

  def speed
    @driver.speed
  end

  def speed=(speed)
    @driver.speed=speed
  end

  def xfer(txdata: [], length: 0)
    @driver.xfer(txdata: txdata, length: length)
  end

end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver


8
9
10
# File 'lib/spi.rb', line 8

def driver
  @driver
end

Instance Method Details

#speedObject


18
19
20
# File 'lib/spi.rb', line 18

def speed
  @driver.speed
end

#speed=(speed) ⇒ Object


22
23
24
# File 'lib/spi.rb', line 22

def speed=(speed)
  @driver.speed=speed
end

#xfer(txdata: [], length: 0) ⇒ Object


26
27
28
# File 'lib/spi.rb', line 26

def xfer(txdata: [], length: 0)
  @driver.xfer(txdata: txdata, length: length)
end