Class: EventMachine::Gpio::Adapter
- Inherits:
-
Object
- Object
- EventMachine::Gpio::Adapter
- Defined in:
- lib/em-gpio/adapter.rb
Constant Summary collapse
- BASE_PATH =
"/sys/class/gpio/"
Instance Attribute Summary collapse
-
#pin ⇒ Object
Returns the value of attribute pin.
Instance Method Summary collapse
- #export! ⇒ Object
-
#initialize(pin) ⇒ Adapter
constructor
A new instance of Adapter.
- #read ⇒ Object
- #set_mode(direction) ⇒ Object
- #write(value) ⇒ Object
Constructor Details
#initialize(pin) ⇒ Adapter
Returns a new instance of Adapter.
9 10 11 |
# File 'lib/em-gpio/adapter.rb', line 9 def initialize(pin) @pin = pin end |
Instance Attribute Details
#pin ⇒ Object
Returns the value of attribute pin.
5 6 7 |
# File 'lib/em-gpio/adapter.rb', line 5 def pin @pin end |
Instance Method Details
#export! ⇒ Object
25 26 27 |
# File 'lib/em-gpio/adapter.rb', line 25 def export! File.open(BASE_PATH + "export", "w"){|f| f.write(pin)} end |
#read ⇒ Object
13 14 15 |
# File 'lib/em-gpio/adapter.rb', line 13 def read File.read(BASE_PATH + "gpio#{pin}/value").to_i end |
#set_mode(direction) ⇒ Object
21 22 23 |
# File 'lib/em-gpio/adapter.rb', line 21 def set_mode(direction) File.open(BASE_PATH + "gpio#{pin}/direction", "w"){|f| f.write(direction)} end |
#write(value) ⇒ Object
17 18 19 |
# File 'lib/em-gpio/adapter.rb', line 17 def write(value) File.open(BASE_PATH + "gpio#{pin}/value", "w"){|f| f.write(value)} end |