intel_galileo 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/intel_galileo.rb
CHANGED
@@ -3,19 +3,26 @@ require File.dirname(__FILE__) + "/intel_galileo/gpio"
|
|
3
3
|
require File.dirname(__FILE__) + "/intel_galileo/pin"
|
4
4
|
require File.dirname(__FILE__) + "/intel_galileo/analog_in_pin"
|
5
5
|
require File.dirname(__FILE__) + "/intel_galileo/digital_pin"
|
6
|
+
require File.dirname(__FILE__) + "/intel_galileo/pwm"
|
6
7
|
|
7
8
|
module IntelGalileo
|
8
9
|
DIGITAL_PINS = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
|
9
10
|
DIGITAL_GPIOS = ["50","51","32","18","28","17","24","27","26","19","16","25","38","39"]
|
10
11
|
|
11
|
-
ANALOG_IN_PINS
|
12
|
-
|
12
|
+
ANALOG_IN_PINS = ["A0","A1","A2","A3","A4","A5"]
|
13
|
+
ANALOG_IN_MUX_GPIOS = ["37","36","23","22","21","20"]
|
13
14
|
|
15
|
+
PWM_GPIO_PINS = { 3 => 3, 5 => 5, 6 => 6, 9 => 1, 10 => 7, 11 => 4 }
|
16
|
+
|
14
17
|
def self.digital_pin2gpio(pin)
|
15
18
|
DIGITAL_GPIOS[DIGITAL_PINS.index(pin)]
|
16
19
|
end
|
17
20
|
|
18
21
|
def self.analog_in_pin2mux(pin)
|
19
|
-
|
22
|
+
ANALOG_IN_MUX_GPIOS[ANALOG_IN_PINS.index(pin)]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.pin2pwm(pin)
|
26
|
+
PWM_GPIO_PINS[pin]
|
20
27
|
end
|
21
28
|
end
|
@@ -2,11 +2,7 @@ module IntelGalileo
|
|
2
2
|
class AnalogInPin < Pin
|
3
3
|
def initialize(pin)
|
4
4
|
@pin = pin
|
5
|
-
|
6
|
-
@mux_gpio.ensureDrive('strong')
|
7
|
-
@mux_gpio.ensureDirection('out')
|
8
|
-
@mux_gpio.write(0)
|
9
|
-
@direction = nil
|
5
|
+
set_mux_gpio(pin)
|
10
6
|
end
|
11
7
|
|
12
8
|
def read
|
@@ -16,5 +12,18 @@ module IntelGalileo
|
|
16
12
|
puts "Reading"
|
17
13
|
return value
|
18
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def get_mux_gpio(pin)
|
19
|
+
IntelGalileo::Gpio.new(IntelGalileo.analog_in_pin2mux(pin))
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_mux_gpio(pin)
|
23
|
+
mux_gpio = get_mux_gpio(pin)
|
24
|
+
mux_gpio.ensureDrive('strong')
|
25
|
+
mux_gpio.ensureDirection('out')
|
26
|
+
mux_gpio.write(0)
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|
@@ -1,16 +1,23 @@
|
|
1
1
|
module IntelGalileo
|
2
2
|
class DigitalPin < Pin
|
3
|
+
attr_reader :gpio
|
3
4
|
def initialize(pin)
|
4
|
-
@gpio =
|
5
|
+
@gpio = get_gpio(pin)
|
5
6
|
@direction = nil
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
+
def read
|
9
10
|
@gpio.read()
|
10
11
|
end
|
11
12
|
|
12
13
|
def write(value)
|
13
14
|
@gpio.write(value)
|
14
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_gpio(pin)
|
20
|
+
IntelGalileo::Gpio.new(IntelGalileo.digital_pin2gpio(pin))
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module IntelGalileo
|
2
|
+
class Pwm
|
3
|
+
def initialize(pin)
|
4
|
+
@pwm = get_pwm(pin)
|
5
|
+
self.enable()
|
6
|
+
end
|
7
|
+
|
8
|
+
def enable
|
9
|
+
export unless exported?
|
10
|
+
end
|
11
|
+
|
12
|
+
def disable
|
13
|
+
unexport unless ! exported?
|
14
|
+
end
|
15
|
+
|
16
|
+
# period => 1ms = 1000000
|
17
|
+
def on(percent_time_on, period = 1000000)
|
18
|
+
write_period(period)
|
19
|
+
write_duty_cycle(period / 100 * percent_time_on)
|
20
|
+
end
|
21
|
+
|
22
|
+
def off
|
23
|
+
write_duty_cycle(0)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def write_duty_cycle(duty_cycle)
|
29
|
+
f = File.open("/sys/class/pwm/pwmchip0/pwm#{@pwm}/duty_cycle", 'w')
|
30
|
+
f.write(duty_cycle)
|
31
|
+
f.close
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_period(period)
|
35
|
+
f = File.open("/sys/class/pwm/pwmchip0/pwm#{@pwm}/period", 'w')
|
36
|
+
f.write(period)
|
37
|
+
f.close
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_pwm(pin)
|
41
|
+
IntelGalileo.pin2pwm(pin)
|
42
|
+
end
|
43
|
+
|
44
|
+
def exported?
|
45
|
+
File.exists?("/sys/class/pwm/pwmchip0/pwm#{@pwm}/enable")
|
46
|
+
end
|
47
|
+
|
48
|
+
def export
|
49
|
+
f = File.open('/sys/class/pwm/pwmchip0/export', 'w')
|
50
|
+
f.write(@pwm)
|
51
|
+
f.close
|
52
|
+
|
53
|
+
f = File.open("/sys/class/pwm/pwmchip0/pwm#{@pwm}/enable", 'w')
|
54
|
+
f.write(1)
|
55
|
+
f.close
|
56
|
+
end
|
57
|
+
|
58
|
+
def unexport
|
59
|
+
f = File.open('/sys/class/pwm/pwmchip0/unexport', 'w')
|
60
|
+
f.write(@pwm)
|
61
|
+
f.close
|
62
|
+
end
|
63
|
+
end
|
64
|
+
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.
|
4
|
+
version: 0.0.3
|
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-
|
12
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakefs
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: Gem for interacting with Intel Galileo board
|
47
79
|
email:
|
48
80
|
- misza222@gmail.com
|
@@ -52,10 +84,10 @@ extra_rdoc_files: []
|
|
52
84
|
files:
|
53
85
|
- lib/intel_galileo.rb
|
54
86
|
- lib/intel_galileo/analog_in_pin.rb
|
55
|
-
- lib/intel_galileo/analog_out_pin.rb
|
56
87
|
- lib/intel_galileo/digital_pin.rb
|
57
88
|
- lib/intel_galileo/gpio.rb
|
58
89
|
- lib/intel_galileo/pin.rb
|
90
|
+
- lib/intel_galileo/pwm.rb
|
59
91
|
- lib/intel_galileo/version.rb
|
60
92
|
homepage: https://github.com/itsudo/intel_galileo
|
61
93
|
licenses:
|
@@ -69,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
101
|
requirements:
|
70
102
|
- - ! '>='
|
71
103
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
104
|
+
version: 1.9.2
|
73
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
106
|
none: false
|
75
107
|
requirements:
|
File without changes
|