intel_galileo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ module IntelGalileo
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
+ 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
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module IntelGalileo
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + "/intel_galileo/version"
2
+ require File.dirname(__FILE__) + "/intel_galileo/pin"
3
+
4
+ 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"]
7
+
8
+ def self.pin2gpio(pin)
9
+ GPIO[PINS.index(pin)]
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intel_galileo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michal Pawlowski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Gem for interacting with Intel Galileo board
47
+ email:
48
+ - misza222@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/intel_galileo.rb
54
+ - lib/intel_galileo/pin.rb
55
+ - lib/intel_galileo/version.rb
56
+ homepage: https://github.com/itsudo/intel_galileo
57
+ licenses:
58
+ - MIT
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.25
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Interact with Intel Galileo board
81
+ test_files: []