humble_rpi-plugin-vibrationsensor 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 950847ff3067cfde4ad42d65e74e6159865b7038
4
- data.tar.gz: 5922f6a702c3dd9a593d83d4a7fe2f9be6e8c4e4
3
+ metadata.gz: 5bd0c50d664d3f264d0336a0b1c95107ea56c558
4
+ data.tar.gz: dd7b4f7d483329729945cd69fa05086803abe8ad
5
5
  SHA512:
6
- metadata.gz: 8e5eb9d8820cac5d64d20d0f1d7d4c159a1b496fdfa48b77bec17c24ffc3b8c84d81c083023ec1bee6a57ecef254da5a342ac568f024c3863d4c219378156443
7
- data.tar.gz: ff3c84c4cacafbc21212620677e30103bd1121e75f6aed7929196776ea41b7b7923dca6aeaf01fed22b839d2b00aa014e00d867f28976650bef3172210660c60
6
+ metadata.gz: 12b6f9c1dec8df612fe84c83d16c66e109b4ad5fa613e4a44e7705605335ee80998ca3a5268543d240a22acaee4e736b47d920230186436b8dd24ae564f66b3d
7
+ data.tar.gz: 66aa951dc5ca11f46bd7634d9444272c19999dd05e3eddb32926892e8a63546eb1f67963c7fdf995a5af85dab4e1b962ebd793a6b8964a7fed44bcdebb43d3ae
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 'rpi_pinin'
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
- @pins = settings[:pins].map {|x| RPiPinIn.new x, pull: :up}
23
- @duration = settings[:duration] || '5 seconds'
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
- @verbose = verbose
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
- end
32
-
33
- def start()
34
-
35
- count = 0
36
-
37
- duration = ChronicDuration.parse(@duration)
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
- t0 = Time.now + 1
42
- t1 = Time.now - duration + 1
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.with_index do |pin, i|
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.1.1
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: rpi_pinin
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.2
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.2
55
+ version: 0.1.0
56
56
  description:
57
57
  email: james@r0bertson.co.uk
58
58
  executables: []
metadata.gz.sig CHANGED
Binary file