humble_rpi-plugin-tiltsensor 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -3
- data.tar.gz.sig +1 -2
- data/lib/humble_rpi-plugin-tiltsensor.rb +44 -35
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8c36969c7b828f0f352f02d3551bd9c859b0d8
|
4
|
+
data.tar.gz: 5a3611f9c9d7c129d20e58398ab37170ca552eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71b8b6b1513cb66d0aee788824fbf6d0d3271ad6d50a6558ae041d45d4dca61ba5b7185bb4c454249fb0235bfca4f9b8bc4b156830c6ac0fccbf50cdd405b806
|
7
|
+
data.tar.gz: 1d5cbd7face775deafec53b63a6055d7a76b4a5e53fcb1fdc2ef8619608b74521b9d1a0546c983580af794070999cc15962c03cfff9734141ed3c42f1c93ec7b
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
�
|
2
|
-
|
3
|
-
V�'�9Xu�u]�S�
|
1
|
+
z�ۢ��ä��IuDWĶ[�����r����\{f�4P�45�^��өZ��LpU,�O�G�[S�'��B�;7s�a� �Gx
|
2
|
+
x�����9ʄ�5ySn�"�OZc��M)7�mRV�H��5��Z��A���ݻX.����9;�<��5̊�lC'G��`��h��S��K����tW>�Q!���{a�n���_5���tͦK�ٜH�?��eJUZ��߫��|0$8Pp�H^��Ty��%����~��' �2}��w�
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�ӳ�Z�ԭ���A��
|
1
|
+
��-e���!��My�i��D���(/�I8wT��bF,����X��=�+=Q
|
@@ -3,20 +3,27 @@
|
|
3
3
|
# file: humble_rpi-plugin-tiltsensor.rb
|
4
4
|
|
5
5
|
require 'chronic_duration'
|
6
|
-
require '
|
6
|
+
require 'rpi_pinin'
|
7
7
|
|
8
8
|
|
9
|
+
# Hardware test setup:
|
10
|
+
#
|
11
|
+
# * tilt sensor only connected between a GPIO pin and ground
|
12
|
+
#
|
13
|
+
# Trigger an event
|
14
|
+
#
|
15
|
+
# * To trigger a tilt action either tap the sensor when it is vertical or
|
16
|
+
# tilted at an angle of 45 degrees or more
|
17
|
+
|
9
18
|
class HumbleRPiPluginTiltSensor
|
10
|
-
|
19
|
+
|
11
20
|
|
12
21
|
def initialize(settings: {}, variables: {})
|
13
22
|
|
14
|
-
@pins = settings[:pins]
|
23
|
+
@pins = settings[:pins].map {|x| RPiPinIn.new x}
|
15
24
|
@duration = settings[:duration] || '1 minute'
|
16
25
|
@notifier = variables[:notifier]
|
17
26
|
@device_id = variables[:device_id] || 'pi'
|
18
|
-
|
19
|
-
at_exit { @pins.each {|pin| File.write '/sys/class/gpio/unexport', pin } }
|
20
27
|
|
21
28
|
end
|
22
29
|
|
@@ -34,43 +41,45 @@ class HumbleRPiPluginTiltSensor
|
|
34
41
|
puts 'ready to detect tilting'
|
35
42
|
|
36
43
|
@pins.each.with_index do |pin, i|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# milliseconds ago since the last movement
|
42
|
-
if t0 + 0.25 < Time.now then
|
43
|
-
|
44
|
-
count += 1
|
44
|
+
|
45
|
+
Thread.new do
|
46
|
+
|
47
|
+
pin.watch_high do
|
45
48
|
|
46
|
-
|
47
|
-
#
|
49
|
+
# ignore any movements that happened 250
|
50
|
+
# milliseconds ago since the last movement
|
51
|
+
if t0 + 0.25 < Time.now then
|
52
|
+
|
53
|
+
count += 1
|
54
|
+
|
55
|
+
elapsed = Time.now - (t1 + duration)
|
56
|
+
#puts 'elapsed : ' + elapsed.inspect
|
48
57
|
|
49
|
-
|
58
|
+
if elapsed > 0 then
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
# identify if the movement is consecutive
|
61
|
+
msg = if elapsed < duration then
|
62
|
+
s = ChronicDuration.output(duration, :format => :long)
|
63
|
+
"%s/tilt/%s: detected %s times within the past %s" \
|
64
|
+
% [device_id, i, count, s ]
|
65
|
+
else
|
66
|
+
"%s/tilt/%s: detected" % [device_id, i]
|
67
|
+
end
|
68
|
+
|
69
|
+
notifier.notice msg
|
70
|
+
t1 = Time.now
|
71
|
+
count = 0
|
58
72
|
end
|
59
73
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
74
|
+
t0 = Time.now
|
75
|
+
else
|
76
|
+
#puts 'ignoring ...'
|
77
|
+
end
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
#puts 'ignoring ...'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
79
|
+
end #/ watch_high
|
80
|
+
end #/ thread
|
71
81
|
end
|
72
|
-
|
73
|
-
PiPiper.wait
|
82
|
+
|
74
83
|
|
75
84
|
end
|
76
85
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humble_rpi-plugin-tiltsensor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,28 +31,28 @@ cert_chain:
|
|
31
31
|
t7CK+1PY0XmfNlOx95Su4aiQgQZLwnWE7pURlNFwcC8lD4aw/QLNxBi+m8xnr3Rd
|
32
32
|
ETeW21JrQFapKw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-
|
34
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: rpi_pinin
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1
|
42
|
+
version: '0.1'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 0.1.2
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1
|
52
|
+
version: '0.1'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 0.1.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: chronic_duration
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|