Class: Pigpio

Inherits:
Object
  • Object
show all
Defined in:
lib/pigpio.rb,
lib/pigpio/i2c.rb,
lib/pigpio/pwm.rb,
lib/pigpio/spi.rb,
lib/pigpio/bank.rb,
lib/pigpio/gpio.rb,
lib/pigpio/wave.rb,
lib/pigpio/buffer.rb,
lib/pigpio/serial.rb,
lib/pigpio/version.rb,
lib/pigpio/constant.rb,
lib/pigpio/user_gpio.rb,
lib/pigpio/bit_bang_serial.rb,
lib/pigpio/bit_bang_serial_rx.rb,
lib/pigpio/bit_bang_serial_tx.rb,
ext/pigpio/pigpio.c

Defined Under Namespace

Modules: Constant, IF Classes: Bank, BitBangSerial, BitBangSerialRx, BitBangSerialTx, BscXfer, Buffer, Callback, CallbackError, GPIO, I2C, PWM, Pulse, SPI, Serial, UserGPIO, Wave

Constant Summary collapse

VERSION =
"0.1.12"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr = nil, port = nil, &blk) ⇒ Pigpio

Returns a new instance of Pigpio.



19
20
21
22
23
24
25
# File 'lib/pigpio.rb', line 19

def initialize(addr = nil, port = nil, &blk)
  @pi = IF.pigpio_start(addr, port)
  if blk && connect
    blk.call(self)
    IF.pigpio_stop(@pi)
  end
end

Instance Attribute Details

#piObject (readonly)

Returns the value of attribute pi.



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

def pi
  @pi
end

Instance Method Details

#bank(num) ⇒ Object



48
49
50
# File 'lib/pigpio.rb', line 48

def bank(num)
  Bank.new(@pi, num)
end

#connectObject



27
28
29
# File 'lib/pigpio.rb', line 27

def connect
  @pi >= 0
end

#current_tickObject



36
37
38
# File 'lib/pigpio.rb', line 36

def current_tick
  IF.get_current_tick(@pi)
end

#gpio(gpio) ⇒ Object



52
53
54
# File 'lib/pigpio.rb', line 52

def gpio(gpio)
  (gpio < 32 ? UserGPIO : GPIO).new(@pi, gpio)
end

#hardware_revisionObject



40
41
42
# File 'lib/pigpio.rb', line 40

def hardware_revision
  IF.get_hardware_revision(@pi)
end

#i2c(i2c_bus, i2c_addr) ⇒ Object



71
72
73
# File 'lib/pigpio.rb', line 71

def i2c(i2c_bus, i2c_addr)
  I2C.new(@pi, i2c_bus, i2c_addr)
end

#pigpio_versionObject



44
45
46
# File 'lib/pigpio.rb', line 44

def pigpio_version
  IF.get_pigpio_version(@pi)
end

#serial(rx, tx = nil, baud = 9600, data_bits = 8, stop_bits = 1, parity_type = :none) ⇒ Object



60
61
62
63
64
# File 'lib/pigpio.rb', line 60

def serial(rx, tx = nil, baud = 9600, data_bits = 8, stop_bits = 1, parity_type = :none)
  return BitBangSerialRx.new(rx, baud, data_bits) if tx.nil?
  return BitBangSerialTx.new(tx, baud, data_bits, stop_bits) if rx.nil?
  BitBangSerial.new(rx, tx, baud, data_bits, stop_bits)
end

#spi(spi_channel = 0, enable_cex = 1, baud = 500000, bits_per_word: 8, first_MISO: false, first_MOSI: false, idol_bytes: 0, is_3wire: false, active_low_cex: 0, spi_mode: 0) ⇒ Object



66
67
68
69
# File 'lib/pigpio.rb', line 66

def spi(spi_channel = 0, enable_cex = 1, baud = 500000,
  bits_per_word: 8, first_MISO: false, first_MOSI: false, idol_bytes: 0, is_3wire: false, active_low_cex: 0, spi_mode: 0)
  SPI.new(@pi, spi_channel, enable_cex, baud, bits_per_word: bits_per_word, first_MISO: first_MISO, first_MOSI: first_MOSI, idol_bytes: idol_bytes, is_3wire: is_3wire, active_low_cex: active_low_cex, spi_mode: spi_mode)
end

#stopObject



31
32
33
34
# File 'lib/pigpio.rb', line 31

def stop
  IF.pigpio_stop(@pi)
  @pi = -1
end

#waveObject



56
57
58
# File 'lib/pigpio.rb', line 56

def wave
  Wave.new(@pi)
end