Class: EventMachine::Gpio::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/em-gpio/adapter.rb

Constant Summary collapse

BASE_PATH =
"/sys/class/gpio/"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pinObject

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

#readObject



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