humble_rpi-plugin-button 0.1.0 → 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: 8709377a1a6ea45f2d2020d0952d4373d3c4c6cc
4
- data.tar.gz: 4d3aa845297fe4ad98722c8925a8529844276a6a
3
+ metadata.gz: 1255a116c64c496751809f91fa7555d2d509f72e
4
+ data.tar.gz: 5f4fd3a1a23cb0ef1a674b3ffea9c64508ca8cfc
5
5
  SHA512:
6
- metadata.gz: 09566ad633be79e01162351019f1a0061ebb7eabb20a69a6975ff4c2daa41f8543c7dd53baaeea05ea1e69ffe1d5ce2a1d3b7ec95cecfea52fa86bec573ae2e1
7
- data.tar.gz: 8a29c6949f9ffc35a76d30116a84b0f5e964b268cbc0944e94d795b09000bd48148a742244e4ca535aee8488261c2426c93e8ee1025c971ccd38372cc616bfd7
6
+ metadata.gz: b380bd8ce58bd7ce323b8a500efeeb14359d64e4a172690829ae820c5ffa8713091823854472fed28c85fc82347bbb12feeba51024f2d7077668152f17a601de
7
+ data.tar.gz: 7b07fcc7559e10ceb43ab5fbc1c96a08e427a45609ceb899f4537fc60451d13f2625754e2eb867f5fbd149fbf41ecb5a613b63860b0d3a658849ebee5a6bcf6e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -3,29 +3,18 @@
3
3
  # file: humble_rpi-plugin-button.rb
4
4
 
5
5
 
6
- require 'pi_piper'
6
+ require 'rpi_pinin'
7
7
 
8
8
 
9
9
  class HumbleRPiPluginButton
10
- include PiPiper
11
10
 
12
- def initialize(settings: {}, variables: {})
13
11
 
14
- @pins = settings[:pins]
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}
15
16
  @notifier = variables[:notifier]
16
17
  @device_id = variables[:device_id] || 'pi'
17
-
18
- at_exit do
19
-
20
- @pins.each do |pin|
21
-
22
- uexp = open("/sys/class/gpio/unexport", "w")
23
- uexp.write(pin)
24
- uexp.close
25
-
26
- end
27
- end
28
-
29
18
 
30
19
  end
31
20
 
@@ -33,24 +22,44 @@ class HumbleRPiPluginButton
33
22
 
34
23
  notifier = @notifier
35
24
  device_id = @device_id
25
+
26
+ t0 = Time.now + 1
36
27
 
37
28
  puts 'ready to detect buttons'
38
29
 
39
30
  @pins.each.with_index do |button, i|
40
31
 
41
32
  puts 'button %s on GPIO %s enabled ' % [i+1, button]
42
-
33
+
43
34
  n = (i+1).to_s
44
-
45
- PiPiper.watch :pin => button.to_i, :invert => true do |pin|
35
+
36
+ Thread.new do
46
37
 
47
- notifier.notice "%s/button/%s: value %s" % [device_id, i, pin.value]
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
48
50
 
49
- end
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
50
61
 
51
- end
52
-
53
- PiPiper.wait
62
+ end
54
63
 
55
64
 
56
65
  end
@@ -58,4 +67,4 @@ class HumbleRPiPluginButton
58
67
  alias on_start start
59
68
 
60
69
 
61
- end
70
+ end
data.tar.gz.sig CHANGED
Binary file
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,28 +31,28 @@ cert_chain:
31
31
  BpuaDRLyhUfMJfBG+PlWbU2XPeE6pbRnGWCbBwZtUcCzSfwfEehXiw0aZOMCG6Gu
32
32
  OTO58NMjMKNbdQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-06-14 00:00:00.000000000 Z
34
+ date: 2016-04-11 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
  description:
57
57
  email: james@r0bertson.co.uk
58
58
  executables: []
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.4.6
83
+ rubygems_version: 2.4.8
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: A humble_rpi plugin which detects a button press.
metadata.gz.sig CHANGED
Binary file