Class: Cgpio::RealGpio

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

    @nr = nr

    # this will export the pin
    setup @nr

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

Instance Attribute Details

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

#directionObject



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

#offObject



44
45
46
# File 'lib/cgpio/real_gpio.rb', line 44

def off
    self.value = false
end

#off?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/cgpio/real_gpio.rb', line 52

def off?
    !self.value
end

#onObject



40
41
42
# File 'lib/cgpio/real_gpio.rb', line 40

def on
    self.value = true
end

#on?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/cgpio/real_gpio.rb', line 48

def on?
    self.value
end