humble_rpi-plugin-vibrationsensor 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a54e776f0348083acc6f0b5787b8d67d1639c05
4
+ data.tar.gz: 80bbad5cb91e5c2bec414d3af0cf0b668f7ad84f
5
+ SHA512:
6
+ metadata.gz: 768342954ea2e662e3098c1275a6ba18e9c32d3d8797e606554e07692b8021eeef32cc2b1c218e9bac20e0a076ef84bfd8169b3a8d4cd136e9c2efc9402ddb6f
7
+ data.tar.gz: 7ca5c0961087d23352e458d246c9f87a0dfe36d2a60fc49d52d113a4a25feb95a330d13f8df79e1b8672e6db7f5edff936b963b693688070097d8d3e0077b30a
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ l��l�i�&�t�4�I�-L���!|���7G>���)�P9#�$�����쓗��d4,����[�����c��Lv*l�,�j�͵W�*��E>X�����O��v�$���~a�Aߺ}TFp�R�i��
2
+ ��ՙy���9�K�{!�?g�o?�'�g�*Aֿ��1�p�0P��bB#O��Y�>�F��Hms���#�t1e�u�]�K2E���sw7�a�ה��Z�SY�� G������D R�߷ɰ��
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: humble_rpi-plugin-vibrationsensor.rb
4
+
5
+ require 'rpi_pinin'
6
+ require 'chronic_duration'
7
+
8
+
9
+ # Hardware test setup:
10
+ #
11
+ # * vibration sensor (SW-18010P) only connected between a GPIO pin and ground
12
+ #
13
+ # Trigger an event
14
+ #
15
+ # * To trigger a vibration event, tap the sensor at any angle
16
+
17
+ class HumbleRPiPluginVibrationSensor
18
+
19
+
20
+ def initialize(settings: {}, variables: {}, verbose: false)
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'
27
+
28
+ @verbose = verbose
29
+
30
+
31
+ end
32
+
33
+ def start()
34
+
35
+ count = 0
36
+
37
+ duration = ChronicDuration.parse(@duration)
38
+ notifier = @notifier
39
+ device_id = @device_id
40
+
41
+ t0 = Time.now + 1
42
+ t1 = Time.now - duration + 1
43
+
44
+ puts 'ready to detect vibrations'
45
+
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
62
+
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
+ end
90
+
91
+ alias on_start start
92
+
93
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: humble_rpi-plugin-vibrationsensor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMR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yx2pMQgBPrXMtCSFC7rIl97n4r8qzAHFFdjlkeb9hc7TuLfEEJxHdCq
30
+ Okx18NU0Z6NvKviaoYu1eUPxgbcflYShWPx8sICw1XPW2/xPyyj/5yRX9dUeGZDL
31
+ TAc8Dji0E/4sPmhggncK1MvO3UlGIKbNJ4ewkfkejnDqu2OJ+1WjhH0G00m/4HP2
32
+ TgMiPCBLrv0ppQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-04-18 00:00:00.000000000 Z
35
+ dependencies: []
36
+ description:
37
+ email: james@r0bertson.co.uk
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/humble_rpi-plugin-vibrationsensor.rb
43
+ homepage: https://github.com/jrobertson/humble_rpi-plugin-vibrationsensor
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A Humble RPi plugin which detects vibrations using the vibration sensor (SW-18010P).
67
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �|>��k����ȏY��3� +��;��x)Ca� ��
2
+ D�C�qʳU�7��҃��iwjCu0���ZQN>*��a���@�q���,�S�6Hg/�m�(1��T���\e�Ʀy2��[Ɣ�̵�k����$m=`���
3
+ �� n��R�G