humble_rpi-plugin-button 0.2.0 → 0.3.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: 1255a116c64c496751809f91fa7555d2d509f72e
4
- data.tar.gz: 5f4fd3a1a23cb0ef1a674b3ffea9c64508ca8cfc
3
+ metadata.gz: 4bfe9d964429a76c0064b749de7f9399d98548c2
4
+ data.tar.gz: 10b7836831dee0dfa4d6e0120ca40deedb2dbfa2
5
5
  SHA512:
6
- metadata.gz: b380bd8ce58bd7ce323b8a500efeeb14359d64e4a172690829ae820c5ffa8713091823854472fed28c85fc82347bbb12feeba51024f2d7077668152f17a601de
7
- data.tar.gz: 7b07fcc7559e10ceb43ab5fbc1c96a08e427a45609ceb899f4537fc60451d13f2625754e2eb867f5fbd149fbf41ecb5a613b63860b0d3a658849ebee5a6bcf6e
6
+ metadata.gz: 3b16758a535f22cb2205f42b8902ab2d663aade73afd9f039be1333cc1f33c6d40561957abcec4ddbe0be1b83a99a2b67302bd99943a9465232c58059141b4d6
7
+ data.tar.gz: b528ac8dc1019dd365b7eda0bad1d78cc61e3ff92eb4138380d320c65f2d4ad4d3914904b8fd850ee174321cde82ea15d27e234be4fc4f54c6cf3452b91c40d2
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,66 +3,48 @@
3
3
  # file: humble_rpi-plugin-button.rb
4
4
 
5
5
 
6
- require 'rpi_pinin'
6
+ require 'rpi_pinin_msgout'
7
7
 
8
8
 
9
9
  class HumbleRPiPluginButton
10
10
 
11
11
 
12
- def initialize(settings: {ignore_keyup: true}, variables: {})
13
-
14
- @ignore_keyup = settings[:ignore_keyup] || true
15
- @pins = settings[:pins].map {|x| RPiPinIn.new x, pull: :up}
16
- @notifier = variables[:notifier]
17
- @device_id = variables[:device_id] || 'pi'
12
+ def initialize(settings: {}, variables: {}, verbose: false)
18
13
 
19
- end
20
-
21
- def start()
14
+ pins = settings[:pins]
15
+ settings.delete :pins
22
16
 
23
- notifier = @notifier
24
- device_id = @device_id
17
+ h1 = {
18
+ capture_rate: 0.25, # seconds
19
+ mode: :default
20
+ }.merge settings
21
+
22
+ h2 = {device_id: 'pi'}.merge variables
25
23
 
26
- t0 = Time.now + 1
24
+ h3 = {
25
+ pull: :up,
26
+ subtopic: 'button',
27
+ descriptor: 'pressed',
28
+ verbose: verbose
29
+ }
27
30
 
28
- puts 'ready to detect buttons'
31
+ h = h1.merge(h2).merge(h3)
29
32
 
30
- @pins.each.with_index do |button, i|
33
+ @pins = pins.map.with_index do |x,i|
31
34
 
32
- puts 'button %s on GPIO %s enabled ' % [i+1, button]
33
-
34
- n = (i+1).to_s
35
-
36
- Thread.new do
37
-
38
- button.watch do |value|
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
- state = case value
45
- when 1
46
- @ignore_keyup ? :press : :down
47
- when 0
48
- :up unless @ignore_keyup
49
- end
50
-
51
- if state
52
- notifier.notice "%s/button/%s: key%s" % [device_id, i, state]
53
- end
54
-
55
- t0 = Time.now
56
-
57
- end
58
- end
59
-
60
- end
35
+ RPiPinInMsgOut.new x, h.merge(index: i+1)
61
36
 
62
37
  end
63
-
64
38
 
65
39
  end
40
+
41
+ def start()
42
+
43
+ puts 'ready to detect buttons'
44
+
45
+ @pins.each {|pin| Thread.new { pin.capture} }
46
+
47
+ end
66
48
 
67
49
  alias on_start start
68
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humble_rpi-plugin-button
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,10 +31,10 @@ cert_chain:
31
31
  BpuaDRLyhUfMJfBG+PlWbU2XPeE6pbRnGWCbBwZtUcCzSfwfEehXiw0aZOMCG6Gu
32
32
  OTO58NMjMKNbdQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-04-11 00:00:00.000000000 Z
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.1
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.1
56
56
  description:
57
57
  email: james@r0bertson.co.uk
58
58
  executables: []
metadata.gz.sig CHANGED
Binary file