Class: Taopaipai::IO
- Inherits:
-
Object
- Object
- Taopaipai::IO
- Defined in:
- lib/taopaipai/io.rb
Constant Summary collapse
- MAX_WRITE_ATTEMPTS =
220
Instance Method Summary collapse
- #direction(pin, direction) ⇒ Object
- #export(pin) ⇒ Object
-
#initialize(base_path) ⇒ IO
constructor
A new instance of IO.
- #read(pin) ⇒ Object
- #unexport(pin) ⇒ Object
- #write(pin, value) ⇒ Object
Constructor Details
#initialize(base_path) ⇒ IO
Returns a new instance of IO.
5 6 7 |
# File 'lib/taopaipai/io.rb', line 5 def initialize(base_path) @base_path = base_path end |
Instance Method Details
#direction(pin, direction) ⇒ Object
17 18 19 |
# File 'lib/taopaipai/io.rb', line 17 def direction(pin, direction) write_to_file("gpio#{pin}/direction", direction) end |
#export(pin) ⇒ Object
9 10 11 |
# File 'lib/taopaipai/io.rb', line 9 def export(pin) write_to_file('export', pin.to_s) end |
#read(pin) ⇒ Object
21 22 23 |
# File 'lib/taopaipai/io.rb', line 21 def read(pin) File.open(relative("gpio#{pin}/value"), 'r'){|f| f.read } end |
#unexport(pin) ⇒ Object
13 14 15 |
# File 'lib/taopaipai/io.rb', line 13 def unexport(pin) write_to_file('unexport', pin.to_s) end |
#write(pin, value) ⇒ Object
25 26 27 |
# File 'lib/taopaipai/io.rb', line 25 def write(pin, value) write_to_file("gpio#{pin}/value", value) end |