ruby_hid 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +37 -0
- data/lib/ruby_hid/axis.rb +2 -0
- data/lib/ruby_hid/store.rb +35 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1cf90fc54fd1ef00cade61b8475261c0431c92e
|
4
|
+
data.tar.gz: f0e981ea75d5a796b94a57c032d851a636021b34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac3382ef3c8a2d01924a5e07dae57cec44f21449e6e1b259dc30198df946e340d88c0b450ce6bdf35d190fcd650364d0f262482fcda62dd9769982a97efda2d2
|
7
|
+
data.tar.gz: d0e75d621165fcaccac43348916c0790bf7b0d34f15bb959c985e7477141605f3f520912dfb1d9184e301d4c0310945d082a86bc702ff2cc523874e782efc72e
|
data/README.md
CHANGED
@@ -319,6 +319,43 @@ loop do
|
|
319
319
|
end
|
320
320
|
```
|
321
321
|
|
322
|
+
You can access specific named attribute of the store like so:
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
store.left_x
|
326
|
+
store.left_y
|
327
|
+
store.dpad_x
|
328
|
+
store.dpad_y
|
329
|
+
store.btn_1
|
330
|
+
```
|
331
|
+
|
332
|
+
This returns raw values, as they are returned by the controller.
|
333
|
+
|
334
|
+
You can also access the controller values in a normalised form,
|
335
|
+
where all values range from 0 to 1.
|
336
|
+
|
337
|
+
|
338
|
+
```ruby
|
339
|
+
require 'ruby_hid'
|
340
|
+
|
341
|
+
store = RubyHid::Store.new
|
342
|
+
|
343
|
+
loop do
|
344
|
+
puts store.normalised_hash
|
345
|
+
sleep 0.1
|
346
|
+
end
|
347
|
+
```
|
348
|
+
|
349
|
+
You can access specific normalised attribute of the store like so:
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
store.normalise(:left_x)
|
353
|
+
store.normalise(:left_y)
|
354
|
+
store.normalise(:dpad_x)
|
355
|
+
store.normalise(:dpad_y)
|
356
|
+
store.normalise(:btn_1)
|
357
|
+
```
|
358
|
+
|
322
359
|
Helping Out
|
323
360
|
===========
|
324
361
|
|
data/lib/ruby_hid/axis.rb
CHANGED
data/lib/ruby_hid/store.rb
CHANGED
@@ -10,6 +10,41 @@ module RubyHid
|
|
10
10
|
init_device
|
11
11
|
end
|
12
12
|
|
13
|
+
def normalise(key)
|
14
|
+
value = @table[key]
|
15
|
+
if value
|
16
|
+
if Store.is_button?(key)
|
17
|
+
value
|
18
|
+
else # it's an axis
|
19
|
+
range = Store.value_range(key)
|
20
|
+
(value - range.min).to_f / range.size
|
21
|
+
end
|
22
|
+
else
|
23
|
+
0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def normalised_hash
|
28
|
+
@table.keys.inject({}) do |result, key|
|
29
|
+
result[key] = normalise(key)
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.value_range(key)
|
37
|
+
if Axis::DPAD_KEYS.include?(key)
|
38
|
+
-1...1
|
39
|
+
else
|
40
|
+
0...255
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.is_button?(key)
|
45
|
+
Button::EVENTS.values.include?(key)
|
46
|
+
end
|
47
|
+
|
13
48
|
def init_device
|
14
49
|
if device.nil?
|
15
50
|
self.device = Device.new(
|