Class: GpioSysfs::Pin

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pin) ⇒ Pin

Returns a new instance of Pin.



7
8
9
# File 'lib/gpio_sysfs/pin.rb', line 7

def initialize(pin)
  @pin = pin
end

Instance Attribute Details

#pinObject

Returns the value of attribute pin.



5
6
7
# File 'lib/gpio_sysfs/pin.rb', line 5

def pin
  @pin
end

Instance Method Details

#directionObject



21
22
23
24
25
# File 'lib/gpio_sysfs/pin.rb', line 21

def direction
  export

  File.read(direction_path).chomp
end

#direction=(direction) ⇒ Object



27
28
29
30
31
# File 'lib/gpio_sysfs/pin.rb', line 27

def direction=(direction)
  export

  File.write(direction_path, direction)
end

#exportObject



11
12
13
14
15
# File 'lib/gpio_sysfs/pin.rb', line 11

def export
  return if exported?

  File.write(EXPORT_PATH, pin)
end

#exported?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/gpio_sysfs/pin.rb', line 17

def exported?
  File.exist?(pin_path)
end

#valueObject



33
34
35
36
37
# File 'lib/gpio_sysfs/pin.rb', line 33

def value
  export

  File.read(value_path).to_i.positive?
end

#value=(value) ⇒ Object



39
40
41
42
43
# File 'lib/gpio_sysfs/pin.rb', line 39

def value=(value)
  self.direction = "out"

  File.write(value_path, normalized_value(value))
end