Class: ObjectOrientedBeagleboneBlack::Gpio
- Inherits:
-
Object
- Object
- ObjectOrientedBeagleboneBlack::Gpio
- Defined in:
- lib/object_oriented_beaglebone_black/gpio.rb
Instance Method Summary collapse
- #direction ⇒ Object
- #direction=(direction) ⇒ Object
- #export ⇒ Object
-
#initialize(pin_number) ⇒ Gpio
constructor
A new instance of Gpio.
- #unexport ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize(pin_number) ⇒ Gpio
Returns a new instance of Gpio.
4 5 6 7 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 4 def initialize(pin_number) @pin_number = pin_number @gpio_directory = File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["io_root_directory"], "gpio") end |
Instance Method Details
#direction ⇒ Object
21 22 23 24 25 26 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 21 def direction # Using this instead of simple "File.open(file_path).read" in order to close file after reading. direction = nil File.open(File.join(@gpio_directory, "gpio#{@pin_number}", "direction"), "r") { |file| direction = file.read.strip } direction end |
#direction=(direction) ⇒ Object
17 18 19 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 17 def direction=(direction) File.open(File.join(@gpio_directory, "gpio#{@pin_number}", "direction"), "w") { |file| file.write(direction) } end |
#export ⇒ Object
9 10 11 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 9 def export File.open(File.join(@gpio_directory, "export"), "w") { |file| file.write(@pin_number) } end |
#unexport ⇒ Object
13 14 15 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 13 def unexport File.open(File.join(@gpio_directory, "unexport"), "w") { |file| file.write(@pin_number) } end |
#value ⇒ Object
32 33 34 35 36 37 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 32 def value # Using this instead of simple "File.open(file_path).read" in order to close file after reading. value = nil File.open(File.join(@gpio_directory, "gpio#{@pin_number}", "value"), "r") { |file| value = file.read.strip.to_i } value end |
#value=(value) ⇒ Object
28 29 30 |
# File 'lib/object_oriented_beaglebone_black/gpio.rb', line 28 def value=(value) File.open(File.join(@gpio_directory, "gpio#{@pin_number}", "value"), "w") { |file| file.write(value) } end |