Class: Cgpio::VirtualGpio
- Inherits:
-
Object
- Object
- Cgpio::VirtualGpio
- Defined in:
- lib/cgpio/virtual_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 = {}) ⇒ VirtualGpio
constructor
A new instance of VirtualGpio.
- #off ⇒ Object
- #off? ⇒ Boolean
- #on ⇒ Object
- #on? ⇒ Boolean
- #value ⇒ Object
- #value=(val) ⇒ Object
Constructor Details
#initialize(nr, options = {}) ⇒ VirtualGpio
Returns a new instance of VirtualGpio.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cgpio/virtual_gpio.rb', line 4 def initialize(nr, ={}) = { direction: :out }.merge() @nr = nr @value = false # set the initial direction self.direction = [:direction] end |
Instance Attribute Details
#nr ⇒ Object (readonly)
Returns the value of attribute nr.
2 3 4 |
# File 'lib/cgpio/virtual_gpio.rb', line 2 def nr @nr end |
Instance Method Details
#direction ⇒ Object
34 35 36 |
# File 'lib/cgpio/virtual_gpio.rb', line 34 def direction @direction end |
#direction=(direction) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/cgpio/virtual_gpio.rb', line 16 def direction=(direction) if direction == :out @direction = 0x01 elsif direction == :in @direction = 0x02 else raise "unsupported gpio direction. use :out or :in" end end |
#off ⇒ Object
42 43 44 |
# File 'lib/cgpio/virtual_gpio.rb', line 42 def off self.value = false end |
#off? ⇒ Boolean
50 51 52 |
# File 'lib/cgpio/virtual_gpio.rb', line 50 def off? !value end |
#on ⇒ Object
38 39 40 |
# File 'lib/cgpio/virtual_gpio.rb', line 38 def on self.value = true end |
#on? ⇒ Boolean
46 47 48 |
# File 'lib/cgpio/virtual_gpio.rb', line 46 def on? value end |
#value ⇒ Object
26 27 28 |
# File 'lib/cgpio/virtual_gpio.rb', line 26 def value @value end |
#value=(val) ⇒ Object
30 31 32 |
# File 'lib/cgpio/virtual_gpio.rb', line 30 def value=(val) @value = val end |