myfirmata-plugin-led 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: e8e6d6144fbe8bdf93ddc18eb21698457c5dce8d
4
- data.tar.gz: 66e70c56869a82fe64ab035dcf33b36c84a68872
3
+ metadata.gz: 429de64c9028346d007d6cb1fc209ca30375e123
4
+ data.tar.gz: 4ff2ee1049d47352ee0fb5557a9ce0dacc9e6cb4
5
5
  SHA512:
6
- metadata.gz: 9a3b4e51a09a9462c43a751afc3694d7d158529a5973f60979b7e753b72ae024816f142875f952ffd1a1ff249b077240a37181f205dc89c397277515463690ec
7
- data.tar.gz: e11c75f036a3703dc5c0ff81220beb812c2d36c4ce651d14387829dbbe2b1daca8337061f64a299225f14ef82a22afe36e6dd795029e111c90500b772b671a7f
6
+ metadata.gz: fb5660cc5a9dfe16e577e5b9e8301ce404abc580af543405afe0e7381a2bab99f81ab22c99dda0d26820161c8c1a53a00941ace08ad2c373160a30bd297757e5
7
+ data.tar.gz: 6c795834d939373bd74853cba7a89a1168d5074377c6ebabc58ffd1b92237581cdff35915e255bc4777cba78a133837fe8485310515b0f4e50f12fe36f232971
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- `�`n���gB�`n��N���u'
1
+ �@�g��l�E %��6���$�WV����c�v��� �Bi��۽Sx���Ce��٪z��TrX7��Gz1%�sO�T�q<������
2
+ ���ɾ��1�0T�|�# ��+�Fg���iq��y����"�U�J�V��
@@ -4,10 +4,25 @@
4
4
 
5
5
  # a plugin for the myfirmata gem
6
6
 
7
+ require 'pinx'
8
+
7
9
 
8
10
  class MyFirmataPluginLed
9
11
 
12
+ class Led < PinX
10
13
 
14
+ def initialize(arduino, id)
15
+ super(id)
16
+ @arduino = arduino
17
+ end
18
+
19
+ def set_pin(val)
20
+ super(val)
21
+ @arduino.digital_write @id, val
22
+ end
23
+
24
+ end
25
+
11
26
  def initialize(arduino, settings: {}, variables: {})
12
27
 
13
28
  @arduino = arduino
@@ -29,21 +44,38 @@ class MyFirmataPluginLed
29
44
 
30
45
  def on_led_message(message)
31
46
 
32
- r = message.match(/(\d+)\s*(on|off)/)
47
+ r = message.match(/(\d+)\s*(on|off|blink)\s*([\d\.]+)?(?:\s*duration\s)?([\d\.]+)?/)
33
48
 
34
49
  if r then
35
-
36
- index, state = r.captures
37
- @arduino.digital_write @pins[index.to_i], state == 'on'
38
-
50
+ index, state, seconds, raw_duration = r.captures
51
+ duration = raw_duration ? raw_duration.to_f : nil
52
+
53
+ a = case state
54
+
55
+ when 'on'
56
+ [:on, duration]
57
+
58
+ when 'off'
59
+ [:off]
60
+
61
+ when 'blink'
62
+ seconds = seconds ? seconds.to_f : 0.5
63
+ [:blink, seconds, duration: duration]
64
+ end
65
+
66
+ @led[index.to_i].send(*a)
39
67
  end
40
68
  end
41
69
 
42
70
  def start()
43
-
71
+
72
+ if @pins.any? then
73
+ @led = @pins.map{|x| Led.new @arduino, x}
74
+ end
75
+
44
76
  end
45
77
 
46
78
  alias on_start start
47
79
 
48
80
 
49
- end
81
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myfirmata-plugin-led
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,8 +31,28 @@ cert_chain:
31
31
  hA5TmpepRkzABj64ycUlVOaQDWrrrgDtCitUgrNa9JNyyT+PNkSiwDRC+eXZiQkn
32
32
  pZEM1cvtbpDkMA==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-04-15 00:00:00.000000000 Z
35
- dependencies: []
34
+ date: 2017-05-09 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: pinx
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.0
36
56
  description:
37
57
  email: james@jamesrobertson.eu
38
58
  executables: []
@@ -63,5 +83,5 @@ rubyforge_project:
63
83
  rubygems_version: 2.6.8
64
84
  signing_key:
65
85
  specification_version: 4
66
- summary: myfirmata-plugin-led
86
+ summary: A MyFirmata plugin to control 1 or more LEDs via a SimplePubSub subscription.
67
87
  test_files: []
metadata.gz.sig CHANGED
Binary file