Skip to content

Commit

Permalink
Cleaning up!
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Carlos del Valle <jc.ekinox@gmail.com> (imekinox)
  • Loading branch information
imekinox committed Nov 23, 2010
1 parent 12a39e3 commit c973193
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 76 deletions.
9 changes: 9 additions & 0 deletions 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"

2 changes: 2 additions & 0 deletions 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.
Expand Up @@ -32,7 +32,7 @@ package org.libfreenect.events
public class libfreenectMotorEvent extends Event public class libfreenectMotorEvent extends Event
{ {


public static const LIBFREENECT_MOTOR_MOVED:String = "LIBFREENECT_MOTOR_MOVED"; public static const MOVED:String = "MOVED";


public var data:*; public var data:*;


Expand Down
15 changes: 9 additions & 6 deletions wrappers/actionscript/org/libfreenect/libfreenect.as
Expand Up @@ -14,7 +14,7 @@
* *
* If you redistribute this file in source form, modified or unmodified, * If you redistribute this file in source form, modified or unmodified,
* you may: * 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 * accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL20 file, 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 * 3) Delete the GPL v2.0 clause and accompany it with the APACHE20 file
Expand All @@ -30,12 +30,15 @@ package org.libfreenect
public class libfreenect public class libfreenect
{ {


public static const LIBFREENECT_SUCCESS:int = 0; public static const SUCCESS:int = 0;
public static const LIBFREENECT_SIZE_ERROR:int = -1; public static const ERROR:int = -1;


public static const LIBFREENECT_CAMERA:int = 0; public static const CAMERA_ID:int = 0;
public static const LIBFREENECT_MOTOR:int = 1; public static const MOTOR_ID:int = 1;
public static const LIBFREENECT_MIC:int = 2; 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;
} }
} }
12 changes: 2 additions & 10 deletions wrappers/actionscript/org/libfreenect/libfreenectCamera.as
Expand Up @@ -55,14 +55,6 @@ package org.libfreenect
public function libfreenectCamera() public function libfreenectCamera()
{ {
if ( !_singleton_lock ) throw new Error( 'Use libfreenectCamera.instance' ); 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{ private function onDepthReceived(event:libfreenectSocketEvent):void{
Expand All @@ -81,7 +73,7 @@ package org.libfreenect


public function initRGBStream(container:Sprite):void{ public function initRGBStream(container:Sprite):void{
socket_rgb = new libfreenectSocket(); 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); if(!canvas_rgb) canvas_rgb = new BitmapData(640, 480, false, 0xFF000000);
rgb_bmp = new Bitmap(canvas_rgb); rgb_bmp = new Bitmap(canvas_rgb);
container.addChild(rgb_bmp); container.addChild(rgb_bmp);
Expand All @@ -90,7 +82,7 @@ package org.libfreenect


public function initDepthStream(container:Sprite):void{ public function initDepthStream(container:Sprite):void{
socket_depth = new libfreenectSocket(); 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); if(!canvas_depth) canvas_depth = new BitmapData(640, 480, false, 0xFF000000);
depth_bmp = new Bitmap(canvas_depth); depth_bmp = new Bitmap(canvas_depth);
container.addChild(depth_bmp); container.addChild(depth_bmp);
Expand Down
5 changes: 1 addition & 4 deletions wrappers/actionscript/org/libfreenect/libfreenectData.as
Expand Up @@ -45,11 +45,8 @@ package org.libfreenect
if ( !_singleton_lock ) throw new Error( 'Use libfreenectData.instance' ); if ( !_singleton_lock ) throw new Error( 'Use libfreenectData.instance' );


socket = new libfreenectSocket(); socket = new libfreenectSocket();
//Another initialization may be needed here


//socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT,onConnect); socket.addEventListener(libfreenectSocketEvent.ONDATA,onDataReceived);
//socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONERROR,onError);
socket.addEventListener(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA,onDataReceived);


socket.connect("localhost", 6003); socket.connect("localhost", 6003);
} }
Expand Down
14 changes: 7 additions & 7 deletions wrappers/actionscript/org/libfreenect/libfreenectMotor.as
Expand Up @@ -40,28 +40,28 @@ package org.libfreenect
private static var _instance:libfreenectMotor; private static var _instance:libfreenectMotor;


private var _current_position:Number; private var _current_position:Number;
public var inf:libfreenectData; public var _info:libfreenectData;


public function libfreenectMotor() public function libfreenectMotor()
{ {
if ( !_singleton_lock ) throw new Error( 'Use libfreenectMotor.instance' ); if ( !_singleton_lock ) throw new Error( 'Use libfreenectMotor.instance' );


inf = libfreenectData.instance; _info = libfreenectData.instance;
inf.addEventListener(libfreenectDataEvent.DATA_RECEIVED, onDataReceived); _info.addEventListener(libfreenectDataEvent.DATA_RECEIVED, onDataReceived);
} }


private function onDataReceived(event:libfreenectDataEvent):void{ 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 public function set position(position:Number):void
{ {
var data:ByteArray = new ByteArray; var data:ByteArray = new ByteArray;
data.writeByte(libfreenect.LIBFREENECT_MOTOR); data.writeByte(libfreenect.MOTOR_ID);
data.writeByte(1); //MOVE MOTOR data.writeByte(1); //MOVE MOTOR
data.writeInt(position); data.writeInt(position);
if(inf.sendData(data) == libfreenect.LIBFREENECT_SUCCESS){ if(_info.sendData(data) == libfreenect.SUCCESS){
dispatchEvent(new libfreenectMotorEvent(libfreenectMotorEvent.LIBFREENECT_MOTOR_MOVED, position)); dispatchEvent(new libfreenectMotorEvent(libfreenectMotorEvent.MOVED, position));
} else { } else {
throw new Error('Data was not complete'); throw new Error('Data was not complete');
} }
Expand Down
82 changes: 34 additions & 48 deletions wrappers/actionscript/org/libfreenect/libfreenectSocket.as
Expand Up @@ -43,89 +43,77 @@
*/ */
public class libfreenectSocket extends EventDispatcher 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 static var _instance:libfreenectSocket;
private var _packages_received:Number = 0; private var _packet_size:Number;
private var packet_size:Number; private var _socket:Socket;
private var socket:Socket; private var _buffer:ByteArray;
private var buffer:ByteArray;
private var rawPackage:ByteArray;
private var _port:Number; private var _port:Number;
private var byteArray:ByteArray;


public function libfreenectSocket() public function libfreenectSocket()
{ {
//if ( !_singleton_lock ) throw new Error( 'Use libfreenectSocket.instance' ); _socket = new Socket();

_buffer = new ByteArray();
socket = new Socket();
buffer = new ByteArray(); _socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
rawPackage = new ByteArray(); _socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);

_socket.addEventListener(Event.CONNECT, onSocketConnect);
//Another initialization may be needed here

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 = 6003):void
public function connect(host:String = 'localhost', port:uint = 8000):void
{ {
_port = port; _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) if (!this.connected)
socket.connect(host, port); _socket.connect(host, port);
else else
dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONCONNECT, null)); dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONCONNECT, null));
} }


public function get connected():Boolean public function get connected():Boolean
{ {
return socket.connected; return _socket.connected;
} }


public function close():void public function close():void
{ {
socket.close(); _socket.close();
} }


public function sendData(data:ByteArray):int{ public function sendData(data:ByteArray):int{
if(data.length == _send_size){ if(data.length == libfreenect.DATA_OUT_SIZE){
trace("sendData"); trace("sendData");
socket.writeBytes(data, 0, _send_size); _socket.writeBytes(data, 0, libfreenect.DATA_OUT_SIZE);
socket.flush(); _socket.flush();
return libfreenect.LIBFREENECT_SUCCESS; return libfreenect.SUCCESS;
} else { } else {
throw new Error( 'Incorrect data size (' + data.length + '). Expected: ' + _send_size); throw new Error( 'Incorrect data size (' + data.length + '). Expected: ' + libfreenect.DATA_OUT_SIZE);
return libfreenect.LIBFREENECT_SIZE_ERROR; return libfreenect.ERROR;
} }
} }

private function onSocketData(event:ProgressEvent):void private function onSocketData(event:ProgressEvent):void
{ {
if(socket.bytesAvailable == 237){ if(_socket.bytesAvailable < 237){
byteArray = new ByteArray(); var _byte_arr:ByteArray = new ByteArray();
socket.readBytes(byteArray, 0, socket.bytesAvailable); _socket.readBytes(_byte_arr, 0, _socket.bytesAvailable);
trace("policy_file : " + byteArray); trace("policy_file : " + byteArray);
} }
if(socket.bytesAvailable > 0) { if(_socket.bytesAvailable > 0) {
if(socket.bytesAvailable >= packet_size){ if(_socket.bytesAvailable >= _packet_size){
socket.readBytes(rawPackage, 0, packet_size); _socket.readBytes(_buffer, 0, _packet_size);
rawPackage.endian = Endian.LITTLE_ENDIAN; _buffer.endian = Endian.LITTLE_ENDIAN;
rawPackage.position = 0; _buffer.position = 0;
dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.LIBFREENECT_SOCKET_ONDATA, rawPackage)); dispatchEvent(new libfreenectSocketEvent(libfreenectSocketEvent.ONDATA, _buffer));
} }
} }
} }


private function onSocketError(event:IOErrorEvent):void{ 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{ 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 public function set instance(instance:libfreenectSocket):void
Expand All @@ -137,9 +125,7 @@
{ {
if ( _instance == null ) if ( _instance == null )
{ {
//_singleton_lock = true;
_instance = new libfreenectSocket(); _instance = new libfreenectSocket();
//_singleton_lock = false;
} }
return _instance; return _instance;
} }
Expand Down

0 comments on commit c973193

Please sign in to comment.