Class: IntelGalileo::Gpio

Inherits:
Object
  • Object
show all
Defined in:
lib/intel_galileo/gpio.rb

Instance Method Summary collapse

Constructor Details

#initialize(gpio) ⇒ Gpio

Returns a new instance of Gpio.



3
4
5
6
7
8
# File 'lib/intel_galileo/gpio.rb', line 3

def initialize(gpio)
  @gpio = gpio
  @drive = nil
  @direction = nil
  self.enable()
end

Instance Method Details

#disableObject



43
44
45
# File 'lib/intel_galileo/gpio.rb', line 43

def disable
  unexport unless ! exported?
end

#enableObject



10
11
12
# File 'lib/intel_galileo/gpio.rb', line 10

def enable
  export unless exported?
end

#ensureDirection(direction) ⇒ Object



31
32
33
34
35
# File 'lib/intel_galileo/gpio.rb', line 31

def ensureDirection(direction)
  if @direction != direction
    setDirection(direction)
  end
end

#ensureDrive(drive) ⇒ Object



37
38
39
40
41
# File 'lib/intel_galileo/gpio.rb', line 37

def ensureDrive(drive)
  if @drive != drive
    setDrive(drive)
  end
end

#readObject



14
15
16
17
18
19
20
21
# File 'lib/intel_galileo/gpio.rb', line 14

def read
  ensureDirection('in')
  f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'r')
  value = f.read
  f.close
  puts "Reading"
  return value
end

#write(value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/intel_galileo/gpio.rb', line 23

def write(value)
  ensureDirection('out')
  f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'w')
  f.write(value)
  f.close
  puts "Writing #{value}"
end