Class: BBB::Pins::IO::GPIO
- Inherits:
-
Object
- Object
- BBB::Pins::IO::GPIO
- Includes:
- Mapped
- Defined in:
- lib/BBB/pins/io/gpio.rb
Instance Attribute Summary collapse
-
#converted_position ⇒ Object
readonly
Returns the value of attribute converted_position.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#file_mode ⇒ Object
readonly
Returns the value of attribute file_mode.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #export ⇒ Object
- #export_path ⇒ Object
- #file_class ⇒ Object
- #gpio_path ⇒ Object
- #gpio_pin_dir ⇒ Object
-
#initialize(direction, position) ⇒ GPIO
constructor
A new instance of GPIO.
- #io ⇒ Object
- #read ⇒ Object
- #set_mode ⇒ Object
- #unexport ⇒ Object
- #unexport_path ⇒ Object
- #value_map ⇒ Object
- #write(value) ⇒ Object
Methods included from Mapped
Constructor Details
#initialize(direction, position) ⇒ GPIO
9 10 11 12 13 14 |
# File 'lib/BBB/pins/io/gpio.rb', line 9 def initialize(direction, position) self.direction = direction @position = position @converted_position = pin_map.gpio self.export end |
Instance Attribute Details
#converted_position ⇒ Object (readonly)
Returns the value of attribute converted_position.
7 8 9 |
# File 'lib/BBB/pins/io/gpio.rb', line 7 def converted_position @converted_position end |
#direction ⇒ Object
Returns the value of attribute direction.
7 8 9 |
# File 'lib/BBB/pins/io/gpio.rb', line 7 def direction @direction end |
#file_mode ⇒ Object (readonly)
Returns the value of attribute file_mode.
7 8 9 |
# File 'lib/BBB/pins/io/gpio.rb', line 7 def file_mode @file_mode end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
7 8 9 |
# File 'lib/BBB/pins/io/gpio.rb', line 7 def position @position end |
Instance Method Details
#export ⇒ Object
62 63 64 65 |
# File 'lib/BBB/pins/io/gpio.rb', line 62 def export file_class.open(export_path, "w") { |f| f.write("#{ converted_position }") } set_mode end |
#export_path ⇒ Object
50 51 52 |
# File 'lib/BBB/pins/io/gpio.rb', line 50 def export_path gpio_path + "/export" end |
#file_class ⇒ Object
71 72 73 |
# File 'lib/BBB/pins/io/gpio.rb', line 71 def file_class File end |
#gpio_path ⇒ Object
46 47 48 |
# File 'lib/BBB/pins/io/gpio.rb', line 46 def gpio_path "/sys/class/gpio" end |
#gpio_pin_dir ⇒ Object
58 59 60 |
# File 'lib/BBB/pins/io/gpio.rb', line 58 def gpio_pin_dir "#{gpio_path}/gpio#{converted_position}" end |
#io ⇒ Object
26 27 28 29 30 |
# File 'lib/BBB/pins/io/gpio.rb', line 26 def io return @io unless @io.nil? value_file = gpio_pin_dir + "/value" @io = file_class.open(value_file, file_mode) end |
#read ⇒ Object
37 38 39 40 |
# File 'lib/BBB/pins/io/gpio.rb', line 37 def read io.rewind value_map[io.read] end |
#set_mode ⇒ Object
21 22 23 24 |
# File 'lib/BBB/pins/io/gpio.rb', line 21 def set_mode direction_file = gpio_pin_dir + "/direction" file_class.open(direction_file, "w") {|f| f.write(direction)} end |
#unexport ⇒ Object
67 68 69 |
# File 'lib/BBB/pins/io/gpio.rb', line 67 def unexport file_class.open(unexport_path, "w") { |f| f.write("#{converted_position}") } end |
#unexport_path ⇒ Object
54 55 56 |
# File 'lib/BBB/pins/io/gpio.rb', line 54 def unexport_path gpio_path + "/unexport" end |
#value_map ⇒ Object
42 43 44 |
# File 'lib/BBB/pins/io/gpio.rb', line 42 def value_map @value_map ||= {:high=>1, :low=>0, 1=>:high, 0=>:low} end |
#write(value) ⇒ Object
32 33 34 35 |
# File 'lib/BBB/pins/io/gpio.rb', line 32 def write(value) io.write(value_map[value]) io.flush end |