kinectaby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Scott Chacon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ Kinectaby - libfreenect Ruby bindings
2
+ =====================================
3
+
4
+ Kinectaby is a first pass at Ruby bindings to the amazing Kinect libfreenect
5
+ driver.
6
+
7
+ INSTALLING AND RUNNING
8
+ ========================
9
+
10
+ First you need a Kinect.
11
+
12
+ Then you need to install libfreenect.
13
+
14
+ Next, you need to install rake-compiler:
15
+
16
+ $ sudo gem install rake-compiler
17
+
18
+ Then you need to get and compile this.
19
+
20
+ $ git clone git://github.com/schacon/kinectaby.git
21
+ $ cd kinectaby
22
+ $ rake compile
23
+ $ rake test
24
+
25
+ API
26
+ ==============
27
+
28
+ require 'kinectaby'
29
+
30
+ context = Kinectaby::Context.new
31
+ context.num_devices
32
+ context.shutdown
33
+
34
+ device = context.open_device(0)
35
+ device.set_led(Kinectaby::LED_RED)
36
+ device.close
37
+
38
+ CONTRIBUTING
39
+ ==============
40
+
41
+ Fork schacon/kinectaby on GitHub, make it awesomer (preferably in a branch named
42
+ for the topic), send me a pull request.
43
+
44
+
45
+ AUTHORS
46
+ ==============
47
+
48
+ * Scott Chacon <schacon@gmail.com>
49
+
50
+ LICENSE
51
+ ==============
52
+
53
+ MIT. See LICENSE file.
54
+
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # stolen largely from defunkt/mustache
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/extensiontask'
5
+
6
+ Rake::ExtensionTask.new('kinectaby') do |r|
7
+ r.lib_dir = 'lib/kinectaby'
8
+ end
9
+
10
+ #
11
+ # Tests
12
+ #
13
+
14
+ task :default => :test
15
+
16
+ desc "Run tests"
17
+ task :turn do
18
+ suffix = "-n #{ENV['TEST']}" if ENV['TEST']
19
+ sh "turn test/*_test.rb #{suffix}"
20
+ end
21
+
22
+ Rake::TestTask.new do |t|
23
+ t.libs << 'lib'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+ desc "Update the libfreenect SHA"
29
+ task :libfreenect do
30
+ sha = `git --git-dir=../libfreenect/.git rev-parse HEAD`
31
+ File.open("LIBFREENECT_VERSION", 'w') do |f|
32
+ f.puts "# git --git-dir=../libfreenect/.git rev-parse HEAD"
33
+ f.puts sha
34
+ end
35
+ end
36
+
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("kinectaby")
4
+
5
+ have_library('freenect')
6
+
7
+ create_makefile("kinectaby/kinectaby")
8
+
@@ -0,0 +1,128 @@
1
+ #include <ruby.h>
2
+ #include <assert.h>
3
+
4
+ #include "libfreenect.h"
5
+
6
+ static VALUE rb_mKinectaby;
7
+
8
+ static VALUE rb_cKinectabyContext;
9
+ static VALUE rb_cKinectabyDevice;
10
+
11
+ /*
12
+ * Kinectaby Context
13
+ */
14
+ static VALUE rb_freenect_context_allocate(VALUE klass)
15
+ {
16
+ freenect_context *context = NULL;
17
+ return Data_Wrap_Struct(klass, NULL, NULL, context);
18
+ }
19
+
20
+ static VALUE rb_freenect_context_init(VALUE self)
21
+ {
22
+ freenect_context *context;
23
+ int error;
24
+
25
+ error = freenect_init(&context, NULL);
26
+ if (error < 0)
27
+ rb_raise(rb_eRuntimeError, "freenect init failed");
28
+
29
+ DATA_PTR(self) = context;
30
+ return Qnil;
31
+ }
32
+
33
+ static VALUE rb_freenect_context_num_devices(VALUE self)
34
+ {
35
+ freenect_context *context;
36
+ int devices;
37
+
38
+ Data_Get_Struct(self, freenect_context, context);
39
+
40
+ return INT2FIX(freenect_num_devices(context));
41
+ }
42
+
43
+ static VALUE rb_freenect_context_open_device(VALUE self, VALUE device_num)
44
+ {
45
+ freenect_context *context;
46
+ freenect_device *device;
47
+ int error;
48
+
49
+ Data_Get_Struct(self, freenect_context, context);
50
+
51
+ error = freenect_open_device(context, &device, FIX2INT(device_num));
52
+ if (error < 0)
53
+ rb_raise(rb_eRuntimeError, "freenect device open failed");
54
+
55
+ return Data_Wrap_Struct(rb_cKinectabyDevice, NULL, NULL, device);
56
+ }
57
+
58
+ static VALUE rb_freenect_context_shutdown(VALUE self)
59
+ {
60
+ freenect_context *context;
61
+ int error;
62
+
63
+ Data_Get_Struct(self, freenect_context, context);
64
+
65
+ error = freenect_shutdown(context);
66
+ if (error < 0)
67
+ rb_raise(rb_eRuntimeError, "freenect shutdown failed");
68
+
69
+ return Qtrue;
70
+ }
71
+
72
+ /*
73
+ * Kinectaby Device
74
+ */
75
+ static VALUE rb_freenect_device_close(VALUE self)
76
+ {
77
+ freenect_device *device;
78
+ int error;
79
+
80
+ Data_Get_Struct(self, freenect_device, device);
81
+
82
+ error = freenect_close_device(device);
83
+ if (error < 0)
84
+ rb_raise(rb_eRuntimeError, "freenect device close failed");
85
+
86
+ return Qtrue;
87
+ }
88
+
89
+ static VALUE rb_freenect_device_set_led(VALUE self, VALUE led)
90
+ {
91
+ freenect_device *device;
92
+ Data_Get_Struct(self, freenect_device, device);
93
+
94
+ return INT2FIX(freenect_set_led(device, FIX2INT(led)));
95
+ }
96
+
97
+
98
+ void Init_kinectaby()
99
+ {
100
+ rb_mKinectaby = rb_define_module("Kinectaby");
101
+
102
+ /*
103
+ * Context
104
+ */
105
+ rb_cKinectabyContext = rb_define_class_under(rb_mKinectaby, "Context", rb_cObject);
106
+ rb_define_alloc_func(rb_cKinectabyContext, rb_freenect_context_allocate);
107
+ rb_define_method(rb_cKinectabyContext, "initialize", rb_freenect_context_init, 0);
108
+ rb_define_method(rb_cKinectabyContext, "num_devices", rb_freenect_context_num_devices, 0);
109
+ rb_define_method(rb_cKinectabyContext, "open_device", rb_freenect_context_open_device, 1);
110
+ rb_define_method(rb_cKinectabyContext, "shutdown", rb_freenect_context_shutdown, 0);
111
+
112
+ /*
113
+ * Device
114
+ */
115
+ rb_cKinectabyDevice = rb_define_class_under(rb_mKinectaby, "Device", rb_cObject);
116
+ rb_define_method(rb_cKinectabyDevice, "set_led", rb_freenect_device_set_led, 1);
117
+ rb_define_method(rb_cKinectabyDevice, "close", rb_freenect_device_close, 0);
118
+
119
+ /* Constants */
120
+ rb_define_const(rb_mKinectaby, "LED_OFF", INT2FIX(LED_OFF));
121
+ rb_define_const(rb_mKinectaby, "LED_GREEN", INT2FIX(LED_GREEN));
122
+ rb_define_const(rb_mKinectaby, "LED_RED", INT2FIX(LED_RED));
123
+ rb_define_const(rb_mKinectaby, "LED_YELLOW", INT2FIX(LED_YELLOW));
124
+ rb_define_const(rb_mKinectaby, "LED_BLINK_YELLOW", INT2FIX(LED_BLINK_YELLOW));
125
+ rb_define_const(rb_mKinectaby, "LED_BLINK_GREEN", INT2FIX(LED_BLINK_GREEN));
126
+ rb_define_const(rb_mKinectaby, "LED_BLINK_RED_YELLOW", INT2FIX(LED_BLINK_RED_YELLOW));
127
+ }
128
+
data/lib/kinectaby.rb ADDED
@@ -0,0 +1 @@
1
+ require 'kinectaby/kinectaby'
@@ -0,0 +1,42 @@
1
+ require File.expand_path "../test_helper", __FILE__
2
+
3
+ # these tests basically all require a single kinect conntected
4
+
5
+ context "Kinectaby::Context stuff" do
6
+ setup do
7
+ @context = Kinectaby::Context.new
8
+ end
9
+
10
+ test "Initialize and shutdown Kinect" do
11
+ assert @context.shutdown
12
+ end
13
+
14
+ test "Count Kinect devices" do
15
+ assert 1, @context.num_devices
16
+ end
17
+
18
+ test "Kinect LED constants" do
19
+ assert_equal 0, Kinectaby::LED_OFF
20
+ assert_equal 6, Kinectaby::LED_BLINK_RED_YELLOW
21
+ end
22
+
23
+ test "Get a device" do
24
+ device = @context.open_device(0)
25
+ device.close
26
+ end
27
+
28
+ test "Get no device" do
29
+ assert_raise RuntimeError do
30
+ device = @context.open_device(1)
31
+ end
32
+ end
33
+
34
+ test "set led" do
35
+ device = @context.open_device(0)
36
+ device.set_led(Kinectaby::LED_RED)
37
+ device.set_led(Kinectaby::LED_BLINK_RED_YELLOW)
38
+ device.set_led(Kinectaby::LED_GREEN)
39
+ device.set_led(Kinectaby::LED_OFF)
40
+ end
41
+
42
+ end
@@ -0,0 +1,28 @@
1
+ dir = File.dirname(File.expand_path(__FILE__))
2
+ $LOAD_PATH.unshift dir + '/../lib'
3
+ $TESTING = true
4
+ require 'test/unit'
5
+ require 'rubygems'
6
+ require 'kinectaby'
7
+ require 'pp'
8
+
9
+ ##
10
+ # test/spec/mini 3
11
+ # http://gist.github.com/25455
12
+ # chris@ozmm.org
13
+ #
14
+ def context(*args, &block)
15
+ return super unless (name = args.first) && block
16
+ require 'test/unit'
17
+ klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
18
+ def self.test(name, &block)
19
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
20
+ end
21
+ def self.xtest(*args) end
22
+ def self.setup(&block) define_method(:setup, &block) end
23
+ def self.teardown(&block) define_method(:teardown, &block) end
24
+ end
25
+ (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
26
+ klass.class_eval &block
27
+ end
28
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kinectaby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Scott Chacon
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-18 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ Kinectaby is a Ruby binding to the libfreenect OS Kinect library.
24
+
25
+ email: schacon@gmail.com
26
+ executables: []
27
+
28
+ extensions:
29
+ - ext/kinectaby/extconf.rb
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - README.md
34
+ - Rakefile
35
+ - LICENSE
36
+ - lib/kinectaby.rb
37
+ - test/context_test.rb
38
+ - test/test_helper.rb
39
+ - ext/kinectaby/kinectaby.c
40
+ - ext/kinectaby/extconf.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/schacon/kinectaby
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Kinectaby is a Ruby binding to the libfreenect OS Kinect library
75
+ test_files: []
76
+