leapmotion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a7745b555b8eee26548bb59ad793ea27597171f
4
- data.tar.gz: 9fe17f8b3a625be013e5ba1ee7bec776302a2cc7
3
+ metadata.gz: 35139984cdd09f3f3f8bf67990f7e58347867731
4
+ data.tar.gz: 2841285ba6400c24b521a07c03988c7b01a6e8f4
5
5
  SHA512:
6
- metadata.gz: f0a3519eb71a44a84f01e58e149937beeaa851bb9f03be70af3b856526cff4326cac0005413c2715f926bfa50b1c17d28ec4624429b534e10aae28df0d13895c
7
- data.tar.gz: cae818cf0ec459333b2ed7228d7190467bae747ea90f015a410a131b7cd7006d60b2a1190fc3d456e4f86b4c382427181774dc041b11933ead7942a8b2d695eb
6
+ metadata.gz: 61486825ef5c23d471328e31b33d814b43cc4717c59566eca7f84ea30800fb2ab90d0abe609a0345991ddaf6fa2a8ee393168963c1c8b3e327127fa0f9a25fd9
7
+ data.tar.gz: a0dc82c0ca83c23d35d917ff4596e174e1298fe067f35e7b2ce91e097f7874bd51fcd922d566c504f999124a7ed687613027e9550c36ca1fcb9d9cb1000d49be
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- leapmotion (0.0.1)
4
+ leapmotion (0.0.2)
5
5
  event_emitter
6
6
  hashie
7
7
  json
@@ -13,7 +13,6 @@ GEM
13
13
  event_emitter (0.2.5)
14
14
  hashie (2.0.5)
15
15
  json (1.8.0)
16
- json (1.8.0-java)
17
16
  rake (10.1.0)
18
17
  websocket (1.1.1)
19
18
  websocket-client-simple (0.0.5)
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.2 2013-08-01
2
+
3
+ * LeapMotion.connect :gestures => true
4
+
1
5
  === 0.0.1 2013-08-01
2
6
 
3
7
  * connect and get raw data
data/README.md CHANGED
@@ -23,7 +23,7 @@ Samples
23
23
  Usage
24
24
  -----
25
25
 
26
- ### start "Leap Motion.app"
26
+ ### Start "Leap Motion.app"
27
27
 
28
28
  - `/Applications/Leap Motion.app`
29
29
  - It provides WebSocket API.
@@ -31,7 +31,7 @@ Usage
31
31
  <img src="http://shokai.org/archive/file/31d034b4fa72350a67a94f85a00b83a2.png">
32
32
 
33
33
 
34
- ### run ruby
34
+ ### Run Ruby
35
35
 
36
36
  ```ruby
37
37
  require 'rubygems'
@@ -62,6 +62,21 @@ end
62
62
  leap.wait
63
63
  ```
64
64
 
65
+ ### Gestures
66
+
67
+ ```ruby
68
+ leap = LeapMotion.connect :gestures => true
69
+
70
+ leap.on :gestures do |gestures|
71
+ gestures.each do |g|
72
+ puts g.type
73
+ puts g
74
+ end
75
+ puts "-"*5
76
+ end
77
+
78
+ leap.wait
79
+ ```
65
80
 
66
81
  Contributing
67
82
  ------------
data/lib/leapmotion.rb CHANGED
@@ -4,6 +4,7 @@ require "event_emitter"
4
4
  require "websocket-client-simple"
5
5
 
6
6
  require "leapmotion/version"
7
+ require "leapmotion/options"
7
8
  require "leapmotion/main"
8
9
 
9
10
  module LeapMotion
@@ -1,7 +1,9 @@
1
1
  module LeapMotion
2
- def self.connect(ws_url=nil)
3
- ws_url = "http://localhost:6437" unless ws_url
4
- LeapMotion::Device.new ws_url
2
+ def self.connect(opts={})
3
+ DEFAULT_OPTION.each do |k,v|
4
+ opts[k] = v unless opts.has_key? k
5
+ end
6
+ LeapMotion::Device.new opts
5
7
  end
