Class: Cgpio::RealGpio
- Inherits:
-
Object
- Object
- Cgpio::RealGpio
- Defined in:
- lib/cgpio/real_gpio.rb
Instance Attribute Summary collapse
-
#nr ⇒ Object
readonly
Returns the value of attribute nr.
Instance Method Summary collapse
- #direction ⇒ Object
- #direction=(direction) ⇒ Object
-
#initialize(nr, options = {}) ⇒ RealGpio
constructor
A new instance of RealGpio.
- #off ⇒ Object
- #off? ⇒ Boolean
- #on ⇒ Object
- #on? ⇒ Boolean
Constructor Details
#initialize(nr, options = {}) ⇒ RealGpio
Returns a new instance of RealGpio.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cgpio/real_gpio.rb', line 5 def initialize(nr, ={}) = { direction: :out }.merge() @nr = nr # this will export the pin setup @nr # set the initial direction self.direction = [:direction] end |
Instance Attribute Details
#nr ⇒ Object (readonly)
Returns the value of attribute nr.
3 4 5 |
# File 'lib/cgpio/real_gpio.rb', line 3 def nr @nr end |
Instance Method Details
#direction ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/cgpio/real_gpio.rb', line 30 def direction if (get_direction == 0x01) :out elsif (get_direction == 0x02) :in else raise "unknown gpio direction" end end |
#direction=(direction) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cgpio/real_gpio.rb', line 19 def direction=(direction) if direction == :out # direction values defined in ext/cgpio/gpio.h set_direction(0x01) elsif direction == :in set_direction(0x02) else raise "unsupported gpio direction. use :out or :in" end end |
#off ⇒ Object
44 45 46 |
# File 'lib/cgpio/real_gpio.rb', line 44 def off self.value = false end |
#off? ⇒ Boolean
52 53 54 |
# File 'lib/cgpio/real_gpio.rb', line 52 def off? !self.value end |
#on ⇒ Object
40 41 42 |
# File 'lib/cgpio/real_gpio.rb', line 40 def on self.value = true end |
#on? ⇒ Boolean
48 49 50 |
# File 'lib/cgpio/real_gpio.rb', line 48 def on? self.value end |