myfirmata 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51d5b3bb9b79c6b103c29d74f10749d783fccdb1
4
+ data.tar.gz: 7e712e6c120ef889acdaafc16d2e5d89bfe68470
5
+ SHA512:
6
+ metadata.gz: 550e2e2eb181af720e2264c86b1e968d0fd21d93bba888540637e5d09c3dc886c082ef0803162b90e4510faa7197eee5eb1c2007827fd25e97353c5faeb2eeaf
7
+ data.tar.gz: 6a91cc2d4055614a9e65f1e6802197a7d0a76f989136e7eed62b7b65693e65e05192c07cbd16d9e946be10c631c3d11fdfd0ef429bd4729fbbd911f9868d118f
@@ -0,0 +1,3 @@
1
+ �!��U��n��s��RG������+�S`ƹ��"2�K�`�-rT��$���NU�;y�%2��-5&ۯ��j��1�0]��Ì�{�Yڗ���$n��⛩�Xg�C�D�����1 ����Qü�<�� ,p��3U�
2
+ ����
3
+ c�j���_R��s{׀���f��*%�Y*
@@ -0,0 +1,2 @@
1
+ �!��%H�z�L�oЙa���eN����"� �)�"F�� �mK{�;fb@+�P=F*0C��)��\�`�B�
2
+ �Ҝ"�e��ʠ���@O2��H%�]��
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: myfirmata.rb
4
+
5
+ require 'sps-sub'
6
+ require 'arduino_firmata'
7
+
8
+
9
+
10
+
11
+ Thread.abort_on_exception=true
12
+
13
+ class DummyNotifier
14
+
15
+ def notice(message)
16
+ puts Time.now.to_s + ' - ' + message
17
+ end
18
+
19
+ end
20
+
21
+ class MyFirmata
22
+
23
+ def initialize(device_name: Socket.gethostname, sps_address: nil,
24
+ sps_port: 59000, plugins: {}, basetopic: 'MyFirmata')
25
+
26
+ @arduino = ArduinoFirmata.connect # use default arduino
27
+
28
+ @basetopic = basetopic
29
+ @device_name, @sps_address, @sps_port = device_name, sps_address, sps_port
30
+
31
+ if sps_address then
32
+ @publisher = @subscriber = SPSSub.new address: @sps_address,
33
+ port: @sps_port, callback: self
34
+ else
35
+ @publisher = DummyNotifier.new
36
+ end
37
+
38
+ @plugins = initialize_plugins(plugins || [])
39
+
40
+ at_exit do
41
+
42
+ @plugins.each do |x|
43
+ if x.respond_to? :on_exit then
44
+ puts 'stopping ' + x.inspect
45
+ Thread.new { x.on_exit() }
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ # triggered from a sps-sub callback
54
+ #
55
+ def ontopic(topic, msg)
56
+
57
+ component = topic[/\w+$/]
58
+
59
+ method_name = "on_#{component}_message".to_sym
60
+
61
+ @plugins.each do |x|
62
+
63
+ if x.respond_to? method_name then
64
+ x.method(method_name).call(msg)
65
+ end
66
+
67
+ end
68
+ end
69
+
70
+ def start()
71
+
72
+ @plugins.each do |x|
73
+
74
+ if x.respond_to? :on_start then
75
+
76
+ Thread.new do
77
+
78
+ x.on_start()
79
+
80
+ end.join
81
+
82
+ end
83
+ end
84
+
85
+ if @subscriber then
86
+
87
+ subtopics = %w(output do)
88
+ topics = subtopics\
89
+ .map {|x| "%s/%s/%s/#" % [@basetopic, @device_name, x]}.join(' | ')
90
+ @subscriber.subscribe topic: topics
91
+
92
+ else
93
+ loop while true
94
+ end
95
+
96
+ end
97
+
98
+
99
+ private
100
+
101
+
102
+ def initialize_plugins(plugins)
103
+
104
+ @plugins = plugins.inject([]) do |r, plugin|
105
+
106
+ name, settings = plugin
107
+ return r if settings[:active] == false and !settings[:active]
108
+
109
+ klass_name = @basetopic + 'Plugin' + name.to_s
110
+
111
+ device_id = "%s/%s" % [@basetopic, @device_name]
112
+ vars = {device_id: device_id, notifier: @publisher}
113
+
114
+ r << Kernel.const_get(klass_name)\
115
+ .new(@arduino, settings: settings, variables: vars)
116
+ def r.to_s()
117
+ klass_name
118
+ end
119
+
120
+ r
121
+ end
122
+ end
123
+
124
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myfirmata
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
+ 8ixkARkWAmV1MB4XDTE3MDIwNDE2NDkxOFoXDTE4MDIwNDE2NDkxOFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBALOoYMQkwdK6lT/5KAIFc9FS6oBQ0wWYgXugoMZ+kC0Exc+QmPOXXj5JoFI5
19
+ +wna5HAtnzKissZ7KK3PwnOqsq3XuCWuRsKD9pZr4429u8veve9ssMO4ofZXWUbf
20
+ rVVY7KQu0kNoje8/C383JpM2Rg1pQtVsNiEyTklEIlqggyTS/C1kQEEJNcQjXa5R
21
+ YauxDFcLFZRtwvlICgGpO9i/SQZCmOs8zk5X5B8YPPGUe9QXAbfRa8PM5P/6P9mB
22
+ TGLS3tUEXXn7yzaSCAfXr7pCDJgqtivdjtRzoDYMugw8uy3WbvYCihKB5RvFsoTn
23
+ h3mmhi6wkL/SAb4RFt83F68ZtWsCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUnWY1WYLhsA4Q3SPUnBY4/tHQstgwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAqJHAUf3T
27
+ wuwkMO3u2XZl1MSIY80wMhnMotSNyrSBODpF4eZCoPPlK67MJQZ+ajhUbdkwCkjM
28
+ T+DgT/gGSBBVZ7TZngT5nWBEia7TxXYcHcD1TUc6uIYCPtL8WcCecksZ3hLsaEtb
29
+ zrJc77JrTehHtgw7gFz9ruqwYENKnAJQgfYGdqKe//aGle2K3pHZEL+DaqeAfN6e
30
+ Oz/A7kgKDdqhzyuGZycXl0HOAZypGOqUHZN1jS8bRniTLMNtzp9nDItkqWxmXSBz
31
+ LroV3/aqM4X9Qj5qyaIOfdIYDF1P516Swyt0w1Wbm0khBvQPNJKYJSW50OqEteTM
32
+ kMJN7MsgKMX6cA==
33
+ -----END CERTIFICATE-----
34
+ date: 2017-02-04 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: sps-sub
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.3'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.3
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.3'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.3.3
56
+ - !ruby/object:Gem::Dependency
57
+ name: arduino_firmata
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.3'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.3.7
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.3'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.7
76
+ description:
77
+ email: james@jamesrobertson.eu
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/myfirmata.rb
83
+ homepage: https://github.com/jrobertson/myfirmata
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.6.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: The MyFirmata gem uses the ArduinoFirmata gem to trigger messages and listen
107
+ for actionable messages using the SimplePubSub messaging system
108
+ test_files: []
Binary file