6
8
 
7
9
  class Data < Hashie::Mash
@@ -10,13 +12,18 @@ module LeapMotion
10
12
  class Device
11
13
  include EventEmitter
12
14
  attr_accessor :version
15
+ attr_reader :options
13
16
 
14
- def initialize(ws_url)
15
- @ws = WebSocket::Client::Simple.connect ws_url
17
+ def initialize(opts)
18
+ @ws = WebSocket::Client::Simple.connect opts[:websocket]
19
+ @options = opts
16
20
  @version = nil
17
21
  this = self
18
22
  @ws.on :message do |msg|
19
23
  data = Data.new JSON.parse msg.data rescue this.emit :error, "JSON parse error"
24
+ if data.has_key? "gestures" and !data.gestures.empty?
25
+ this.emit :gestures, data.gestures
26
+ end
20
27
  if data.has_key? "currentFrameRate"
21
28
  this.emit :data, data
22
29
  elsif data.has_key? "version"
@@ -25,6 +32,10 @@ module LeapMotion
25
32
  end
26
33
 
27
34
  @ws.on :open do
35
+ if this.options[:gestures]
36
+ data = {:enableGestures => true}.to_json
37
+ send data
38
+ end
28
39
  this.emit :connect
29
40
  end
30
41
 
@@ -0,0 +1,6 @@
1
+ module LeapMotion
2
+ DEFAULT_OPTION={
3
+ :websocket => "ws://127.0.0.1:6437",
4
+ :gestures => false
5
+ }
6
+ end
@@ -1,3 +1,3 @@
1
1
  module LeapMotion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/samples/dump.rb CHANGED
@@ -1,7 +1,8 @@
1
+ require 'rubygems'
1
2
  $:.unshift File.expand_path "../lib", File.dirname(__FILE__)
2
3
  require 'leapmotion'
3
4
 
4
- leap = LeapMotion.connect ARGV.shift
5
+ leap = LeapMotion.connect
5
6
 
6
7
  leap.on :connect do
7
8
  puts "connect"
@@ -13,8 +14,13 @@ leap.on :disconnect do
13
14
  end
14
15
 
15
16
  leap.on :data do |data|
16
- puts "hands #{data.hands.size}"
17
- puts "pointables #{data.pointables.size}"
17
+ puts "hands #{data.hands.size}"
18
+ if data.hands.size > 0
19
+ data.hands.each do |hand|
20
+ puts "sphereRadius #{hand.sphereRadius}"
21
+ end
22
+ end
23
+ puts "pointables #{data.pointables.size}"
18
24
  puts data
19
25
  puts "-"*5
20
26
  end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ $:.unshift File.expand_path "../lib", File.dirname(__FILE__)
3
+ require 'leapmotion'
4
+
5
+ leap = LeapMotion.connect :gestures => true
6
+
7
+ leap.on :connect do
8
+ puts "connect"
9
+ end
10
+
11
+ leap.on :gestures do |gestures|
12
+ gestures.each do |g|
13
+ puts g.type
14
+ puts g
15
+ end
16
+ puts "-"*5
17
+ end
18
+
19
+ leap.on :data do |data|
20
+ # puts data
21
+ end
22
+
23
+ leap.wait
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leapmotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
@@ -111,8 +111,10 @@ files:
111
111
  - leapmotion.gemspec
112
112
  - lib/leapmotion.rb
113
113
  - lib/leapmotion/main.rb
114
+ - lib/leapmotion/options.rb
114
115
  - lib/leapmotion/version.rb
115
116
  - samples/dump.rb
117
+ - samples/gesture.rb
116
118
  homepage: https://github.com/shokai/ruby-leapmotion
117
119
  licenses:
118
120
  - MIT