intel_galileo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module IntelGalileo
2
+ class AnalogInPin < Pin
3
+ def initialize(pin)
4
+ @pin = pin
5
+ @mux_gpio = IntelGalileo::Gpio.new(IntelGalileo.analog_in_pin2mux(pin))
6
+ @mux_gpio.ensureDrive('strong')
7
+ @mux_gpio.ensureDirection('out')
8
+ @mux_gpio.write(0)
9
+ @direction = nil
10
+ end
11
+
12
+ def read
13
+ f = File.open("/sys/bus/iio/devices/iio\:device0/in_voltage#{@pin.to_i}_raw", 'r')
14
+ value = f.read
15
+ f.close
16
+ puts "Reading"
17
+ return value
18
+ end
19
+ end
20
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ module IntelGalileo
2
+ class DigitalPin < Pin
3
+ def initialize(pin)
4
+ @gpio = IntelGalileo::Gpio.new(IntelGalileo.digital_pin2gpio(pin))
5
+ @direction = nil
6
+ end
7
+
8
+ def read
9
+ @gpio.read()
10
+ end
11
+
12
+ def write(value)
13
+ @gpio.write(value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,81 @@
1
+ module IntelGalileo
2
+ class Gpio
3
+ def initialize(gpio)
4
+ @gpio = gpio
5
+ @drive = nil
6
+ @direction = nil
7
+ self.enable()
8
+ end
9
+
10
+ def enable
11
+ export unless exported?
12
+ end
13
+
14
+ def read
15
+ ensureDirection('in')
16
+ f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'r')
17
+ value = f.read
18
+ f.close
19
+ puts "Reading"
20
+ return value
21
+ end
22
+
23
+ def write(value)
24
+ ensureDirection('out')
25
+ f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'w')
26
+ f.write(value)
27
+ f.close
28
+ puts "Writing #{value}"
29
+ end
30
+
31
+ def ensureDirection(direction)
32
+ if @direction != direction
33
+ setDirection(direction)
34
+ end
35
+ end
36
+
37
+ def ensureDrive(drive)
38
+ if @drive != drive
39
+ setDrive(drive)
40
+ end
41
+ end
42
+
43
+ def disable
44
+ unexport unless ! exported?
45
+ end
46
+
47
+ private
48
+
49
+ def setDirection(direction)
50
+ @direction = direction
51
+ f = File.open("/sys/class/gpio/gpio#{@gpio}/direction", 'w')
52
+ f.write(direction)
53
+ f.close
54
+ puts "Setting direction to #{direction}"
55
+ end
56
+
57
+ def setDrive(drive)
58
+ @drive = drive
59
+ f = File.open("/sys/class/gpio/gpio#{@gpio}/drive", 'w')
60
+ f.write(drive)
61
+ f.close
62
+ puts "Setting drive to #{drive}"
63
+ end
64
+
65
+ def exported?
66
+ File.exists?("/sys/class/gpio/gpio#{@gpio}/value")
67
+ end
68
+
69
+ def export
70
+ f = File.open('/sys/class/gpio/export', 'w')
71
+ f.write(@gpio)
72
+ f.close
73
+ end
74
+
75
+ def unexport
76
+ f = File.open('/sys/class/gpio/unexport', 'w')
77
+ f.write(@gpio)
78
+ f.close
79
+ end
80
+ end
81
+ end
@@ -1,66 +1,6 @@
1
1
  module IntelGalileo
2
2
  class Pin
3
- def initialize(pin)
4
- @gpio = IntelGalileo.pin2gpio(pin)
5
- @direction = nil
6
- self.enable()
7
- end
8
-
9
- def enable
10
- export unless exported?
11
- end
12
-
13
3
  def read
14
- ensureDirection('in')
15
- f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'r')
16
- value = f.read
17
- f.close
18
- puts "Reading"
19
- return value
20
- end
21
-
22
- def write(value)
23
- ensureDirection('out')
24
- f = File.open("/sys/class/gpio/gpio#{@gpio}/value", 'w')
25
- f.write(value)
26
- f.close
27
- puts "Writing #{value}"
28
- end
29
-
30
- def ensureDirection(direction)
31
- if @direction != direction
32
- setDirection(direction)
33
- end
34
- end
35
-
36
- def disable
37
- unexport unless ! exported?
38
- end
39
-
40
- private
41
-
42
- def setDirection(direction)
43
- @direction = direction
44
- f = File.open("/sys/class/gpio/gpio#{@gpio}/direction", 'w')
45
- f.write(direction)
46
- f.close
47
- puts "Setting direction to #{direction}"
48
- end
49
-
50
- def exported?
51
- File.exists?("/sys/class/gpio/gpio#{@gpio}/value")
52
- end
53
-
54
- def export
55
- f = File.open('/sys/class/gpio/export', 'w')
56
- f.write(@gpio)
57
- f.close
58
- end
59
-
60
- def unexport
61
- f = File.open('/sys/class/gpio/unexport', 'w')
62
- f.write(@gpio)
63
- f.close
64
4
  end
65
5
  end
66
6
  end
@@ -1,3 +1,3 @@
1
1
  module IntelGalileo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/intel_galileo.rb CHANGED
@@ -1,11 +1,21 @@
1
1
  require File.dirname(__FILE__) + "/intel_galileo/version"
2
+ require File.dirname(__FILE__) + "/intel_galileo/gpio"
2
3
  require File.dirname(__FILE__) + "/intel_galileo/pin"
4
+ require File.dirname(__FILE__) + "/intel_galileo/analog_in_pin"
5
+ require File.dirname(__FILE__) + "/intel_galileo/digital_pin"
3
6
 
4
7
  module IntelGalileo
5
- PINS = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
6
- GPIO = ["50","51","32","18","28","17","24","27","26","19","16","25","38","39"]
8
+ DIGITAL_PINS = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
9
+ DIGITAL_GPIOS = ["50","51","32","18","28","17","24","27","26","19","16","25","38","39"]
7
10
 
8
- def self.pin2gpio(pin)
9
- GPIO[PINS.index(pin)]
11
+ ANALOG_IN_PINS = ["A0","A1","A2","A3","A4","A5"]
12
+ MUX_GPIOS = ["37","36","23","22","21","20"]
13
+
14
+ def self.digital_pin2gpio(pin)
15
+ DIGITAL_GPIOS[DIGITAL_PINS.index(pin)]
16
+ end
17
+
18
+ def self.analog_in_pin2mux(pin)
19
+ MUX_GPIOS[ANALOG_IN_PINS.index(pin)]
10
20
  end
11
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intel_galileo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-06 00:00:00.000000000 Z
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -51,6 +51,10 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - lib/intel_galileo.rb
54
+ - lib/intel_galileo/analog_in_pin.rb
55
+ - lib/intel_galileo/analog_out_pin.rb
56
+ - lib/intel_galileo/digital_pin.rb
57
+ - lib/intel_galileo/gpio.rb
54
58
  - lib/intel_galileo/pin.rb
55
59
  - lib/intel_galileo/version.rb
56
60
  homepage: https://github.com/itsudo/intel_galileo