Class: Pigpio
- Inherits:
-
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
-
#bank(num) ⇒ Object
-
#connect ⇒ Object
-
#current_tick ⇒ Object
-
#gpio(gpio) ⇒ Object
-
#hardware_revision ⇒ Object
-
#i2c(i2c_bus, i2c_addr) ⇒ Object
-
#initialize(addr = nil, port = nil, &blk) ⇒ Pigpio
constructor
A new instance of Pigpio.
-
#pigpio_version ⇒ Object
-
#serial(rx, tx = nil, baud = 9600, data_bits = 8, stop_bits = 1, parity_type = :none) ⇒ Object
-
#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
-
#stop ⇒ Object
-
#wave ⇒ Object
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
#pi ⇒ Object
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
|
#connect ⇒ Object
27
28
29
|
# File 'lib/pigpio.rb', line 27
def connect
@pi >= 0
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_revision ⇒ Object
#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
|
#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
|
#stop ⇒ Object
31
32
33
34
|
# File 'lib/pigpio.rb', line 31
def stop
IF.pigpio_stop(@pi)
@pi = -1
end
|
#wave ⇒ Object
56
57
58
|
# File 'lib/pigpio.rb', line 56
def wave
Wave.new(@pi)
end
|