Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaning up!

Signed-off-by: Juan Carlos del Valle <jc.ekinox@gmail.com> (imekinox)
  • Loading branch information...
commit c9731936cd54bc153027170cad52c8b4aed013c7 1 parent 12a39e3
@imekinox imekinox authored
View
9 udev/51-kinect.rules
@@ -0,0 +1,9 @@
+# ATTR{product}=="Xbox NUI Motor"
+SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02b0", MODE="0666"
+
+# ATTR{product}=="Xbox NUI Audio"
+SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ad", MODE="0666"
+
+# ATTR{product}=="Xbox NUI Camera"
+SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ae", MODE="0666"
+
View
2  udev/README
@@ -0,0 +1,2 @@
+Simply place this file in /etc/udev/rules.d and you'll no longer need
+to run your apps as root.
View
2  wrappers/actionscript/org/libfreenect/events/libfreenectMotorEvent.as
@@ -32,7 +32,7 @@ package org.libfreenect.events
public class libfreenectMotorEvent extends Event
{
- public static const LIBFREENECT_MOTOR_MOVED:String = "LIBFREENECT_MOTOR_MOVED";
+ public static const MOVED:String = "MOVED";
public var data:*;
View
15 wrappers/actionscript/org/libfreenect/libfreenect.as
@@ -14,7 +14,7 @@
*
* If you redistribute this file in source form, modified or unmodified,
* you may:
- * 1) Leave this header intact and distribute it under the same terms,
+ * 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, or
* 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
@@ -30,12 +30,15 @@ package org.libfreenect
public class libfreenect
{
- public static const LIBFREENECT_SUCCESS:int = 0;
- public static const LIBFREENECT_SIZE_ERROR:int = -1;
+ public static const SUCCESS:int = 0;
+ public static const ERROR:int = -1;
- public static const LIBFREENECT_CAMERA:int = 0;
- public static const LIBFREENECT_MOTOR:int = 1;
- public static const LIBFREENECT_MIC:int = 2;
+ public static const CAMERA_ID:int = 0;
+ public static const MOTOR_ID:int = 1;
+ public static const MIC_ID:int = 2;
+ public static const RAW_IMG_SIZE:int = 640 * 480 * 4;
+ public static const DATA_IN_SIZE:int = 3 * 2 + 3 * 8;
+ public static const DATA_OUT_SIZE:int = 6;
}
}
View
12 wrappers/actionscript/org/libfreenect/libfreenectCamera.as
@@ -55,14 +55,6 @@ package org.libfreenect
public function libfreenectCamera()
{
if ( !_singleton_lock ) throw new Error( 'Use libfreenectCamera.instance' );
-
- //socket = new libfreenectSocket();
-
- //Another initialization may be needed here
-
- //socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT,onConnect);
- //socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONERROR,onError);
- //socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA,onDataReceived);
}
private function onDepthReceived(event:libfreenectSocketEvent):void{
@@ -81,7 +73,7 @@ package org.libfreenect
public function initRGBStream(container:Sprite):void{
socket_rgb = new libfreenectSocket();
- socket_rgb.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA,onRGBReceived);
+ socket_rgb.addEventListener(libfreenectSocketEvent.ONDATA,onRGBReceived);
if(!canvas_rgb) canvas_rgb = new BitmapData(640, 480, false, 0xFF000000);
rgb_bmp = new Bitmap(canvas_rgb);
container.addChild(rgb_bmp);
@@ -90,7 +82,7 @@ package org.libfreenect
public function initDepthStream(container:Sprite):void{
socket_depth = new libfreenectSocket();
- socket_depth.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA,onDepthReceived);
+ socket_depth.addEventListener(libfreenectSocketEvent.ONDATA,onDepthReceived);
if(!canvas_depth) canvas_depth = new BitmapData(640, 480, false, 0xFF000000);
depth_bmp = new Bitmap(canvas_depth);
container.addChild(depth_bmp);
View
5 wrappers/actionscript/org/libfreenect/libfreenectData.as
@@ -45,11 +45,8 @@ package org.libfreenect
if ( !_singleton_lock ) throw new Error( 'Use libfreenectData.instance' );
socket = new libfreenectSocket();
- //Another initialization may be needed here
- //socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT,onConnect);
- //socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONERROR,onError);
- socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA,onDataReceived);
+ socket.addEventListener(libfreenectSocketEvent.ONDATA,onDataReceived);
socket.connect("localhost", 6003);
}
View
14 wrappers/actionscript/org/libfreenect/libfreenectMotor.as
@@ -40,28 +40,28 @@ package org.libfreenect
private static var _instance:libfreenectMotor;
private var _current_position:Number;
- public var inf:libfreenectData;
+ public var _info:libfreenectData;
public function libfreenectMotor()
{
if ( !_singleton_lock ) throw new Error( 'Use libfreenectMotor.instance' );
- inf = libfreenectData.instance;
- inf.addEventListener(libfreenectDataEvent.DATA_RECEIVED, onDataReceived);
+ _info = libfreenectData.instance;
+ _info.addEventListener(libfreenectDataEvent.DATA_RECEIVED, onDataReceived);
}
private function onDataReceived(event:libfreenectDataEvent):void{
- var object:Object = event.data; // Acelerometer info so far
+ var object:Object = event.data; // Acelerometer _infoo so far
}
public function set position(position:Number):void
{
var data:ByteArray = new ByteArray;
- data.writeByte(libfreenect.LIBFREENECT_MOTOR);
+ data.writeByte(libfreenect.MOTOR_ID);
data.writeByte(1); //MOVE MOTOR
data.writeInt(position);
- if(inf.sendData(data) == libfreenect.LIBFREENECT_SUCCESS){
- dispatchEvent(new libfreenectMotorEvent(libfreenectMotorEvent.LIBFREENECT_MOTOR_MOVED, position));
+ if(_info.sendData(data) == libfreenect.SUCCESS){
+ dispatchEvent(new libfreenectMotorEvent(libfreenectMotorEvent.MOVED, position));
} else {
throw new Error('Data was not complete');
}
View
82 wrappers/actionscript/org/libfreenect/libfreenectSocket.as
@@ -43,89 +43,77 @@
*/
public class libfreenectSocket extends EventDispatcher
{
- private static const _images_size:int = 640 * 480 * 4; //614400; //NEEDS DEFINITION (65536 * 9 = 589824) 640 * 480 * 2 = 614400
- private static const _data_size:int = 3 * 2 + 3 * 8;
- private static const _send_size:int = 6;
- //private static var _singleton_lock:Boolean = false;
private static var _instance:libfreenectSocket;
- private var _packages_received:Number = 0;
- private var packet_size:Number;
- private var socket:Socket;
- private var buffer:ByteArray;
- private var rawPackage:ByteArray;
+ private var _packet_size:Number;
+ private var _socket:Socket;
+ private var _buffer:ByteArray;
private var _port:Number;
- private var byteArray:ByteArray;
public function libfreenectSocket()
- {
- //if ( !_singleton_lock ) throw new Error( 'Use libfreenectSocket.instance' );
-
- socket = new Socket();
- buffer = new ByteArray();
- rawPackage = new ByteArray();
-
- //Another initialization may be needed here
-
- socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
- socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);
- socket.addEventListener(Event.CONNECT, onSocketConnect);
+ {
+ _socket = new Socket();
+ _buffer = new ByteArray();
+
+ _socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
+ _socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);
+ _socket.addEventListener(Event.CONNECT, onSocketConnect);
}
- //DEFAULT PORT NEEDS DEFINITION
- public function connect(host:String = 'localhost', port:uint = 8000):void
+ public function connect(host:String = 'localhost', port:uint = 6003):void
{
_port = port;
- packet_size = (_port == 6003) ? _data_size : _images_size;
+ _packet_size = (_port == 6003) ? libfreenect.DATA_IN_SIZE : libfreenect.RAW_IMG_SIZE;
if (!this.connected)
- socket.connect(host, port);
+ _socket.connect(host, port);
else
- dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT, null));
+ dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONCONNECT, null));
}
public function get connected():Boolean
{
- return socket.connected;
+ return _socket.connected;
}
public function close():void
{
- socket.close();
+ _socket.close();
}
public function sendData(data:ByteArray):int{
- if(data.length == _send_size){
+ if(data.length == libfreenect.DATA_OUT_SIZE){
trace("sendData");
- socket.writeBytes(data, 0, _send_size);
- socket.flush();
- return libfreenect.LIBFREENECT_SUCCESS;
+ _socket.writeBytes(data, 0, libfreenect.DATA_OUT_SIZE);
+ _socket.flush();
+ return libfreenect.SUCCESS;
} else {
- throw new Error( 'Incorrect data size (' + data.length + '). Expected: ' + _send_size);
- return libfreenect.LIBFREENECT_SIZE_ERROR;
+ throw new Error( 'Incorrect data size (' + data.length + '). Expected: ' + libfreenect.DATA_OUT_SIZE);
+ return libfreenect.ERROR;
}
}
+
private function onSocketData(event:ProgressEvent):void
{
- if(socket.bytesAvailable == 237){
- byteArray = new ByteArray();
- socket.readBytes(byteArray, 0, socket.bytesAvailable);
+ if(_socket.bytesAvailable < 237){
+ var _byte_arr:ByteArray = new ByteArray();
+ _socket.readBytes(_byte_arr, 0, _socket.bytesAvailable);
trace("policy_file : " + byteArray);
}
- if(socket.bytesAvailable > 0) {
- if(socket.bytesAvailable >= packet_size){
- socket.readBytes(rawPackage, 0, packet_size);
- rawPackage.endian = Endian.LITTLE_ENDIAN;
- rawPackage.position = 0;
- dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA, rawPackage));
+ if(_socket.bytesAvailable > 0) {
+ if(_socket.bytesAvailable >= _packet_size){
+ _socket.readBytes(_buffer, 0, _packet_size);
+ _buffer.endian = Endian.LITTLE_ENDIAN;
+ _buffer.position = 0;
+ dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONDATA, _buffer));
}
}
}
private function onSocketError(event:IOErrorEvent):void{
- dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONERROR, null));
+ dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONERROR, null));
}
private function onSocketConnect(event:Event):void{
- dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT, null));
+ dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONCONNECT, null));
}
public function set instance(instance:libfreenectSocket):void
@@ -137,9 +125,7 @@
{
if ( _instance == null )
{
- //_singleton_lock = true;
_instance = new libfreenectSocket();
- //_singleton_lock = false;
}
return _instance;
}
Please sign in to comment.
Something went wrong with that request. Please try again.