Class: RubyPins::Pin

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pins.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/ruby_pins.rb', line 6

def name
  @name
end

#pinObject

Returns the value of attribute pin.



6
7
8
# File 'lib/ruby_pins.rb', line 6

def pin
  @pin
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/ruby_pins.rb', line 6

def state
  @state
end

Instance Method Details

#exportObject



50
51
52
# File 'lib/ruby_pins.rb', line 50

def export
  `echo #{self.pin} > /sys/class/gpio/export`
end

#offObject



29
30
31
32
# File 'lib/ruby_pins.rb', line 29

def off
  @state = :off
  unexport
end

#onObject



22
23
24
25
26
27
# File 'lib/ruby_pins.rb', line 22

def on
  @state = :on
  export
  set_out
  turn_on
end

#send_inObject



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_outObject



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

#unexportObject



54
55
56
# File 'lib/ruby_pins.rb', line 54

def unexport
  `echo #{self.pin} > /sys/class/gpio/unexport`
end