Class: Cgpio::VirtualGpio

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
    options = {
        direction: :out
    }.merge(options)

    @nr = nr
    @value = false

    # set the initial direction
    self.direction = options[:direction]
end

Instance Attribute Details

#nrObject (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

#directionObject



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

#offObject



42
43
44
# File 'lib/cgpio/virtual_gpio.rb', line 42

def off
    self.value = false
end

#off?Boolean

Returns:

  • (Boolean)


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

def off?
    !value
end

#onObject



38
39
40
# File 'lib/cgpio/virtual_gpio.rb', line 38

def on
    self.value = true
end

#on?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/cgpio/virtual_gpio.rb', line 46

def on?
    value
end

#valueObject



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