raspberry_pi_iot 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Actuator.html +1 -1
- data/doc/BH1750.html +1 -1
- data/doc/BME280.html +1 -1
- data/doc/BMP280.html +1 -1
- data/doc/BMxSensor.html +1 -1
- data/doc/BinaryActuator.html +1 -1
- data/doc/BinaryEffector.html +1 -1
- data/doc/BinaryReceptor.html +1 -1
- data/doc/BinarySensor.html +1 -1
- data/doc/Bus.html +1 -1
- data/doc/Button.html +343 -53
- data/doc/DHT11.html +1 -1
- data/doc/DHT22.html +1 -1
- data/doc/DHTxxSensor.html +1 -1
- data/doc/DS18B20.html +1 -1
- data/doc/DigitalActuator.html +1 -1
- data/doc/DigitalEffector.html +16 -28
- data/doc/DigitalReceptor.html +1 -1
- data/doc/DigitalSensor.html +1 -1
- data/doc/Effector.html +1 -1
- data/doc/HCSR501.html +1 -1
- data/doc/HumitureSensor.html +1 -1
- data/doc/IoT.html +1 -1
- data/doc/LED.html +99 -47
- data/doc/MAX44009.html +1 -1
- data/doc/RaspberryPi.html +1 -1
- data/doc/RaspberryPiIoT.html +115 -0
- data/doc/Receptor.html +1 -1
- data/doc/Sensor.html +1 -1
- data/doc/TemperatureSensor.html +1 -1
- data/doc/_index.html +16 -1
- data/doc/class_list.html +1 -1
- data/doc/file.LICENSE.html +92 -0
- data/doc/file.README.html +26 -4
- data/doc/file_list.html +5 -0
- data/doc/index.html +26 -4
- data/doc/method_list.html +105 -113
- data/doc/top-level-namespace.html +2 -2
- data/lib/button.rb +28 -4
- data/lib/digital_effector.rb +8 -14
- data/lib/led.rb +4 -0
- data/lib/led_rgb.rb +27 -44
- data/lib/raspberry_pi_iot.rb +7 -0
- data/test/test_Raspberry_Pi_IoT.rb +11 -0
- data/test/test_button.rb +9 -3
- data/test/test_helper.rb +4 -0
- data/test/test_led.rb +4 -4
- data/test/test_led_rgb.rb +25 -2
- data/test/test_thermal.rb +27 -0
- metadata +69 -4
@@ -82,7 +82,7 @@
|
|
82
82
|
<p class="children">
|
83
83
|
|
84
84
|
|
85
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Bus.html" title="Bus (module)">Bus</a></span>, <span class='object_link'><a href="IoT.html" title="IoT (module)">IoT</a></span>, <span class='object_link'><a href="RaspberryPi.html" title="RaspberryPi (module)">RaspberryPi</a></span>
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Bus.html" title="Bus (module)">Bus</a></span>, <span class='object_link'><a href="IoT.html" title="IoT (module)">IoT</a></span>, <span class='object_link'><a href="RaspberryPi.html" title="RaspberryPi (module)">RaspberryPi</a></span>, <span class='object_link'><a href="RaspberryPiIoT.html" title="RaspberryPiIoT (module)">RaspberryPiIoT</a></span>
|
86
86
|
|
87
87
|
|
88
88
|
|
@@ -102,7 +102,7 @@
|
|
102
102
|
</div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Thu Dec 20 18:09:38 2018 by
|
106
106
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.9.16 (ruby-2.3.3).
|
108
108
|
</div>
|
data/lib/button.rb
CHANGED
@@ -10,31 +10,43 @@ class Button < BinaryReceptor
|
|
10
10
|
@measure_pause = 0.01
|
11
11
|
@long_click = 1.0
|
12
12
|
@short_interval = 0.2
|
13
|
+
@timeout = 30
|
13
14
|
@intervals = []
|
15
|
+
# samples: wait time press time wait time press time
|
16
|
+
# double press: [[1.486804292, 0.090814152], [0.131284967, 0.13125429]]
|
17
|
+
# long press: [[0.910878286, 1.109352219]]
|
14
18
|
end
|
15
19
|
|
16
|
-
# Is button pressed?
|
20
|
+
# Is button being pressed?
|
17
21
|
def pressed?
|
18
22
|
low?
|
19
23
|
end
|
20
24
|
|
21
|
-
# Is button not pressed?
|
25
|
+
# Is button not being pressed?
|
22
26
|
def not_pressed?
|
23
27
|
high?
|
24
28
|
end
|
25
29
|
|
30
|
+
def was_pressed?
|
31
|
+
@intervals.size > 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def was_not_pressed?
|
35
|
+
!was_pressed?
|
36
|
+
end
|
37
|
+
|
26
38
|
# Wait for the 1st pressing of button
|
27
39
|
def wait_for_press
|
28
40
|
wait_for_presses(1)
|
29
41
|
end
|
30
42
|
|
31
43
|
# Wait for several sequential presses
|
32
|
-
def wait_for_presses(attempts=2)
|
44
|
+
def wait_for_presses(attempts=2, timeout=@timeout)
|
33
45
|
@intervals = []
|
34
46
|
attempts.times do
|
35
47
|
interval = []
|
36
48
|
timer = Time.now
|
37
|
-
while not_pressed? do
|
49
|
+
while not_pressed? && (Time.now-timer) < timeout do
|
38
50
|
sleep @measure_pause
|
39
51
|
end
|
40
52
|
interval << Time.now-timer
|
@@ -67,4 +79,16 @@ class Button < BinaryReceptor
|
|
67
79
|
def long_press?(intervals=@intervals)
|
68
80
|
intervals.size == 1 && intervals[0][1] >= @long_click
|
69
81
|
end
|
82
|
+
|
83
|
+
def set_timeout(timeout)
|
84
|
+
@timeout = timeout
|
85
|
+
end
|
86
|
+
|
87
|
+
def timeout?
|
88
|
+
min_wait_time = 0.0
|
89
|
+
@intervals.each do |interval|
|
90
|
+
min_wait_time = [min_wait_time, interval[0]].min
|
91
|
+
end
|
92
|
+
min_wait_time > @timeout
|
93
|
+
end
|
70
94
|
end
|
data/lib/digital_effector.rb
CHANGED
@@ -9,13 +9,13 @@ class DigitalEffector < Effector
|
|
9
9
|
@pins = {} # GPIO pins
|
10
10
|
|
11
11
|
def initialize(pins, state=:low)
|
12
|
-
@states = {}
|
13
|
-
@pins = pins
|
12
|
+
@states = {} # ON / Off states for pin numbers
|
13
|
+
@pins = pins # DigitalEffector.new {red: 17, green: 28, blue: 22}
|
14
14
|
@pins.each_value do |pin|
|
15
15
|
RPi::GPIO.setup pin, :as => :output, :initialize => state
|
16
16
|
@states[pin] = (state == :high)
|
17
17
|
end
|
18
|
-
@pin = pins.values[0]
|
18
|
+
@pin = pins.values[0] # default pin
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.on(pin=@pin)
|
@@ -27,23 +27,17 @@ class DigitalEffector < Effector
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def on(pin=@pin)
|
30
|
-
|
31
|
-
@states[pin] = true
|
30
|
+
DigitalEffector.on pin
|
31
|
+
@states[pin_number(pin)] = true
|
32
32
|
end
|
33
33
|
|
34
34
|
def off(pin=@pin)
|
35
|
-
|
36
|
-
@states[pin] = false
|
35
|
+
DigitalEffector.off pin
|
36
|
+
@states[pin_number(pin)] = false
|
37
37
|
end
|
38
38
|
|
39
39
|
def on?(pin=@pin)
|
40
|
-
|
41
|
-
if pin.class.name == 'Fixnum' # by number
|
42
|
-
state = @states[pin]
|
43
|
-
elsif @pins[pin] # by name
|
44
|
-
state = @states[@pins[pin]]
|
45
|
-
end
|
46
|
-
state
|
40
|
+
@states[pin_number(pin)]
|
47
41
|
end
|
48
42
|
|
49
43
|
def off?(pin=@pin)
|
data/lib/led.rb
CHANGED
@@ -7,10 +7,12 @@ class LED < BinaryEffector
|
|
7
7
|
self.name = 'LED'
|
8
8
|
end
|
9
9
|
|
10
|
+
# Turn on the LED.
|
10
11
|
def on(pin=@pin)
|
11
12
|
super(pin)
|
12
13
|
end
|
13
14
|
|
15
|
+
# Turn off the LED.
|
14
16
|
def off(pin=@pin)
|
15
17
|
super(pin)
|
16
18
|
end
|
@@ -25,12 +27,14 @@ class LED < BinaryEffector
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
30
|
+
# Turn the LED on for N seconds.
|
28
31
|
def on_for(seconds=1)
|
29
32
|
on
|
30
33
|
sleep seconds
|
31
34
|
off
|
32
35
|
end
|
33
36
|
|
37
|
+
# Turn the LED off for N seconds.
|
34
38
|
def off_for(seconds=1)
|
35
39
|
off
|
36
40
|
sleep seconds
|
data/lib/led_rgb.rb
CHANGED
@@ -14,45 +14,25 @@ class LED
|
|
14
14
|
self.name = 'RGB LED'
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
DigitalEffector.on @red
|
19
|
-
end
|
20
|
-
|
21
|
-
def red_off
|
22
|
-
DigitalEffector.off @red
|
23
|
-
end
|
24
|
-
|
25
|
-
def green_on
|
26
|
-
DigitalEffector.on @green
|
27
|
-
end
|
28
|
-
|
29
|
-
def green_off
|
30
|
-
DigitalEffector.off @green
|
31
|
-
end
|
32
|
-
|
33
|
-
def blue_on
|
34
|
-
DigitalEffector.on @blue
|
35
|
-
end
|
36
|
-
|
37
|
-
def blue_off
|
38
|
-
DigitalEffector.off @blue
|
39
|
-
end
|
40
|
-
|
41
|
-
def on(color)
|
17
|
+
def on(color=:all)
|
42
18
|
color = :aoi if color == :aqua
|
43
19
|
case color
|
44
20
|
when :red
|
45
|
-
|
21
|
+
super @red
|
46
22
|
when :green
|
47
|
-
|
23
|
+
super @green
|
48
24
|
when :blue
|
49
|
-
|
25
|
+
super @blue
|
50
26
|
when :yellow
|
51
|
-
|
52
|
-
|
27
|
+
super @red
|
28
|
+
super @green
|
53
29
|
when :aoi
|
54
|
-
|
55
|
-
|
30
|
+
super @blue
|
31
|
+
super @green
|
32
|
+
when :all
|
33
|
+
super @red
|
34
|
+
super @green
|
35
|
+
super @blue
|
56
36
|
else
|
57
37
|
end
|
58
38
|
end
|
@@ -61,30 +41,33 @@ class LED
|
|
61
41
|
color = :aoi if color == :aqua
|
62
42
|
case color
|
63
43
|
when :red
|
64
|
-
|
44
|
+
super @red
|
65
45
|
when :green
|
66
|
-
|
46
|
+
super @green
|
67
47
|
when :blue
|
68
|
-
|
48
|
+
super @blue
|
69
49
|
when :yellow
|
70
|
-
|
71
|
-
|
50
|
+
super @red
|
51
|
+
super @green
|
72
52
|
when :aoi
|
73
|
-
|
74
|
-
|
53
|
+
super @blue
|
54
|
+
super @green
|
75
55
|
when :all
|
76
|
-
|
56
|
+
super @red
|
57
|
+
super @green
|
58
|
+
super @blue
|
77
59
|
else
|
78
60
|
all_off
|
79
61
|
end
|
80
62
|
end
|
81
63
|
|
82
|
-
def
|
83
|
-
|
84
|
-
green_off
|
85
|
-
blue_off
|
64
|
+
def all_on
|
65
|
+
on :all
|
86
66
|
end
|
87
67
|
|
68
|
+
def all_off
|
69
|
+
off :all
|
70
|
+
end
|
88
71
|
|
89
72
|
def blink(list = :all, repeat=3, switched_on=0.25, switched_off=0.5)
|
90
73
|
colors = (list == :all) ? [:red, :green, :blue] : (list.class == Array ? list : [list])
|
data/lib/raspberry_pi_iot.rb
CHANGED
data/test/test_button.rb
CHANGED
@@ -10,12 +10,16 @@ class RaspberryPiIoT_ButtonTest < MiniTest::Test
|
|
10
10
|
def setup
|
11
11
|
@pin = 21
|
12
12
|
@button = Button.new(@pin)
|
13
|
+
@button.set_timeout 10
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_wait_for_press
|
17
|
+
assert @button.not_pressed?
|
18
|
+
assert @button.was_not_pressed?
|
16
19
|
printf "Waiting for press...\n"
|
17
20
|
@button.wait_for_press
|
18
|
-
assert @button.
|
21
|
+
assert @button.was_pressed? if !@button.timeout?
|
22
|
+
|
19
23
|
end
|
20
24
|
|
21
25
|
|
@@ -27,9 +31,10 @@ class RaspberryPiIoT_ButtonTest < MiniTest::Test
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def test_wait_for_long_press
|
30
|
-
printf "Waiting for 1 long press...\n"
|
34
|
+
printf "Waiting for 1 long press (> 1 second)...\n"
|
31
35
|
@button.wait_for_press
|
32
|
-
assert
|
36
|
+
assert @button.single_press?
|
37
|
+
assert !@button.double_press?
|
33
38
|
assert @button.long_press?
|
34
39
|
end
|
35
40
|
|
@@ -37,5 +42,6 @@ class RaspberryPiIoT_ButtonTest < MiniTest::Test
|
|
37
42
|
printf "Waiting for double press...\n", p
|
38
43
|
@button.wait_for_presses 2
|
39
44
|
assert @button.double_press?
|
45
|
+
assert !@button.single_press?
|
40
46
|
end
|
41
47
|
end
|
data/test/test_helper.rb
ADDED
data/test/test_led.rb
CHANGED
@@ -35,11 +35,11 @@ class RaspberryPiIoT_LedTest < Minitest::Test
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_sos
|
38
|
+
3.times { @led.on_for(0.25); @led.off_for(0.25) }
|
39
|
+
sleep 1
|
38
40
|
3.times { @led.on_for(0.5); @led.off_for(0.25) }
|
39
|
-
sleep
|
40
|
-
3.times { @led.on_for(0.
|
41
|
-
sleep 0.5
|
42
|
-
3.times { @led.on_for(0.5); @led.off_for(0.25) }
|
41
|
+
sleep 1
|
42
|
+
3.times { @led.on_for(0.25); @led.off_for(0.25) }
|
43
43
|
sleep 1.5
|
44
44
|
@led.off
|
45
45
|
end
|
data/test/test_led_rgb.rb
CHANGED
@@ -17,20 +17,41 @@ class RaspberryPiIoT_LedRgbTest < Minitest::Test
|
|
17
17
|
|
18
18
|
def test_red
|
19
19
|
@rgb.on :red
|
20
|
+
assert @rgb.on? :red
|
20
21
|
sleep @time_on
|
21
22
|
@rgb.off
|
23
|
+
assert @rgb.off? :red
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_green
|
25
27
|
@rgb.on :green
|
28
|
+
assert @rgb.on? :green
|
26
29
|
sleep @time_on
|
27
30
|
@rgb.off
|
31
|
+
assert @rgb.off? :green
|
28
32
|
end
|
29
33
|
|
30
34
|
def test_blue
|
31
35
|
@rgb.on :blue
|
36
|
+
assert @rgb.on? :blue
|
32
37
|
sleep @time_on
|
33
38
|
@rgb.off
|
39
|
+
assert @rgb.off? :blue
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_all_on
|
43
|
+
@rgb.on :all
|
44
|
+
assert @rgb.on? :red
|
45
|
+
assert @rgb.on? :green
|
46
|
+
assert @rgb.on? :blue
|
47
|
+
sleep @time_on
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_all_off
|
51
|
+
@rgb.off :all
|
52
|
+
assert @rgb.off? :red
|
53
|
+
assert @rgb.off? :green
|
54
|
+
assert @rgb.off? :blue
|
34
55
|
end
|
35
56
|
|
36
57
|
def test_colors
|
@@ -53,10 +74,12 @@ class RaspberryPiIoT_LedRgbTest < Minitest::Test
|
|
53
74
|
end
|
54
75
|
|
55
76
|
def test_sos
|
56
|
-
@rgb.blink :red, 3, 0.25, 0.
|
77
|
+
@rgb.blink :red, 3, 0.25, 0.25
|
57
78
|
sleep 1
|
58
79
|
@rgb.blink :red, 3, 0.5, 0.5
|
59
80
|
sleep 1
|
60
|
-
@rgb.blink :red, 3, 0.25, 0.
|
81
|
+
@rgb.blink :red, 3, 0.25, 0.25
|
82
|
+
assert @rgb.off?
|
83
|
+
sleep 1
|
61
84
|
end
|
62
85
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
$LOAD_PATH << "../lib"
|
6
|
+
require "thermal_sensor"
|
7
|
+
|
8
|
+
class RaspberryPiIoT_ThermalSensorTest < MiniTest::Test
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@sensor = RaspberryPi::ThermalSensor.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sensor_value
|
15
|
+
c = @sensor.celsius
|
16
|
+
assert c > 15.0
|
17
|
+
|
18
|
+
r = @sensor.reaumur
|
19
|
+
assert r < c
|
20
|
+
|
21
|
+
f = @sensor.fahrenheit
|
22
|
+
assert f > c
|
23
|
+
|
24
|
+
k = @sensor.kelvin
|
25
|
+
assert k > f
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raspberry_pi_iot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Shock (Mikhail V. Shokhirev)
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.16
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.16
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: rpi_gpio
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,11 +199,13 @@ files:
|
|
143
199
|
- doc/LED.html
|
144
200
|
- doc/MAX44009.html
|
145
201
|
- doc/RaspberryPi.html
|
202
|
+
- doc/RaspberryPiIoT.html
|
146
203
|
- doc/Receptor.html
|
147
204
|
- doc/Sensor.html
|
148
205
|
- doc/TemperatureSensor.html
|
149
206
|
- doc/_index.html
|
150
207
|
- doc/class_list.html
|
208
|
+
- doc/file.LICENSE.html
|
151
209
|
- doc/file.README.html
|
152
210
|
- doc/file_list.html
|
153
211
|
- doc/frames.html
|
@@ -182,18 +240,25 @@ files:
|
|
182
240
|
- lib/temperature_sensor.rb
|
183
241
|
- lib/thermal_sensor.rb
|
184
242
|
- test/standalone_test_bmp280.rb
|
243
|
+
- test/test_Raspberry_Pi_IoT.rb
|
185
244
|
- test/test_bh1750.rb
|
186
245
|
- test/test_button.rb
|
187
246
|
- test/test_dht11.rb
|
188
247
|
- test/test_ds18b20.rb
|
248
|
+
- test/test_helper.rb
|
189
249
|
- test/test_info.rb
|
190
250
|
- test/test_led.rb
|
191
251
|
- test/test_led_rgb.rb
|
192
252
|
- test/test_max44009_gy49.rb
|
253
|
+
- test/test_thermal.rb
|
193
254
|
homepage: https://github.com/mike-shock/Ruby-Raspberry_Pi_IoT/
|
194
255
|
licenses:
|
195
256
|
- MIT
|
196
|
-
metadata:
|
257
|
+
metadata:
|
258
|
+
allowed_push_host: https://rubygems.org
|
259
|
+
homepage_uri: https://github.com/mike-shock/Ruby-Raspberry_Pi_IoT/
|
260
|
+
source_code_uri: 'TODO: Put your gem''s public repo URL here.'
|
261
|
+
changelog_uri: 'TODO: Put your gem''s CHANGELOG.md URL here.'
|
197
262
|
post_install_message:
|
198
263
|
rdoc_options: []
|
199
264
|
require_paths:
|