leap-motion-ws 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +1 -0
- data/README.rdoc +65 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/leap-motion-ws.gemspec +29 -0
- data/lib/leap-motion-ws.rb +1 -0
- data/lib/leap/motion/utils/ring.rb +19 -0
- data/lib/leap/motion/ws.rb +58 -0
- data/lib/leap/motion/ws/frame.rb +24 -0
- data/lib/leap/motion/ws/gesture.rb +25 -0
- data/lib/leap/motion/ws/hand.rb +25 -0
- data/lib/leap/motion/ws/pointable.rb +25 -0
- data/samples/itunes_controller.rb +141 -0
- data/samples/motion_ws_sample.rb +38 -0
- data/samples/ring_sample.rb +19 -0
- data/samples/rock_paper_scissors.rb +66 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad2f348b76ec5ba36959631f0358b128a2501d6a
|
4
|
+
data.tar.gz: 138cf8fac6634bcce856f07b344cefb2d576d556
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b93617d0af9307fc94903677f85aade0b54fae4e26e969ebf98aa556dca609b8aee1ec98b02d4980ed01ba6e3da17652cae102f42f13fa75cf9215b6cc3384bb
|
7
|
+
data.tar.gz: 751881faa2cc40ae20ba740aeb44659aad1c65b3312c25e7866a64cb53ada4c833cc67c5429d7d30f4b7d62b10d25831b424e2b90cf6f00d00c8070ba974cbb4
|
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# For MacOS:
|
18
|
+
.DS_Store
|
19
|
+
.rake_tasks
|
20
|
+
|
21
|
+
# For ext
|
22
|
+
Makefile
|
23
|
+
ext/config.h
|
24
|
+
*.bundle
|
25
|
+
*.so
|
26
|
+
*.dll
|
27
|
+
*.swp
|
28
|
+
*.log
|
29
|
+
*.o
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
leap-motion-ws (0.0.1)
|
5
|
+
json
|
6
|
+
websocket-eventmachine-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.2.13)
|
12
|
+
i18n (= 0.6.1)
|
13
|
+
multi_json (~> 1.0)
|
14
|
+
bourne (1.4.0)
|
15
|
+
mocha (~> 0.13.2)
|
16
|
+
eventmachine (1.0.3)
|
17
|
+
i18n (0.6.1)
|
18
|
+
json (1.7.7)
|
19
|
+
metaclass (0.0.1)
|
20
|
+
mocha (0.13.3)
|
21
|
+
metaclass (~> 0.0.1)
|
22
|
+
multi_json (1.7.3)
|
23
|
+
rake (10.0.4)
|
24
|
+
rdoc (4.0.1)
|
25
|
+
json (~> 1.4)
|
26
|
+
shoulda (3.4.0)
|
27
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
28
|
+
shoulda-matchers (~> 1.0, >= 1.4.1)
|
29
|
+
shoulda-context (1.1.1)
|
30
|
+
shoulda-matchers (1.5.6)
|
31
|
+
activesupport (>= 3.0.0)
|
32
|
+
bourne (~> 1.3)
|
33
|
+
websocket (1.0.7)
|
34
|
+
websocket-eventmachine-base (1.0.2)
|
35
|
+
eventmachine (~> 1.0)
|
36
|
+
websocket (~> 1.0)
|
37
|
+
websocket-native (~> 1.0)
|
38
|
+
websocket-eventmachine-client (1.0.1)
|
39
|
+
websocket-eventmachine-base (~> 1.0)
|
40
|
+
websocket-native (1.0.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler
|
47
|
+
leap-motion-ws!
|
48
|
+
rake
|
49
|
+
rdoc
|
50
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
BSD
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= leap-motion-ws
|
2
|
+
|
3
|
+
= DESCRIPTION
|
4
|
+
|
5
|
+
Ruby interface to the Leap Motion Controller (via WebSocket)
|
6
|
+
|
7
|
+
If you don't want to use a WebSocket interface, see https://github.com/glejeune/ruby-leap-motion
|
8
|
+
|
9
|
+
= SYNOPSIS
|
10
|
+
|
11
|
+
require 'leap-motion-ws'
|
12
|
+
|
13
|
+
class LeapTest < LEAP::Motion::WS
|
14
|
+
def on_connect
|
15
|
+
puts "Connect"
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_frame frame
|
19
|
+
puts "Frame ##{frame.id}, timestamp: #{frame.timestamp}, hands: #{frame.hands.size}, pointables: #{frame.pointables.size}, gestures: #{frame.gestures.size}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_disconnect
|
23
|
+
puts "disconect"
|
24
|
+
stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
leap = LeapTest.new()
|
29
|
+
leap.start
|
30
|
+
|
31
|
+
= INSTALLATION
|
32
|
+
|
33
|
+
[sudo] gem install leap-motion-ws
|
34
|
+
|
35
|
+
= CONTRIBUTING
|
36
|
+
|
37
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
38
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
39
|
+
* Fork the project
|
40
|
+
* Start a feature/bugfix branch
|
41
|
+
* Commit and push until you are happy with your contribution
|
42
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
44
|
+
|
45
|
+
= LICENCE
|
46
|
+
|
47
|
+
Copyright (c) 2013, Gregoire Lejeune
|
48
|
+
All rights reserved.
|
49
|
+
Redistribution and use in source and binary forms, with or without
|
50
|
+
modification, are permitted provided that the following conditions are met:
|
51
|
+
|
52
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
53
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
54
|
+
* Neither the name of the University of California, Berkeley nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
55
|
+
|
56
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
|
57
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
58
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
59
|
+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
60
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
61
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
62
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
63
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
64
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
65
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rubygems/package_task'
|
6
|
+
require 'rdoc/task'
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |test|
|
9
|
+
test.libs << 'lib' << 'test'
|
10
|
+
test.pattern = 'test/**/test_*.rb'
|
11
|
+
test.verbose = true
|
12
|
+
end
|
13
|
+
task :test => :compile
|
14
|
+
|
15
|
+
task :default => :test
|
16
|
+
|
17
|
+
RDoc::Task.new do |rdoc|
|
18
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
19
|
+
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = "leap-motion-ws #{version}"
|
22
|
+
rdoc.rdoc_files.include('README*')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "leap-motion-ws"
|
5
|
+
s.description = "Ruby interface to the Leap Motion Controller (via WebSocket)"
|
6
|
+
s.summary = "Ruby interface to the Leap Motion Controller (via WebSocket)"
|
7
|
+
|
8
|
+
s.version = open(File.join(File.dirname(__FILE__), "VERSION")).read
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
|
11
|
+
s.authors = ["Gregoire Lejeune"]
|
12
|
+
s.email = "gregoire.lejeune@free.fr"
|
13
|
+
s.homepage = "http://github.com/glejeune/leap-motion-ws"
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
18
|
+
s.extra_rdoc_files = ["LICENSE.txt","README.rdoc"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency("websocket-eventmachine-client")
|
22
|
+
s.add_dependency("json")
|
23
|
+
|
24
|
+
s.add_development_dependency("shoulda")
|
25
|
+
s.add_development_dependency("bundler")
|
26
|
+
s.add_development_dependency("rdoc")
|
27
|
+
s.add_development_dependency("rake")
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'leap/motion/ws'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Ring < Array
|
2
|
+
attr_reader :max_size
|
3
|
+
|
4
|
+
def initialize(max_size, enum = nil)
|
5
|
+
@max_size = max_size
|
6
|
+
enum.each { |e| self << e } if enum
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(el)
|
10
|
+
if self.size < @max_size || @max_size.nil?
|
11
|
+
super
|
12
|
+
else
|
13
|
+
self.shift
|
14
|
+
self.push(el)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
alias :push :<<
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'websocket-eventmachine-client'
|
3
|
+
require 'json'
|
4
|
+
require 'leap/motion/ws/frame'
|
5
|
+
|
6
|
+
module LEAP
|
7
|
+
class Motion
|
8
|
+
class WS
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = {:uri => "ws://127.0.0.1:6437", :enable_gesture => false}.merge(options)
|
11
|
+
@gesture_enables = false
|
12
|
+
@ws = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def gestures?
|
16
|
+
@gesture_enables
|
17
|
+
end
|
18
|
+
|
19
|
+
def gesture!
|
20
|
+
unless @ws.nil?
|
21
|
+
data = JSON "enableGestures" => true
|
22
|
+
@ws.send data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def start(enable_gesture = false)
|
27
|
+
EM.run do
|
28
|
+
@ws = WebSocket::EventMachine::Client.connect(:uri => @options[:uri])
|
29
|
+
|
30
|
+
@ws.onopen do
|
31
|
+
on_connect if respond_to? :on_connect
|
32
|
+
gesture! if enable_gesture or @options[:enable_gesture]
|
33
|
+
end
|
34
|
+
|
35
|
+
@ws.onmessage do |msg, type|
|
36
|
+
message = JSON(msg)
|
37
|
+
if message.key?("id") and message.key?("timestamp")
|
38
|
+
on_frame LEAP::Motion::WS::Frame.new(message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@ws.onerror do |err|
|
43
|
+
on_error(err) if respond_to? :on_error
|
44
|
+
end
|
45
|
+
|
46
|
+
@ws.onclose do
|
47
|
+
on_disconnect if respond_to? :on_disconnect
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def stop
|
53
|
+
EM::stop_event_loop
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'leap/motion/ws/gesture'
|
2
|
+
require 'leap/motion/ws/pointable'
|
3
|
+
require 'leap/motion/ws/hand'
|
4
|
+
|
5
|
+
module LEAP
|
6
|
+
class Motion
|
7
|
+
class WS
|
8
|
+
class Frame
|
9
|
+
attr_reader :gestures, :pointables, :hands, :id, :timestamp, :r, :s, :t
|
10
|
+
def initialize(data)
|
11
|
+
@hands = LEAP::Motion::WS::Hand.list(data)
|
12
|
+
@gestures = LEAP::Motion::WS::Gesture.list(data)
|
13
|
+
@pointables = LEAP::Motion::WS::Pointable.list(data)
|
14
|
+
@id = data["id"]
|
15
|
+
@timestamp = data["timestamp"]
|
16
|
+
@r = data["r"]
|
17
|
+
@s = data["s"]
|
18
|
+
@t = data["t"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LEAP
|
2
|
+
class Motion
|
3
|
+
class WS
|
4
|
+
class Gesture
|
5
|
+
def self.list(data)
|
6
|
+
gestures = []
|
7
|
+
if data["gestures"]
|
8
|
+
data["gestures"].each do |gesture|
|
9
|
+
gestures << LEAP::Motion::WS::Gesture.new(gesture)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
return gestures
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(mid)
|
20
|
+
@data[mid.id2name]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LEAP
|
2
|
+
class Motion
|
3
|
+
class WS
|
4
|
+
class Hand
|
5
|
+
def self.list(data)
|
6
|
+
hands = []
|
7
|
+
if data["hands"]
|
8
|
+
data["hands"].each do |hand|
|
9
|
+
hands << LEAP::Motion::WS::Hand.new(hand)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
return hands
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(mid)
|
20
|
+
@data[mid.id2name]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LEAP
|
2
|
+
class Motion
|
3
|
+
class WS
|
4
|
+
class Pointable
|
5
|
+
def self.list(data)
|
6
|
+
pointables = []
|
7
|
+
if data["pointables"]
|
8
|
+
data["pointables"].each do |pointable|
|
9
|
+
pointables << LEAP::Motion::WS::Pointable.new(pointable)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
return pointables
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(mid)
|
20
|
+
@data[mid.id2name]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift "../lib"
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
begin
|
6
|
+
require 'rubyosa'
|
7
|
+
rescue LoadError
|
8
|
+
puts "Please install rubyosa19"
|
9
|
+
exit 0
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'leap-motion-ws'
|
13
|
+
|
14
|
+
class Track
|
15
|
+
def initialize(itunes)
|
16
|
+
@itunes = itunes
|
17
|
+
@track = nil
|
18
|
+
@change = false
|
19
|
+
track
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
track.name
|
24
|
+
end
|
25
|
+
|
26
|
+
def artist
|
27
|
+
track.artist
|
28
|
+
end
|
29
|
+
|
30
|
+
def album
|
31
|
+
track.album
|
32
|
+
end
|
33
|
+
|
34
|
+
def next
|
35
|
+
@itunes.next_track
|
36
|
+
@change = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def previous
|
40
|
+
@itunes.previous_track
|
41
|
+
@change = true
|
42
|
+
end
|
43
|
+
|
44
|
+
def playpause
|
45
|
+
@itunes.playpause
|
46
|
+
end
|
47
|
+
|
48
|
+
def change?
|
49
|
+
track
|
50
|
+
c = @change
|
51
|
+
@change = false
|
52
|
+
return c
|
53
|
+
end
|
54
|
+
|
55
|
+
def playing?
|
56
|
+
track.enabled?
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
"#{name} by #{artist} - #{album}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def track
|
65
|
+
t = @itunes.current_track
|
66
|
+
if @track.nil? or t.name != @track.name or t.artist != @track.artist or t.album != @track.album
|
67
|
+
@change = true
|
68
|
+
@track = t
|
69
|
+
end
|
70
|
+
return @track
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class ITunesController < LEAP::Motion::WS
|
75
|
+
def initialize
|
76
|
+
@itunes = OSA.app('iTunes')
|
77
|
+
@track = Track.new @itunes
|
78
|
+
|
79
|
+
@last = true
|
80
|
+
@last_time = 0
|
81
|
+
super
|
82
|
+
end
|
83
|
+
|
84
|
+
def on_connect
|
85
|
+
puts "Connect"
|
86
|
+
end
|
87
|
+
|
88
|
+
def on_frame frame
|
89
|
+
if @track.change?
|
90
|
+
puts "Playing : #{@track}"
|
91
|
+
end
|
92
|
+
unless frame.timestamp.nil?
|
93
|
+
delay = frame.timestamp - @last_time
|
94
|
+
if frame.hands.size == 1 and @last and delay > 1100000
|
95
|
+
@last_time = frame.timestamp
|
96
|
+
case frame.pointables.size
|
97
|
+
when 0 then @track.playpause
|
98
|
+
when 2 then @track.next
|
99
|
+
when 4..5 then @track.previous
|
100
|
+
end
|
101
|
+
@last = false
|
102
|
+
elsif frame.hands.size == 0
|
103
|
+
@last = true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def on_disconnect
|
109
|
+
puts "Disconect"
|
110
|
+
stop
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
puts <<EOF
|
115
|
+
itunes_controller - by Grégoire Lejeune
|
116
|
+
|
117
|
+
Usage :
|
118
|
+
|
119
|
+
* 0 finger : play/pause
|
120
|
+
* 2 fingers : next track
|
121
|
+
* 4 (or more) fingers : prevous track
|
122
|
+
|
123
|
+
Enjoy!
|
124
|
+
|
125
|
+
EOF
|
126
|
+
leap = ITunesController.new()
|
127
|
+
|
128
|
+
Signal.trap("TERM") do
|
129
|
+
puts "Terminating..."
|
130
|
+
leap.stop
|
131
|
+
end
|
132
|
+
Signal.trap("KILL") do
|
133
|
+
puts "Terminating..."
|
134
|
+
leap.stop
|
135
|
+
end
|
136
|
+
Signal.trap("INT") do
|
137
|
+
puts "Terminating..."
|
138
|
+
leap.stop
|
139
|
+
end
|
140
|
+
|
141
|
+
leap.start
|
@@ -0,0 +1,38 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
|
3
|
+
require 'leap-motion-ws'
|
4
|
+
|
5
|
+
class LeapTest < LEAP::Motion::WS
|
6
|
+
def on_connect
|
7
|
+
puts "Connect"
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_frame frame
|
11
|
+
puts "Frame ##{frame.id}, timestamp: #{frame.timestamp}, hands: #{frame.hands.size}, pointables: #{frame.pointables.size}"
|
12
|
+
frame.gestures.each do |gesture|
|
13
|
+
puts " -> #{gesture.type} / #{gesture.state}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_disconnect
|
18
|
+
puts "disconect"
|
19
|
+
stop
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
leap = LeapTest.new(:enable_gesture => true)
|
24
|
+
|
25
|
+
Signal.trap("TERM") do
|
26
|
+
puts "Terminating..."
|
27
|
+
leap.stop
|
28
|
+
end
|
29
|
+
Signal.trap("KILL") do
|
30
|
+
puts "Terminating..."
|
31
|
+
leap.stop
|
32
|
+
end
|
33
|
+
Signal.trap("INT") do
|
34
|
+
puts "Terminating..."
|
35
|
+
leap.stop
|
36
|
+
end
|
37
|
+
|
38
|
+
leap.start
|
@@ -0,0 +1,66 @@
|
|
1
|
+
$:.unshift "../lib"
|
2
|
+
|
3
|
+
require 'leap-motion-ws'
|
4
|
+
|
5
|
+
class LeapTest < LEAP::Motion::WS
|
6
|
+
def initialize
|
7
|
+
@last = nil
|
8
|
+
@last_time = 0
|
9
|
+
@elements = ["rock", "paper", "scissors"]
|
10
|
+
@results = [ 0, -1, 1, 1, 0, -1, -1, 1, 0 ]
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def result human, machine
|
15
|
+
@results[(@elements.index(human) * 3) + @elements.index(machine)]
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_connect
|
19
|
+
puts "Connect"
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_frame frame
|
23
|
+
unless frame.timestamp.nil?
|
24
|
+
delay = frame.timestamp - @last_time
|
25
|
+
if frame.hands.size == 1 and @last.nil? and delay > 1100000
|
26
|
+
@last_time = frame.timestamp
|
27
|
+
@last = case frame.pointables.size
|
28
|
+
when 0..1 then "rock"
|
29
|
+
when 2 then "scissors"
|
30
|
+
when 3..5 then "paper"
|
31
|
+
end
|
32
|
+
ia_choise = @elements.sample
|
33
|
+
print "You: #{@last}, Me: #{ia_choise} - "
|
34
|
+
case result(@last, ia_choise)
|
35
|
+
when -1 then puts "I win !"
|
36
|
+
when 1 then puts "You win !"
|
37
|
+
else puts "Draw"
|
38
|
+
end
|
39
|
+
elsif frame.hands.size == 0
|
40
|
+
@last = nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def on_disconnect
|
46
|
+
puts "disconect"
|
47
|
+
stop
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
leap = LeapTest.new()
|
52
|
+
|
53
|
+
Signal.trap("TERM") do
|
54
|
+
puts "Terminating..."
|
55
|
+
leap.stop
|
56
|
+
end
|
57
|
+
Signal.trap("KILL") do
|
58
|
+
puts "Terminating..."
|
59
|
+
leap.stop
|
60
|
+
end
|
61
|
+
Signal.trap("INT") do
|
62
|
+
puts "Terminating..."
|
63
|
+
leap.stop
|
64
|
+
end
|
65
|
+
|
66
|
+
leap.start
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leap-motion-ws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregoire Lejeune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: websocket-eventmachine-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby interface to the Leap Motion Controller (via WebSocket)
|
98
|
+
email: gregoire.lejeune@free.fr
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.rdoc
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- leap-motion-ws.gemspec
|
113
|
+
- lib/leap-motion-ws.rb
|
114
|
+
- lib/leap/motion/utils/ring.rb
|
115
|
+
- lib/leap/motion/ws.rb
|
116
|
+
- lib/leap/motion/ws/frame.rb
|
117
|
+
- lib/leap/motion/ws/gesture.rb
|
118
|
+
- lib/leap/motion/ws/hand.rb
|
119
|
+
- lib/leap/motion/ws/pointable.rb
|
120
|
+
- samples/itunes_controller.rb
|
121
|
+
- samples/motion_ws_sample.rb
|
122
|
+
- samples/ring_sample.rb
|
123
|
+
- samples/rock_paper_scissors.rb
|
124
|
+
homepage: http://github.com/glejeune/leap-motion-ws
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.0.3
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Ruby interface to the Leap Motion Controller (via WebSocket)
|
148
|
+
test_files: []
|