module FFI::WiringPi::GPIO

frozen_string_literal: true

Constants

GPIO_CLOCK
HIGH
INPUT
LOW
OUTPUT
PUD_DOWN
PUD_OFF
PUD_UP
PWM_MODE_BAL
PWM_MODE_MS
PWM_OUTPUT
PWM_TONE_OUTPUT
SOFT_PWM_OUTPUT
SOFT_TONE_OUTPUT

Public Class Methods

batch_write(boolean_array) click to toggle source
# File lib/ffi/wiring_pi/gpio.rb, line 129
def self.batch_write(boolean_array)
  digital_write_byte boolean_array.each_with_index.sum { |bit, i| (bit ? 1 : 0 ) << i }
end
down(pin) click to toggle source

Sets pin to LOW state

@param pin [Integer] pin position (depends on setup mode)

# File lib/ffi/wiring_pi/gpio.rb, line 92
def self.down(pin)
  write(pin, false)
end
get(pin, mode = FFI::WiringPi::GPIO::OUTPUT) click to toggle source
# File lib/ffi/wiring_pi/gpio.rb, line 52
def self.get(pin, mode = FFI::WiringPi::GPIO::OUTPUT)
  set_pin_mode(pin, mode)
  Pin.new(pin, mode)
end
pwm_mode(mode = :balanced) click to toggle source
# File lib/ffi/wiring_pi/gpio.rb, line 138
def self.pwm_mode(mode = :balanced)
  raise ArgumentError("mode is invalid: #{mode.inspect}") unless mode.in?([:balanced, :mark_space])
  pwm_set_mode mode == :balanced ? PWM_MODE_BAL : PWM_MODE_MS
end
pwm_range(range = 1024) click to toggle source
# File lib/ffi/wiring_pi/gpio.rb, line 147
def self.pwm_range(range = 1024)
  raise ArgumentError("range is invalid: #{range.inspect}") unless range.is_a?(Integer) && range >= 0
  pwm_set_range range
end
read(pin) click to toggle source

Read pin state (aka digital_read)

@param pin [Integer] pin position (depends on setup mode) @returns [Boolean] `true` if pin is in high state, `false` if in low

# File lib/ffi/wiring_pi/gpio.rb, line 106
def self.read(pin)
  result = digital_read(pin)
  case result
  when LOW
    false
  when HIGH
    true
  else
    raise "Unknown result: #{result.inspect}"
  end
end
up(pin) click to toggle source

Sets pin to HIGH state

@param pin [Integer] pin position (depends on setup mode)

# File lib/ffi/wiring_pi/gpio.rb, line 84
def self.up(pin)
  write(pin, true)
end
write(pin, state) click to toggle source

Write pin state (aka digital_write)

@param pin [Integer] pin position (depends on setup mode) @param state [Boolean] `true` to set to HIGH, `false` to set to LOW

# File lib/ffi/wiring_pi/gpio.rb, line 66
def self.write(pin, state)
  digital_write(pin, state ? HIGH : LOW)
end