-
Notifications
You must be signed in to change notification settings - Fork 34
/
kinect.js
72 lines (58 loc) · 1.8 KB
/
kinect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var kinect = require('./build/Release/kinect.node');
var EventEmitter = require('events').EventEmitter;
var inherits = require('util').inherits;
var assert = require('assert');
function Context(context) {
this._kContext = context;
this._activated = {};
EventEmitter.apply(this, arguments);
}
inherits(Context, EventEmitter);
Context.prototype.activate = function(wat) {
var self = this;
if (this._activated[wat]) throw new Error('Already had activated ' + wat)
switch(wat) {
case "depth":
process.nextTick(function() {
self._kContext.setDepthCallback();
});
break;
case "video":
//var buf = self._videoBuffer = new Buffer(640 * 480 * 3);
//self._kContext.setVideoBuffer(buf);
self._kContext.setVideoCallback();
break;
default: throw new Error('Cannot activate ' + wat);
}
this._activated[wat] = true;
};
Context.prototype.start = Context.prototype.activate;
kinect.Context.prototype.depthCallback = function depthCallback(depthBuffer) {
this._context.emit('depth', depthBuffer);
};
kinect.Context.prototype.videoCallback = function videoCallback(videoBuffer) {
this._context.emit('video', videoBuffer);
};
Context.prototype.led = function lef(color) {
this._kContext.led(color);
};
Context.prototype.tilt = function tilt(angle) {
this._kContext.tilt(angle);
};
Context.prototype.close = function close() {
this._kContext.close();
};
Context.prototype.resume = function() {
this._kContext.resume();
};
Context.prototype.pause = function() {
this._kContext.pause();
};
module.exports = function(options) {
if (! options) options = {};
if (! options.device) options.device = 0;
var kContext = new kinect.Context(options.device);
var context = new Context(kContext);
kContext._context = context;
return context;
};