ruby_hid 0.0.0 → 0.0.1

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: aa992e562d3a8c3cf63778551f1343426ffddf5b
4
- data.tar.gz: 3f95ab6dc3e1af2b4eb455011efe18c19d45dae2
3
+ metadata.gz: f77ff9705448676fcba81e4d570be6735fb76e83
4
+ data.tar.gz: b2662f69540b32c1d96b14e7933b3e8501189197
5
5
  SHA512:
6
- metadata.gz: bfcb6375e83f35e706e75d9e681182d78e934ca5885a9891a3bf569014d8d63cfbcc2516e606b21638f4b90faca6080ec5fb7189fdf69ddd066d09ff33f22d01
7
- data.tar.gz: fbc72ad1244eaff5e9d56b4c599b8c820137d0355fe694a52acf9ac230cc71399d1be1ab9030c1c712d21afc206e3c659e34019c349dc9b2a0f22f91becfcd7d
6
+ metadata.gz: f1b5529b242fe09f9e78dcc1b539f9688bb127260d1c2bf78c7478441ed42b9259c9c473c0ef0f7c40741c43db306ad66eb8411f2289fb9c13d020f3d455e62e
7
+ data.tar.gz: 404875e0fa3ffd3e22f599fb8845bda9895725d15a306a378635c6510cd427461947faa65c73fcc6ab4f938450509f45bc7e4e643deb82dca44205ecc9aaf42c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ruby-hid
1
+ ruby_hid
2
2
  ==========
3
3
 
4
4
  A ruby library for observing HID game controllers. Currently supports
@@ -263,7 +263,6 @@ axes as small as possible, and modify a shared object.
263
263
 
264
264
  ```ruby
265
265
  require 'ostruct'
266
- require_relative '../lib/ruby_hid.rb'
267
266
 
268
267
  @cursor = OpenStruct.new(
269
268
  :x => 50.0, :y => 50.0,
@@ -300,6 +299,26 @@ loop do
300
299
  end
301
300
  ```
302
301
 
302
+ The ruby_hid Store
303
+ -----------------
304
+
305
+ Don't want to worry about setting up all those observers? The ruby_hid store
306
+ is an object which, once initialised, holds all of the values from the first
307
+ controller found.
308
+
309
+ This is ruby_hid with all the difficulty taken out.
310
+
311
+ ```ruby
312
+ require 'ruby_hid'
313
+
314
+ store = RubyHid::Store.new
315
+
316
+ loop do
317
+ puts store.to_h
318
+ sleep 0.1
319
+ end
320
+ ```
321
+
303
322
  Helping Out
304
323
  ===========
305
324
 
data/lib/ruby_hid/axis.rb CHANGED
@@ -41,4 +41,4 @@ module RubyHid
41
41
 
42
42
  end
43
43
 
44
- end
44
+ end
@@ -45,4 +45,5 @@ module RubyHid
45
45
  end
46
46
 
47
47
  end
48
- end
48
+
49
+ end
@@ -146,4 +146,5 @@ module RubyHid
146
146
  end
147
147
 
148
148
  end
149
- end
149
+
150
+ end
@@ -171,4 +171,4 @@ module RubyHid
171
171
 
172
172
  end
173
173
 
174
- end
174
+ end
@@ -0,0 +1,37 @@
1
+ module RubyHid
2
+
3
+ class Store < OpenStruct
4
+
5
+ attr_accessor :device
6
+
7
+ def initialize
8
+ super
9
+ init_observers
10
+ init_device
11
+ end
12
+
13
+ def init_device
14
+ if device.nil?
15
+ self.device = Device.new(
16
+ RubyHid::Device.list[0]
17
+ )
18
+ end
19
+ device.start_watching
20
+ end
21
+
22
+ def init_observers
23
+ events = Axis::EVENTS.values + Button::EVENTS.values
24
+ store = self
25
+ events.each do |name|
26
+ send("#{name}=", 0)
27
+ control = Axis.find_by_name(name)
28
+ control ||= Button.find_by_name(name)
29
+ control.add_event(
30
+ lambda {|val| store.send("#{name}=", val)}
31
+ )
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
data/lib/ruby_hid.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  `sudo chmod 777 /sys/class/leds/*/brightness`
2
2
  `sudo chmod 777 /dev/input/event*`
3
3
 
4
+ require 'ostruct'
4
5
  require_relative './ruby_hid/device.rb'
5
6
  require_relative './ruby_hid/observer.rb'
6
7
  require_relative './ruby_hid/button.rb'
7
8
  require_relative './ruby_hid/axis.rb'
9
+ require_relative './ruby_hid/store.rb'
8
10
 
9
11
  RubyHid::Axis.build
10
12
  RubyHid::Button.build
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_hid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Faraday
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: HID device observer library for Ruby applications. Currently only ubuntu
14
14
  Linux distributions.
@@ -24,6 +24,7 @@ files:
24
24
  - lib/ruby_hid/button.rb
25
25
  - lib/ruby_hid/device.rb
26
26
  - lib/ruby_hid/observer.rb
27
+ - lib/ruby_hid/store.rb
27
28
  homepage: https://github.com/AJFaraday/ruby-hid
28
29
  licenses:
29
30
  - MIT