humble_rpi-plugin-tiltsensor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ad589565ec499623c1da73fd764397a991ae93c
4
+ data.tar.gz: c4dcee13ccb0092faa1ef2da54e6aae9c477fe12
5
+ SHA512:
6
+ metadata.gz: 4d91175c6aa019c578ec36583dfadeec65e1984a1b5cab7dc07a5712e7249313d5e32214df9fa61381868f569c1890ac1f495c709432736fec2325d95453f561
7
+ data.tar.gz: 47d988c6a6e4e7e0c7cfd0b2115d781164385eb12d1f7448163f64711641ed7d6f29550f853d4f95ae2cb6a266690682ef322dbb3c3345f0ae2ab7294646511b
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ u�L0n���, �,w���!9àK&|��N@Қ�fǟ%41��MX��d�k����H1Q<s�>�1�<��I�m$�#�S��/Ћ��"�)�d��d5Q�N:�&�p��
2
+ ���2嗛D��D��oSfbE?�Cl�\/9�{��#4��E���c������
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: humble_rpi-plugin-tiltsensor.rb
4
+
5
+ require 'chronic_duration'
6
+ require 'pi_piper'
7
+
8
+
9
+ class HumbleRPiPluginTiltSensor
10
+ include PiPiper
11
+
12
+ def initialize(settings: {}, variables: {})
13
+
14
+ @pins = settings[:pins]
15
+ @duration = settings[:duration] || '1 minute'
16
+ @notifier = variables[:notifier]
17
+ @device_id = variables[:device_id] || 'pi'
18
+
19
+ at_exit { @pins.each {|pin| File.write '/sys/class/gpio/unexport', pin } }
20
+
21
+ end
22
+
23
+ def start()
24
+
25
+ count = 0
26
+
27
+ duration = ChronicDuration.parse(@duration)
28
+ notifier = @notifier
29
+ device_id = @device_id
30
+
31
+ t0 = Time.now + 1
32
+ t1 = Time.now - duration + 10
33
+
34
+ puts 'ready to detect tilting'
35
+
36
+ @pins.each.with_index do |pin, i|
37
+
38
+ PiPiper.watch :pin => pin.to_i, :invert => true do |pin|
39
+
40
+ # ignore any movements that happened 250
41
+ # milliseconds ago since the last movement
42
+ if t0 + 0.25 < Time.now then
43
+
44
+ count += 1
45
+
46
+ elapsed = Time.now - (t1 + duration)
47
+ #puts 'elapsed : ' + elapsed.inspect
48
+
49
+ if elapsed > 0 then
50
+
51
+ # identify if the movement is consecutive
52
+ msg = if elapsed < duration then
53
+ "%s/tilt/%s: detected %s times within the past %s" \
54
+ % [device_id, i, count, duration]
55
+ else
56
+ "%s/tilt/%s: detected" % [device_id, i]
57
+ end
58
+
59
+ notifier.notice msg
60
+ t1 = Time.now
61
+ count = 0
62
+ end
63
+
64
+ t0 = Time.now
65
+ else
66
+ #puts 'ignoring ...'
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ PiPiper.wait
73
+
74
+ end
75
+
76
+ alias on_start start
77
+
78
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: humble_rpi-plugin-tiltsensor
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
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MDMwNTE4NDMxMloXDTE3MDMwNTE4NDMxMlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBALMMMSPVKf8kj0Cj4whcX8d5vgQDpFlbSXx6C+UKLgFb4RtvtrGzC18wb9eS
19
+ 2Lqz2/kGcaWBu6p3DfPgIK2wgQdYIXIgwiKa+FbzFTJJRsBWCMJN9XDtFBP7CC2s
20
+ J0H2n1Vuy/a/HYQwFhEqTUt10bpicS42i38ZAYnP81v7egTwa+dAMFGnhku5jkU7
21
+ 6+744dQXHJyca9TvV6yUOs+fSG2i3JI9P7iKq6MZOvXRYBoSB1+ZGLileshpUC/T
22
+ 2VLHsilv4+gxZruCoW2QWubkguup7MmZZtg7wFO/S7FawQAMqHtPxruBgieatEfz
23
+ 5avaQG5ve882lhg4lyb9l0sLskcCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQU3I8ffHJD4tXDrtcB4zPgYJHd6PYwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAo1T9ybqb
27
+ Tp6Fc6zf0FwlnWE6uooTNulSvl5UtjrtsFgoku71JsyAxrgrtjS0aPSFaY600s+3
28
+ cpjj0kKg2dX6ObrVjq4LE3XQsoJNdxsFnYUTQ0eEbpFudZzWncJCmmHTtAqwOMDV
29
+ cj3CYAgMp+bOXu8mX+rRoB1f53O6Dy4MxVHsKj86yVwDwtwm48Flw7drVcT5UQE0
30
+ Cgy24BaVHLdXIvycuUDbaTEWeg0CKv2YLvz51CEVuSKLV9bD+SvReExSOY5zw3eZ
31
+ t7CK+1PY0XmfNlOx95Su4aiQgQZLwnWE7pURlNFwcC8lD4aw/QLNxBi+m8xnr3Rd
32
+ ETeW21JrQFapKw==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-03-05 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: pi_piper
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.3'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.2
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.3'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.2
56
+ - !ruby/object:Gem::Dependency
57
+ name: chronic_duration
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.10'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.10.6
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.10'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.6
76
+ description:
77
+ email: james@r0bertson.co.uk
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/humble_rpi-plugin-tiltsensor.rb
83
+ homepage: https://github.com/jrobertson/humble_rpi-plugin-tiltsensor
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: A Humble RPi plugin to detect movement using a tilt sensor.
107
+ test_files: []
metadata.gz.sig ADDED
Binary file