Class: GPIO::Pin
- Inherits:
-
Object
- Object
- GPIO::Pin
- Defined in:
- lib/gpio/pin.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#hardware_pin ⇒ Object
readonly
Returns the value of attribute hardware_pin.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#pin ⇒ Object
readonly
Returns the value of attribute pin.
-
#software_pin ⇒ Object
readonly
Returns the value of attribute software_pin.
Instance Method Summary collapse
-
#initialize(params) ⇒ Pin
constructor
(pin, mode, device=:RaspberryPi).
- #read ⇒ Object
Constructor Details
#initialize(params) ⇒ Pin
(pin, mode, device=:RaspberryPi)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gpio/pin.rb', line 4 def initialize(params) #(pin, mode, device=:RaspberryPi) @device = GPIO.const_get(params[:device]||:RaspberryPi) @pin = params[:pin].to_int @hardware_pin = device.hardware_pin(pin) @software_pin = device.software_pin(pin) @mode = params[:mode].to_s raise "Mode should be :in, :out, :bi, :pwm." unless ['in','out'].include? @mode device.initialize_pin(software_pin, @mode) @mode ||= get_direction @file = @device.pin_file(pin, mode) end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def device @device end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def file @file end |
#hardware_pin ⇒ Object (readonly)
Returns the value of attribute hardware_pin.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def hardware_pin @hardware_pin end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def mode @mode end |
#pin ⇒ Object (readonly)
Returns the value of attribute pin.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def pin @pin end |
#software_pin ⇒ Object (readonly)
Returns the value of attribute software_pin.
3 4 5 |
# File 'lib/gpio/pin.rb', line 3 def software_pin @software_pin end |
Instance Method Details
#read ⇒ Object
19 20 21 |
# File 'lib/gpio/pin.rb', line 19 def read file.rewind; file.getc end |