hybridgroup-firmata 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/firmata/board.rb +18 -10
- data/lib/firmata/event.rb +10 -0
- data/lib/firmata/version.rb +1 -1
- data/lib/firmata.rb +2 -1
- metadata +4 -3
data/lib/firmata/board.rb
CHANGED
@@ -82,6 +82,8 @@ module Firmata
|
|
82
82
|
attr_reader :analog_pins
|
83
83
|
# Public: Returns the String firmware name of Arduion.
|
84
84
|
attr_reader :firmware_name
|
85
|
+
# Public: Returns array of any Events returned from
|
86
|
+
attr_reader :async_events
|
85
87
|
|
86
88
|
# Public: Initialize a Board
|
87
89
|
#
|
@@ -100,6 +102,7 @@ module Firmata
|
|
100
102
|
@pins = []
|
101
103
|
@analog_pins = []
|
102
104
|
@connected = false
|
105
|
+
@async_events = []
|
103
106
|
rescue LoadError
|
104
107
|
puts "Please 'gem install hybridgroup-serialport' for serial port support."
|
105
108
|
end
|
@@ -111,6 +114,11 @@ module Firmata
|
|
111
114
|
@connected
|
112
115
|
end
|
113
116
|
|
117
|
+
def event(name, *data)
|
118
|
+
async_events << Event.new(name, *data)
|
119
|
+
emit(name, *data)
|
120
|
+
end
|
121
|
+
|
114
122
|
# Public: Make connection to Arduino.
|
115
123
|
#
|
116
124
|
# Returns Firmata::Board board.
|
@@ -124,7 +132,7 @@ module Firmata
|
|
124
132
|
2.times { |i| toggle_pin_reporting(i) }
|
125
133
|
|
126
134
|
@connected = true
|
127
|
-
|
135
|
+
event('ready')
|
128
136
|
end)
|
129
137
|
query_analog_mapping
|
130
138
|
end)
|
@@ -175,7 +183,7 @@ module Firmata
|
|
175
183
|
when REPORT_VERSION
|
176
184
|
@major_version = bytes.getbyte
|
177
185
|
@minor_version = bytes.getbyte
|
178
|
-
|
186
|
+
event('report_version')
|
179
187
|
|
180
188
|
when ANALOG_MESSAGE_RANGE
|
181
189
|
least_significant_byte = bytes.getbyte
|
@@ -187,8 +195,8 @@ module Firmata
|
|
187
195
|
if analog_pin = analog_pins[pin]
|
188
196
|
pins[analog_pin].value = value
|
189
197
|
|
190
|
-
|
191
|
-
|
198
|
+
event('analog-read', pin, value)
|
199
|
+
event("analog-read-#{pin}", value)
|
192
200
|
end
|
193
201
|
|
194
202
|
when DIGITAL_MESSAGE_RANGE
|
@@ -202,8 +210,8 @@ module Firmata
|
|
202
210
|
if pin = pins[pin_number] and pin.mode == INPUT
|
203
211
|
value = (port_value >> (i & 0x07)) & 0x01
|
204
212
|
pin.value = value
|
205
|
-
|
206
|
-
|
213
|
+
event('digital-read', pin_number, value)
|
214
|
+
event("digital-read-#{pin_number}", value)
|
207
215
|
end
|
208
216
|
end
|
209
217
|
|
@@ -240,7 +248,7 @@ module Firmata
|
|
240
248
|
n ^= 1
|
241
249
|
end
|
242
250
|
|
243
|
-
|
251
|
+
event('capability_query')
|
244
252
|
|
245
253
|
when ANALOG_MAPPING_RESPONSE
|
246
254
|
pin_index = 0
|
@@ -254,7 +262,7 @@ module Firmata
|
|
254
262
|
pin_index += 1
|
255
263
|
end
|
256
264
|
|
257
|
-
|
265
|
+
event('analog_mapping_query')
|
258
266
|
|
259
267
|
when PIN_STATE_RESPONSE
|
260
268
|
pin = pins[current_buffer[2]]
|
@@ -287,11 +295,11 @@ module Firmata
|
|
287
295
|
i2c_reply[:data].push(current_buffer[i,2].pack("CC").unpack("v").first)
|
288
296
|
i += 2
|
289
297
|
end
|
290
|
-
|
298
|
+
event('i2c_reply', i2c_reply)
|
291
299
|
|
292
300
|
when FIRMWARE_QUERY
|
293
301
|
@firmware_name = current_buffer.slice(4, current_buffer.length - 5).reject { |b| b.zero? }.map(&:chr).join
|
294
|
-
|
302
|
+
event('firmware_query')
|
295
303
|
|
296
304
|
else
|
297
305
|
puts 'bad byte'
|
data/lib/firmata/version.rb
CHANGED
data/lib/firmata.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hybridgroup-firmata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- firmata.gemspec
|
62
62
|
- lib/firmata.rb
|
63
63
|
- lib/firmata/board.rb
|
64
|
+
- lib/firmata/event.rb
|
64
65
|
- lib/firmata/version.rb
|
65
66
|
- test/board_test.rb
|
66
67
|
- test/fake_serial_port.rb
|
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
version: '0'
|
85
86
|
requirements: []
|
86
87
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.8.
|
88
|
+
rubygems_version: 1.8.24
|
88
89
|
signing_key:
|
89
90
|
specification_version: 3
|
90
91
|
summary: ''
|