Class: Brewby::Outputs::GPIO
- Inherits:
-
Object
- Object
- Brewby::Outputs::GPIO
- Defined in:
- lib/brewby/outputs/gpio.rb
Instance Attribute Summary collapse
-
#gpio_path ⇒ Object
readonly
Returns the value of attribute gpio_path.
-
#pin ⇒ Object
readonly
Returns the value of attribute pin.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GPIO
constructor
A new instance of GPIO.
- #initialize_gpio_direction ⇒ Object
- #initialize_gpio_pin ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
- #on? ⇒ Boolean
- #write(value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GPIO
Returns a new instance of GPIO.
5 6 7 8 9 10 11 |
# File 'lib/brewby/outputs/gpio.rb', line 5 def initialize = {} @pin = [:pin] @gpio_path = [:gpio_path] || '/sys/class/gpio' initialize_gpio_pin initialize_gpio_direction end |
Instance Attribute Details
#gpio_path ⇒ Object (readonly)
Returns the value of attribute gpio_path.
4 5 6 |
# File 'lib/brewby/outputs/gpio.rb', line 4 def gpio_path @gpio_path end |
#pin ⇒ Object (readonly)
Returns the value of attribute pin.
4 5 6 |
# File 'lib/brewby/outputs/gpio.rb', line 4 def pin @pin end |
Instance Method Details
#initialize_gpio_direction ⇒ Object
19 20 21 |
# File 'lib/brewby/outputs/gpio.rb', line 19 def initialize_gpio_direction File.write File.join(gpio_path, "gpio#{pin}", "direction"), 'out' end |
#initialize_gpio_pin ⇒ Object
13 14 15 16 17 |
# File 'lib/brewby/outputs/gpio.rb', line 13 def initialize_gpio_pin unless File.exists? File.join(gpio_path, "gpio#{pin}", "value") File.write File.join(gpio_path, "export"), pin end end |
#off ⇒ Object
27 28 29 |
# File 'lib/brewby/outputs/gpio.rb', line 27 def off write(0) end |
#on ⇒ Object
23 24 25 |
# File 'lib/brewby/outputs/gpio.rb', line 23 def on write(1) end |
#on? ⇒ Boolean
31 32 33 |
# File 'lib/brewby/outputs/gpio.rb', line 31 def on? '1' == File.read(File.join(gpio_path, "gpio#{pin}", "value")) end |
#write(value) ⇒ Object
35 36 37 |
# File 'lib/brewby/outputs/gpio.rb', line 35 def write value File.write File.join(gpio_path, "gpio#{pin}", "value"), value end |