ffi-libfreenect 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/LICENSE.txt +23 -0
- data/README.rdoc +86 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/examples/record.rb +76 -0
- data/examples/tilt_led.rb +105 -0
- data/examples/tilt_nod.rb +28 -0
- data/examples/video_snapshot.rb +61 -0
- data/lib/ffi/freenect.rb +170 -0
- data/lib/freenect.rb +40 -0
- data/lib/freenect/context.rb +66 -0
- data/lib/freenect/device.rb +210 -0
- data/lib/freenect/sync.rb +93 -0
- data/spec/context_spec.rb +61 -0
- data/spec/device_spec.rb +97 -0
- data/spec/freenect_spec.rb +90 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +11 -0
- metadata +113 -0
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Josh Grunzweig & Eric Monti
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
= ffi-libfreenect
|
2
|
+
|
3
|
+
FFI-based Ruby wrapper for the OpenKinect libfreenect library.
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
* ffi >= 0.5.0
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
=== via Gem
|
11
|
+
|
12
|
+
(sudo)? gem install ffi-libfreenect
|
13
|
+
|
14
|
+
=== via Rake
|
15
|
+
|
16
|
+
git clone http://github.com/jgrunzweig/ffi-libfreenect.git
|
17
|
+
cd ffi-libfreenect
|
18
|
+
(sudo)? gem install jeweler
|
19
|
+
rake install
|
20
|
+
|
21
|
+
=== Synopsis
|
22
|
+
|
23
|
+
require 'freenect'
|
24
|
+
|
25
|
+
ctx = Freenect.init()
|
26
|
+
devs = ctx.num_devices
|
27
|
+
|
28
|
+
STDERR.puts "Number of Kinects detected: #{devs}"
|
29
|
+
unless devs > 0
|
30
|
+
STDERR.puts "Error: no kinect detected"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
STDERR.puts "Selecting device 0"
|
35
|
+
dev = ctx.open_device(0)
|
36
|
+
|
37
|
+
dev.set_led(:red) # play with the led
|
38
|
+
dev.set_tilt_degrees(30) # tilt up to max
|
39
|
+
sleep 1
|
40
|
+
dev.set_tilt_degrees(-30) # tilt down to max
|
41
|
+
sleep 1
|
42
|
+
dev.set_tilt_degrees(0.0) # tilt back to center
|
43
|
+
sleep 1
|
44
|
+
dev.set_led(:green) # play with the led
|
45
|
+
|
46
|
+
# Actual video and depth capture work similarly to eachother.
|
47
|
+
# But they're still both pretty un-sugary.
|
48
|
+
#
|
49
|
+
# Future versions will probably abstract this and try to make it more
|
50
|
+
# ruby-ish.
|
51
|
+
#
|
52
|
+
# The example below shows how to write a single video frame to a PPM file.
|
53
|
+
|
54
|
+
dev.set_depth_format(Freenect::DEPTH_11BIT)
|
55
|
+
dev.set_video_format(Freenect::VIDEO_RGB)
|
56
|
+
dev.start_depth()
|
57
|
+
dev.start_video()
|
58
|
+
|
59
|
+
$snapshot_finished = nil
|
60
|
+
|
61
|
+
STDERR.puts "Taking snapshot"
|
62
|
+
dev.set_video_callback do |device, video, timestamp|
|
63
|
+
if not $snapshot_finished
|
64
|
+
fname = "%u.ppm" % timestamp
|
65
|
+
STDERR.puts "Writing #{fname}"
|
66
|
+
File.open(fname, "w") do |f|
|
67
|
+
f.puts("P6 %d %d 255\n" % [ Freenect::FRAME_W, Freenect::FRAME_H ] )
|
68
|
+
f.write(video.read_string_length(Freenect::RGB_SIZE))
|
69
|
+
end
|
70
|
+
$snapshot_finished = true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
until $snapshot_finished
|
75
|
+
break if (ctx.process_events >= 0)
|
76
|
+
end
|
77
|
+
|
78
|
+
dev.set_led(:off)
|
79
|
+
dev.stop_depth
|
80
|
+
dev.stop_video
|
81
|
+
dev.close
|
82
|
+
ctx.close
|
83
|
+
|
84
|
+
== Copyright
|
85
|
+
|
86
|
+
Copyright (c) 2010 Josh Grunzweig & Eric Monti. See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ffi-libfreenect"
|
8
|
+
gem.summary = gem.description = %Q{FFI bindings for the libfreenect OpenKinect library}
|
9
|
+
gem.homepage = "http://github.com/jgrunzweig/ffi-libfreenect"
|
10
|
+
gem.authors = ["Josh Grunzweig", "Eric Monti"]
|
11
|
+
|
12
|
+
gem.rdoc_options += ["--title", "FFI Freenect", "--main", "README.rdoc", "--line-numbers"]
|
13
|
+
gem.add_dependency("ffi", ">= 0.5.0")
|
14
|
+
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'yard'
|
40
|
+
YARD::Rake::YardocTask.new
|
41
|
+
rescue LoadError
|
42
|
+
task :yardoc do
|
43
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
44
|
+
end
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/examples/record.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This is a more or less a straight ruby port of the "record" utility
|
3
|
+
# included in the libfreenect fakenect directory using the
|
4
|
+
# ffi-libfreenect ruby class wrappers.
|
5
|
+
#
|
6
|
+
# This was really implemented just to see if ffi-libfreenect was working.
|
7
|
+
# However, the output should be completely compatible the C version fakenect.
|
8
|
+
#
|
9
|
+
# usage: record.rb output_dir
|
10
|
+
#
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'rubygems'
|
14
|
+
rescue LoadError
|
15
|
+
end
|
16
|
+
|
17
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
18
|
+
require 'freenect'
|
19
|
+
|
20
|
+
$last_timestamp = 0
|
21
|
+
$record_running = true
|
22
|
+
|
23
|
+
def open_dump(type, timestamp, extension)
|
24
|
+
$last_timestamp = timestamp
|
25
|
+
filename = "%s-%f-%u.%s" % [ type, Time.now.to_f, timestamp, extension]
|
26
|
+
STDERR.puts "Writing: #{File.join($out_dir, filename)}"
|
27
|
+
File.open(File.join($out_dir,"INDEX.txt"), "a"){|f| f.puts(filename) }
|
28
|
+
File.open(File.join($out_dir, filename), "wb") {|f| yield f}
|
29
|
+
end
|
30
|
+
|
31
|
+
orig_dir = Dir.pwd
|
32
|
+
unless $out_dir = ARGV.shift
|
33
|
+
STDERR.puts "usage: #{File.basename $0} output_dir"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
Dir.mkdir($out_dir) unless File.directory?($out_dir)
|
37
|
+
|
38
|
+
trap('INT') do
|
39
|
+
STDERR.puts "Caught INT signal cleaning up"
|
40
|
+
$record_running = false
|
41
|
+
end
|
42
|
+
|
43
|
+
ctx = Freenect.init()
|
44
|
+
dev = ctx.open_device(0)
|
45
|
+
|
46
|
+
dev.set_depth_format(Freenect::DEPTH_11BIT)
|
47
|
+
dev.set_video_format(Freenect::VIDEO_RGB)
|
48
|
+
dev.start_depth()
|
49
|
+
dev.start_video()
|
50
|
+
|
51
|
+
dev.set_depth_callback do |device, depth, timestamp|
|
52
|
+
open_dump('d', timestamp, "pgm") do |f|
|
53
|
+
f.puts("P5 %d %d 65535\n" % [ Freenect::FRAME_W, Freenect::FRAME_H ] )
|
54
|
+
f.write(depth.read_string_length(Freenect::DEPTH_11BIT_SIZE))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
dev.set_video_callback do |device, video, timestamp|
|
59
|
+
open_dump('r', timestamp, 'ppm') do |f|
|
60
|
+
f.puts("P6 %d %d 255\n" % [ Freenect::FRAME_W, Freenect::FRAME_H ] )
|
61
|
+
f.write(video.read_string_length(Freenect::RGB_SIZE))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
while $record_running and (ctx.process_events >= 0)
|
66
|
+
open_dump('a', $last_timestamp, "dump") do |f|
|
67
|
+
state = dev.get_tilt_state
|
68
|
+
f.write(state.to_ptr.read_string_length(state.size))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Dir.chdir(orig_dir)
|
73
|
+
dev.stop_depth
|
74
|
+
dev.stop_video
|
75
|
+
dev.close
|
76
|
+
ctx.close
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class TILT_LED
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
|
5
|
+
require 'freenect'
|
6
|
+
check_args
|
7
|
+
initialize_device
|
8
|
+
tilt_led_set
|
9
|
+
cleanup
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Define usage
|
14
|
+
#
|
15
|
+
def script_usage
|
16
|
+
puts "Usage: ruby tilt_led.rb -l (0-6) -t (-30-30)"
|
17
|
+
puts "LED Options:"
|
18
|
+
puts " 0 - Off"
|
19
|
+
puts " 1 - Green"
|
20
|
+
puts " 2 - Red"
|
21
|
+
puts " 3 - Yellow"
|
22
|
+
puts " 4 - Blink Yellow"
|
23
|
+
puts " 5 - Blink Green"
|
24
|
+
puts " 6 - Blink Red/Yellow"
|
25
|
+
puts "Tilt Options:"
|
26
|
+
puts " Value must be between -30 and 30 degrees."
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Check arguments. I'm sure there's a better way to do this. What can I saw, I'm a noob.
|
32
|
+
#
|
33
|
+
def check_args
|
34
|
+
if( ARGV.include?("-l") || ARGV.include?("-t") )
|
35
|
+
if (ARGV.include?("-l"))
|
36
|
+
@led_option = ARGV[(ARGV.index("-l") + 1 )]
|
37
|
+
ARGV.delete("-l")
|
38
|
+
ARGV.delete(@led_option)
|
39
|
+
if @led_option.to_i < 0 || @led_option.to_i > 6
|
40
|
+
script_usage
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if (ARGV.include?("-t"))
|
44
|
+
@tilt_option = ARGV[(ARGV.index("-t") + 1 )]
|
45
|
+
ARGV.delete("-t")
|
46
|
+
ARGV.delete(@tilt_option)
|
47
|
+
if @tilt_option.to_i < -30 || @tilt_option.to_i > 30
|
48
|
+
script_usage
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
script_usage
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize_device
|
57
|
+
@ctx = FFI::MemoryPointer.new(:pointer)
|
58
|
+
@dev = FFI::MemoryPointer.new(:pointer)
|
59
|
+
#
|
60
|
+
# initialize context / @device
|
61
|
+
#
|
62
|
+
if (FFI::Freenect.freenect_init(@ctx,nil) != 0)
|
63
|
+
puts "Error: can't initialize context"
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
@ctx = @ctx.read_pointer
|
67
|
+
|
68
|
+
if (FFI::Freenect.freenect_open_device(@ctx, @dev, 0) != 0)
|
69
|
+
puts "Error: can't initialize device"
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
@dev = @dev.read_pointer
|
73
|
+
end
|
74
|
+
|
75
|
+
def tilt_led_set
|
76
|
+
#
|
77
|
+
# Set tilt and/or led options on the @device
|
78
|
+
#
|
79
|
+
puts "Number of devices: #{FFI::Freenect.freenect_num_devices(@ctx)}"
|
80
|
+
if (not @tilt_option.nil?)
|
81
|
+
puts "Tilt set to: #{@tilt_option}"
|
82
|
+
FFI::Freenect.freenect_set_tilt_degs(@dev, @tilt_option.to_f)
|
83
|
+
end
|
84
|
+
if (not @led_option.nil?)
|
85
|
+
puts "LED set to: #{@led_option}"
|
86
|
+
FFI::Freenect.freenect_set_led(@dev, @led_option.to_i)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def cleanup
|
91
|
+
#
|
92
|
+
# Close the context and @device (for cleanup purposes)
|
93
|
+
#
|
94
|
+
FFI::Freenect.freenect_close_device(@dev)
|
95
|
+
if FFI::Freenect.freenect_shutdown(@ctx) != 0
|
96
|
+
puts "Error shutting down context"
|
97
|
+
exit 1
|
98
|
+
else
|
99
|
+
puts "Successfully shut down context"
|
100
|
+
exit 0
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
run = TILT_LED.new
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
5
|
+
|
6
|
+
require 'freenect'
|
7
|
+
|
8
|
+
ctx = Freenect.init
|
9
|
+
unless ctx.num_devices() > 0
|
10
|
+
STDERR.puts "No kinect device detected"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
dev = ctx[0]
|
15
|
+
dev.set_led(:blink_red_yellow)
|
16
|
+
|
17
|
+
3.times do
|
18
|
+
dev.set_tilt_degrees(15)
|
19
|
+
sleep 2
|
20
|
+
dev.set_tilt_degrees(-15)
|
21
|
+
sleep 2
|
22
|
+
end
|
23
|
+
dev.set_tilt_degrees(0.0)
|
24
|
+
|
25
|
+
dev.set_led(:off)
|
26
|
+
dev.close
|
27
|
+
ctx.shutdown
|
28
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Actual video and depth capture work similarly to eachother.
|
3
|
+
# But they're still both pretty un-sugary.
|
4
|
+
#
|
5
|
+
# Future versions will probably abstract this and try to make it more
|
6
|
+
# ruby-ish.
|
7
|
+
#
|
8
|
+
# The example below shows how to capture a single video frame to a PPM file.
|
9
|
+
|
10
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
11
|
+
require 'freenect'
|
12
|
+
ctx = Freenect.init()
|
13
|
+
|
14
|
+
devs = ctx.num_devices
|
15
|
+
|
16
|
+
STDERR.puts "Number of Kinects detected: #{devs}"
|
17
|
+
unless devs > 0
|
18
|
+
STDERR.puts "Error: no kinect detected"
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
STDERR.puts "Selecting device 0"
|
23
|
+
dev = ctx.open_device(0)
|
24
|
+
|
25
|
+
dev.set_led(:green) # play with the led
|
26
|
+
|
27
|
+
dev.set_video_format(Freenect::VIDEO_RGB)
|
28
|
+
dev.start_depth()
|
29
|
+
dev.start_video()
|
30
|
+
|
31
|
+
$snapshot_finished = nil
|
32
|
+
|
33
|
+
STDERR.puts "Attempting snapshot"
|
34
|
+
dev.set_video_callback do |device, video, timestamp|
|
35
|
+
if not $snapshot_finished
|
36
|
+
fname = "%i.ppm" % timestamp
|
37
|
+
STDERR.puts "Writing #{fname}"
|
38
|
+
File.open(fname, "w") do |f|
|
39
|
+
f.puts("P6 %d %d 255\n" % [ Freenect::FRAME_W, Freenect::FRAME_H ] )
|
40
|
+
f.write(video.read_string_length(Freenect::RGB_SIZE))
|
41
|
+
end
|
42
|
+
$snapshot_finished = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ret = -1
|
47
|
+
until $snapshot_finished
|
48
|
+
break if (ret=ctx.process_events) >= 0
|
49
|
+
end
|
50
|
+
|
51
|
+
if ret < 0
|
52
|
+
STDERR.puts "Error: unable to take snapshot. process_events code=#{ret}"
|
53
|
+
end
|
54
|
+
|
55
|
+
dev.set_led(:off)
|
56
|
+
dev.stop_depth
|
57
|
+
dev.stop_video
|
58
|
+
dev.close
|
59
|
+
ctx.close
|
60
|
+
|
61
|
+
|
data/lib/ffi/freenect.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
#nop
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'ffi'
|
8
|
+
|
9
|
+
module FFI::Freenect
|
10
|
+
extend FFI::Library
|
11
|
+
ffi_lib 'freenect', 'freenect_sync'
|
12
|
+
|
13
|
+
FRAME_W = 640
|
14
|
+
FRAME_H = 480
|
15
|
+
FRAME_PIX = FRAME_W * FRAME_H
|
16
|
+
|
17
|
+
IR_FRAME_W = 640
|
18
|
+
IR_FRAME_H = 488
|
19
|
+
IR_FRAME_PIX = FRAME_W * FRAME_H
|
20
|
+
|
21
|
+
RGB_SIZE = FRAME_PIX * 3
|
22
|
+
BAYER_SIZE = FRAME_PIX
|
23
|
+
YUV_RGB_SIZE = RGB_SIZE
|
24
|
+
YUV_RAW_SIZE = FRAME_PIX * 2
|
25
|
+
IR_8BIT_SIZE = IR_FRAME_PIX
|
26
|
+
IR_10BIT_SIZE = IR_FRAME_PIX * 2
|
27
|
+
IR_10BIT_PACKED_SIZE = 390400
|
28
|
+
|
29
|
+
DEPTH_11BIT_SIZE = FRAME_PIX * 2
|
30
|
+
DEPTH_10BIT_SIZE = DEPTH_11BIT_SIZE
|
31
|
+
DEPTH_11BIT_PACKED_SIZE = 422400
|
32
|
+
DEPTH_10BIT_PACKED_SIZE = 384000
|
33
|
+
|
34
|
+
COUNTS_PER_G = 819
|
35
|
+
|
36
|
+
LED_OFF = 0
|
37
|
+
LED_GREEN = 1
|
38
|
+
LED_RED = 2
|
39
|
+
LED_YELLOW = 3
|
40
|
+
LED_BLINK_YELLOW = 4
|
41
|
+
LED_BLINK_GREEN = 5
|
42
|
+
LED_BLINK_RED_YELLOW = 6
|
43
|
+
|
44
|
+
LED_OPTIONS = enum( :off, LED_OFF,
|
45
|
+
:green, LED_GREEN,
|
46
|
+
:red, LED_RED,
|
47
|
+
:yellow, LED_YELLOW,
|
48
|
+
:blink_yellow, LED_BLINK_YELLOW,
|
49
|
+
:blink_green, LED_BLINK_GREEN,
|
50
|
+
:blink_red_yellow, LED_BLINK_RED_YELLOW)
|
51
|
+
|
52
|
+
|
53
|
+
VIDEO_RGB = 0
|
54
|
+
VIDEO_BAYER = 1
|
55
|
+
VIDEO_IR_8BIT = 2
|
56
|
+
VIDEO_IR_10BIT = 3
|
57
|
+
VIDEO_IR_10BIT_PACKED = 4
|
58
|
+
VIDEO_YUV_RGB = 5
|
59
|
+
VIDEO_YUV_RAW = 6
|
60
|
+
|
61
|
+
VIDEO_FORMATS = enum( :rgb, VIDEO_RGB,
|
62
|
+
:bayer, VIDEO_BAYER,
|
63
|
+
:ir_8bit, VIDEO_IR_8BIT,
|
64
|
+
:ir_10bit, VIDEO_IR_10BIT,
|
65
|
+
:yuv_rgb, VIDEO_YUV_RGB,
|
66
|
+
:yuv_raw, VIDEO_YUV_RAW,
|
67
|
+
:ir_10bit_packed, VIDEO_IR_10BIT_PACKED)
|
68
|
+
|
69
|
+
VIDEO_SIZES = enum( :rgb, RGB_SIZE,
|
70
|
+
:bayer, BAYER_SIZE,
|
71
|
+
:ir_8bit, IR_8BIT_SIZE,
|
72
|
+
:ir_10bit, IR_10BIT_SIZE,
|
73
|
+
:yuv_rgb, YUV_RGB_SIZE,
|
74
|
+
:yuv_raw, YUV_RAW_SIZE,
|
75
|
+
:ir_10bit_packed, IR_10BIT_PACKED_SIZE )
|
76
|
+
|
77
|
+
|
78
|
+
DEPTH_11BIT = 0
|
79
|
+
DEPTH_10BIT = 1
|
80
|
+
DEPTH_11BIT_PACKED = 2
|
81
|
+
DEPTH_10BIT_PACKED = 3
|
82
|
+
|
83
|
+
DEPTH_FORMATS = enum( :depth_11bit, DEPTH_11BIT,
|
84
|
+
:depth_10bit, DEPTH_10BIT,
|
85
|
+
:depth_11bit_packed, DEPTH_11BIT_PACKED,
|
86
|
+
:depth_10bit_packed, DEPTH_10BIT_PACKED)
|
87
|
+
|
88
|
+
DEPTH_SIZES = enum( :depth_11bit, DEPTH_11BIT_SIZE,
|
89
|
+
:depth_10bit, DEPTH_10BIT_SIZE,
|
90
|
+
:depth_11bit_packed, DEPTH_11BIT_PACKED_SIZE,
|
91
|
+
:depth_10bit_packed, DEPTH_10BIT_PACKED_SIZE )
|
92
|
+
|
93
|
+
TILT_STATUS_STOPPED = 0x00
|
94
|
+
TILT_STATUS_LIMIT = 0x01
|
95
|
+
TILT_STATUS_MOVING = 0x04
|
96
|
+
|
97
|
+
TILT_STATUS_CODES = enum( :stopped, TILT_STATUS_STOPPED,
|
98
|
+
:limit, TILT_STATUS_LIMIT,
|
99
|
+
:moving, TILT_STATUS_MOVING)
|
100
|
+
|
101
|
+
|
102
|
+
LOG_FATAL = 0
|
103
|
+
LOG_ERROR = 1
|
104
|
+
LOG_WARNING = 2
|
105
|
+
LOG_NOTICE = 3
|
106
|
+
LOG_INFO = 4
|
107
|
+
LOG_DEBUG = 5
|
108
|
+
LOG_SPEW = 6
|
109
|
+
LOG_FLOOD = 7
|
110
|
+
|
111
|
+
LOGLEVELS = enum( :fatal, LOG_FATAL,
|
112
|
+
:error, LOG_ERROR,
|
113
|
+
:warning, LOG_WARNING,
|
114
|
+
:notice, LOG_NOTICE,
|
115
|
+
:info, LOG_INFO,
|
116
|
+
:debug, LOG_DEBUG,
|
117
|
+
:spew, LOG_SPEW,
|
118
|
+
:flood, LOG_FLOOD)
|
119
|
+
|
120
|
+
typedef :pointer, :freenect_context
|
121
|
+
typedef :pointer, :freenect_device
|
122
|
+
typedef :pointer, :freenect_usb_context # actually a libusb_context
|
123
|
+
|
124
|
+
|
125
|
+
class RawTiltState < FFI::Struct
|
126
|
+
layout :accelerometer_x, :int16_t,
|
127
|
+
:accelerometer_y, :int16_t,
|
128
|
+
:accelerometer_z, :int16_t,
|
129
|
+
:tilt_angle, :int8_t,
|
130
|
+
:tilt_status, TILT_STATUS_CODES
|
131
|
+
end
|
132
|
+
|
133
|
+
callback :freenect_log_cb, [:freenect_context, LOGLEVELS, :string], :void
|
134
|
+
callback :freenect_depth_cb, [:freenect_device, :pointer, :uint32], :void
|
135
|
+
callback :freenect_video_cb, [:freenect_device, :pointer, :uint32], :void
|
136
|
+
|
137
|
+
attach_function :freenect_set_log_level, [:freenect_context, LOGLEVELS], :void
|
138
|
+
attach_function :freenect_set_log_callback, [:freenect_context, :freenect_log_cb], :void
|
139
|
+
attach_function :freenect_process_events, [:freenect_context], :int
|
140
|
+
attach_function :freenect_num_devices, [:freenect_context], :int
|
141
|
+
attach_function :freenect_open_device, [:freenect_context, :freenect_device, :int], :int
|
142
|
+
attach_function :freenect_close_device, [:freenect_device], :int
|
143
|
+
attach_function :freenect_init, [:freenect_context, :freenect_usb_context], :int
|
144
|
+
attach_function :freenect_shutdown, [:freenect_context], :int
|
145
|
+
attach_function :freenect_set_user, [:freenect_device, :pointer], :void
|
146
|
+
attach_function :freenect_get_user, [:freenect_device], :pointer
|
147
|
+
attach_function :freenect_set_depth_callback, [:freenect_device, :freenect_depth_cb], :void
|
148
|
+
attach_function :freenect_set_video_callback, [:freenect_device, :freenect_video_cb], :void
|
149
|
+
attach_function :freenect_set_depth_format, [:freenect_device, DEPTH_FORMATS], :int
|
150
|
+
attach_function :freenect_set_video_format, [:freenect_device, VIDEO_FORMATS], :int
|
151
|
+
attach_function :freenect_set_depth_buffer, [:freenect_device, :void], :int
|
152
|
+
attach_function :freenect_set_video_buffer, [:freenect_device, :void], :int
|
153
|
+
attach_function :freenect_start_depth, [:freenect_device], :int
|
154
|
+
attach_function :freenect_start_video, [:freenect_device], :int
|
155
|
+
attach_function :freenect_stop_depth, [:freenect_device], :int
|
156
|
+
attach_function :freenect_stop_video, [:freenect_device], :int
|
157
|
+
attach_function :freenect_update_tilt_state, [:freenect_device], :int
|
158
|
+
attach_function :freenect_get_tilt_state, [:freenect_device], RawTiltState
|
159
|
+
attach_function :freenect_get_tilt_degs, [:freenect_device], :double
|
160
|
+
attach_function :freenect_set_tilt_degs, [:freenect_device, :double], :int
|
161
|
+
attach_function :freenect_set_led, [:freenect_device, LED_OPTIONS], :int
|
162
|
+
attach_function :freenect_get_mks_accel, [RawTiltState, :pointer, :pointer, :pointer], :void
|
163
|
+
|
164
|
+
attach_function :freenect_sync_get_video, [:pointer, :pointer, :int, VIDEO_FORMATS], :int
|
165
|
+
attach_function :freenect_sync_get_depth, [:pointer, :pointer, :int, DEPTH_FORMATS], :int
|
166
|
+
attach_function :freenect_sync_stop, [], :void
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
|