humble_rpi-plugin-tiltsensor 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aff47e594ecd9956c12ba93f4a04d85092129009
4
- data.tar.gz: de6bdc0bce739d8aab3f9fcea267d82d74807b83
3
+ metadata.gz: cd8c36969c7b828f0f352f02d3551bd9c859b0d8
4
+ data.tar.gz: 5a3611f9c9d7c129d20e58398ab37170ca552eac
5
5
  SHA512:
6
- metadata.gz: 1cba0223130991c9fbfe64c025849ef6e6d28088762ff4a13b485c9a8ff44b2eb40aeaef6bf616ab3cc6b788fa4da595cf80592817c8cec5dd0ecfaaf223e4e4
7
- data.tar.gz: 1ad83f723bafe3a5ecd2fcd3fe42af8ed720c809eafc000338d8c0f7fe88ff9e7e92750fe5aacc64c3ccc93632d0575ed838370e836e91bcf2fc1198b40d4d43
6
+ metadata.gz: 71b8b6b1513cb66d0aee788824fbf6d0d3271ad6d50a6558ae041d45d4dca61ba5b7185bb4c454249fb0235bfca4f9b8bc4b156830c6ac0fccbf50cdd405b806
7
+ data.tar.gz: 1d5cbd7face775deafec53b63a6055d7a76b4a5e53fcb1fdc2ef8619608b74521b9d1a0546c983580af794070999cc15962c03cfff9734141ed3c42f1c93ec7b
@@ -1,3 +1,2 @@
1
- V`�wd�|�(7���5��s��t�=��t���@�s������>�^���Ku˯a���}Dw}���ί
2
- ��넳eW������Z�
3
- V�'�9Xu�u]�S�
1
+ z�ۢ��ä��IuDWĶ[���‚��r����\{f4P�45�^��өZ��LpU,�O�G�[S�'��B�;7sa �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
- L���^(��蟍�Z�K��d�a���-�y� B�` yeF3�4u�����P�q��Y�׵4�PyLϛVK��{g�@����Gr�M�$q��F"
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 'pi_piper'
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
- include PiPiper
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
- 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
44
+
45
+ Thread.new do
46
+
47
+ pin.watch_high do
45
48
 
46
- elapsed = Time.now - (t1 + duration)
47
- #puts 'elapsed : ' + elapsed.inspect
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
- if elapsed > 0 then
58
+ if elapsed > 0 then
50
59
 
51
- # identify if the movement is consecutive
52
- msg = if elapsed < duration then
53
- s = ChronicDuration.output(duration, :format => :long)
54
- "%s/tilt/%s: detected %s times within the past %s" \
55
- % [device_id, i, count, s ]
56
- else
57
- "%s/tilt/%s: detected" % [device_id, i]
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
- notifier.notice msg
61
- t1 = Time.now
62
- count = 0
63
- end
74
+ t0 = Time.now
75
+ else
76
+ #puts 'ignoring ...'
77
+ end
64
78
 
65
- t0 = Time.now
66
- else
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.1.1
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-03-05 00:00:00.000000000 Z
34
+ date: 2016-04-17 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
- name: pi_piper
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.3'
42
+ version: '0.1'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 1.3.2
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.3'
52
+ version: '0.1'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 1.3.2
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