humble_rpi-plugin-vibrationsensor 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/humble_rpi-plugin-vibrationsensor.rb +28 -62
- metadata +4 -4
- 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: 5bd0c50d664d3f264d0336a0b1c95107ea56c558
|
4
|
+
data.tar.gz: dd7b4f7d483329729945cd69fa05086803abe8ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12b6f9c1dec8df612fe84c83d16c66e109b4ad5fa613e4a44e7705605335ee80998ca3a5268543d240a22acaee4e736b47d920230186436b8dd24ae564f66b3d
|
7
|
+
data.tar.gz: 66aa951dc5ca11f46bd7634d9444272c19999dd05e3eddb32926892e8a63546eb1f67963c7fdf995a5af85dab4e1b962ebd793a6b8964a7fed44bcdebb43d3ae
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# file: humble_rpi-plugin-vibrationsensor.rb
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'rpi_pinin_msgout'
|
6
6
|
require 'chronic_duration'
|
7
7
|
|
8
8
|
|
@@ -19,75 +19,41 @@ class HumbleRPiPluginVibrationSensor
|
|
19
19
|
|
20
20
|
def initialize(settings: {}, variables: {}, verbose: false)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
@capture_rate = settings[:capture_rate] || 0.25 # seconds
|
25
|
-
@notifier = variables[:notifier]
|
26
|
-
@device_id = variables[:device_id] || 'pi'
|
22
|
+
pins = settings[:pins]
|
23
|
+
settings.delete :pins
|
27
24
|
|
28
|
-
|
25
|
+
h1 = {
|
26
|
+
duration: '5 seconds',
|
27
|
+
capture_rate: 0.25, # seconds
|
28
|
+
mode: :default
|
29
|
+
}.merge settings
|
29
30
|
|
31
|
+
h2 = {device_id: 'pi'}.merge variables
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
notifier = @notifier
|
39
|
-
device_id = @device_id
|
33
|
+
h3 = {
|
34
|
+
pull: :up,
|
35
|
+
subtopic: 'vibration',
|
36
|
+
verbose: verbose
|
37
|
+
}
|
38
|
+
|
39
|
+
h = h1.merge(h2).merge(h3)
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
@pins = pins.map.with_index do |x,i|
|
42
|
+
|
43
|
+
RPiPinInMsgOut.new x, h.merge(index: i)
|
44
|
+
|
45
|
+
end
|
43
46
|
|
47
|
+
end
|
48
|
+
|
49
|
+
def start()
|
50
|
+
|
44
51
|
puts 'ready to detect vibrations'
|
45
52
|
|
46
|
-
@pins.each.
|
47
|
-
|
48
|
-
Thread.new do
|
49
|
-
|
50
|
-
pin.watch_high do
|
51
|
-
|
52
|
-
# ignore any movements that happened 250
|
53
|
-
# milliseconds ago since the last movement
|
54
|
-
if t0 + @capture_rate < Time.now then
|
55
|
-
|
56
|
-
puts Time.now.to_s if @verbose
|
57
|
-
|
58
|
-
count += 1
|
59
|
-
|
60
|
-
elapsed = Time.now - (t1 + duration)
|
61
|
-
#puts 'elapsed : ' + elapsed.inspect
|
53
|
+
@pins.each {|pin| Thread.new { pin.capture_high } }
|
62
54
|
|
63
|
-
if elapsed > 0 then
|
64
|
-
|
65
|
-
# identify if the movement is consecutive
|
66
|
-
msg = if elapsed < duration then
|
67
|
-
s = ChronicDuration.output(duration, :format => :long)
|
68
|
-
"%s/vibration/%s: detected %s times within the past %s" \
|
69
|
-
% [device_id, i, count, s ]
|
70
|
-
else
|
71
|
-
"%s/vibration/%s: detected" % [device_id, i]
|
72
|
-
end
|
73
|
-
|
74
|
-
notifier.notice msg
|
75
|
-
t1 = Time.now
|
76
|
-
count = 0
|
77
|
-
end
|
78
|
-
|
79
|
-
t0 = Time.now
|
80
|
-
else
|
81
|
-
#puts 'ignoring ...'
|
82
|
-
end
|
83
|
-
|
84
|
-
end #/ watch_high
|
85
|
-
end #/ thread
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
55
|
end
|
90
56
|
|
91
|
-
alias on_start start
|
57
|
+
alias on_start start
|
92
58
|
|
93
|
-
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humble_rpi-plugin-vibrationsensor
|
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
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
date: 2016-04-18 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: rpi_pinin_msgout
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
version: '0.1'
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.1.
|
45
|
+
version: 0.1.0
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
version: '0.1'
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.1.
|
55
|
+
version: 0.1.0
|
56
56
|
description:
|
57
57
|
email: james@r0bertson.co.uk
|
58
58
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|