Class: RubyPins::Pin
- Inherits:
-
Object
- Object
- RubyPins::Pin
- Defined in:
- lib/ruby_pins.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#pin ⇒ Object
Returns the value of attribute pin.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(args) ⇒ Pin
constructor
A new instance of Pin.
- #off ⇒ Object
- #on ⇒ Object
- #send_in ⇒ Object
- #set_direction(dir) ⇒ Object
- #set_out ⇒ Object
- #set_value(val) ⇒ Object
- #unexport ⇒ Object
Constructor Details
#initialize(args) ⇒ Pin
Returns a new instance of Pin.
8 9 10 11 |
# File 'lib/ruby_pins.rb', line 8 def initialize args args.each {|k, v| self.send "#{k}=", v} self.state= :off unless self.state end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/ruby_pins.rb', line 6 def name @name end |
#pin ⇒ Object
Returns the value of attribute pin.
6 7 8 |
# File 'lib/ruby_pins.rb', line 6 def pin @pin end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/ruby_pins.rb', line 6 def state @state end |
Instance Method Details
#export ⇒ Object
50 51 52 |
# File 'lib/ruby_pins.rb', line 50 def export `echo #{self.pin} > /sys/class/gpio/export` end |
#off ⇒ Object
29 30 31 32 |
# File 'lib/ruby_pins.rb', line 29 def off @state = :off unexport end |
#on ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ruby_pins.rb', line 22 def on @state = :on export set_out turn_on end |
#send_in ⇒ Object
38 39 40 |
# File 'lib/ruby_pins.rb', line 38 def send_in set_direction 'in' end |
#set_direction(dir) ⇒ Object
42 43 44 |
# File 'lib/ruby_pins.rb', line 42 def set_direction dir `echo #{dir} > /sys/class/gpio/gpio#{self.pin}/direction` end |
#set_out ⇒ Object
34 35 36 |
# File 'lib/ruby_pins.rb', line 34 def set_out set_direction 'out' end |
#set_value(val) ⇒ Object
46 47 48 |
# File 'lib/ruby_pins.rb', line 46 def set_value val `echo #{val} > /sys/class/gpio/gpio#{self.pin}/value` end |
#unexport ⇒ Object
54 55 56 |
# File 'lib/ruby_pins.rb', line 54 def unexport `echo #{self.pin} > /sys/class/gpio/unexport` end |