libfreenect  0.1-beta
/builddir/build/BUILD/libfreenect/include/libfreenect.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of the OpenKinect Project. http://www.openkinect.org
00003  *
00004  * Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
00005  * for details.
00006  *
00007  * This code is licensed to you under the terms of the Apache License, version
00008  * 2.0, or, at your option, the terms of the GNU General Public License,
00009  * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
00010  * or the following URLs:
00011  * http://www.apache.org/licenses/LICENSE-2.0
00012  * http://www.gnu.org/licenses/gpl-2.0.txt
00013  *
00014  * If you redistribute this file in source form, modified or unmodified, you
00015  * may:
00016  *   1) Leave this header intact and distribute it under the same terms,
00017  *      accompanying it with the APACHE20 and GPL20 files, or
00018  *   2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
00019  *   3) Delete the GPL v2 clause and accompany it with the APACHE20 file
00020  * In all cases you must keep the copyright notice intact and include a copy
00021  * of the CONTRIB file.
00022  *
00023  * Binary distributions must follow the binary distribution requirements of
00024  * either License.
00025  */
00026 
00027 #ifndef LIBFREENECT_H
00028 #define LIBFREENECT_H
00029 
00030 #include <stdint.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 #define FREENECT_COUNTS_PER_G 819 
00038 
00039 #define FREENECT_DEPTH_MM_MAX_VALUE 10000
00040 
00041 #define FREENECT_DEPTH_MM_NO_VALUE 0
00042 
00043 #define FREENECT_DEPTH_RAW_MAX_VALUE 2048
00044 
00045 #define FREENECT_DEPTH_RAW_NO_VALUE 2047
00046 
00052 typedef enum {
00053         FREENECT_DEVICE_MOTOR  = 0x01,
00054         FREENECT_DEVICE_CAMERA = 0x02,
00055         FREENECT_DEVICE_AUDIO  = 0x04,
00056 } freenect_device_flags;
00057 
00061 struct freenect_device_attributes;
00062 struct freenect_device_attributes {
00063         struct freenect_device_attributes *next; 
00064         const char* camera_serial; 
00065 };
00066 
00071 typedef enum {
00072         FREENECT_RESOLUTION_LOW    = 0, 
00073         FREENECT_RESOLUTION_MEDIUM = 1, 
00074         FREENECT_RESOLUTION_HIGH   = 2, 
00075         FREENECT_RESOLUTION_DUMMY  = 2147483647, 
00076 } freenect_resolution;
00077 
00080 typedef enum {
00081         FREENECT_VIDEO_RGB             = 0, 
00082         FREENECT_VIDEO_BAYER           = 1, 
00083         FREENECT_VIDEO_IR_8BIT         = 2, 
00084         FREENECT_VIDEO_IR_10BIT        = 3, 
00085         FREENECT_VIDEO_IR_10BIT_PACKED = 4, 
00086         FREENECT_VIDEO_YUV_RGB         = 5, 
00087         FREENECT_VIDEO_YUV_RAW         = 6, 
00088         FREENECT_VIDEO_DUMMY           = 2147483647, 
00089 } freenect_video_format;
00090 
00093 typedef enum {
00094         FREENECT_DEPTH_11BIT        = 0, 
00095         FREENECT_DEPTH_10BIT        = 1, 
00096         FREENECT_DEPTH_11BIT_PACKED = 2, 
00097         FREENECT_DEPTH_10BIT_PACKED = 3, 
00098         FREENECT_DEPTH_REGISTERED   = 4, 
00099         FREENECT_DEPTH_MM           = 5, 
00100         FREENECT_DEPTH_DUMMY        = 2147483647, 
00101 } freenect_depth_format;
00102 
00106 typedef struct {
00107         uint32_t reserved;              
00108         freenect_resolution resolution; 
00109         union {
00110                 int32_t dummy;
00111                 freenect_video_format video_format;
00112                 freenect_depth_format depth_format;
00113         };                              
00114         int32_t bytes;                  
00115         int16_t width;                  
00116         int16_t height;                 
00117         int8_t data_bits_per_pixel;     
00118         int8_t padding_bits_per_pixel;  
00119         int8_t framerate;               
00120         int8_t is_valid;                
00121 } freenect_frame_mode;
00122 
00125 typedef enum {
00126         LED_OFF              = 0, 
00127         LED_GREEN            = 1, 
00128         LED_RED              = 2, 
00129         LED_YELLOW           = 3, 
00130         LED_BLINK_GREEN      = 4, 
00131         // 5 is same as 4, LED blink Green
00132         LED_BLINK_RED_YELLOW = 6, 
00133 } freenect_led_options;
00134 
00135 
00137 typedef enum {
00138         TILT_STATUS_STOPPED = 0x00, 
00139         TILT_STATUS_LIMIT   = 0x01, 
00140         TILT_STATUS_MOVING  = 0x04, 
00141 } freenect_tilt_status_code;
00142 
00144 typedef struct {
00145         int16_t                   accelerometer_x; 
00146         int16_t                   accelerometer_y; 
00147         int16_t                   accelerometer_z; 
00148         int8_t                    tilt_angle;      
00149         freenect_tilt_status_code tilt_status;     
00150 } freenect_raw_tilt_state;
00151 
00152 struct _freenect_context;
00153 typedef struct _freenect_context freenect_context; 
00155 struct _freenect_device;
00156 typedef struct _freenect_device freenect_device; 
00158 // usb backend specific section
00159 #ifdef _WIN32
00160   /* frees Windows users of the burden of specifying the path to <libusb-1.0/libusb.h> */
00161   typedef void freenect_usb_context;
00162 #else
00163   #include <libusb-1.0/libusb.h>
00164   typedef libusb_context freenect_usb_context; 
00165 #endif
00166 //
00167 
00169 #ifndef _WIN32
00170   #define FREENECTAPI 
00171 #else
00172 
00173   #ifdef __cplusplus
00174     #define FREENECTAPI extern "C" __declspec(dllexport)
00175   #else
00176     // this is required when building from a Win32 port of gcc without being
00177     // forced to compile all of the library files (.c) with g++...
00178     #define FREENECTAPI __declspec(dllexport)
00179   #endif
00180 #endif
00181 
00183 typedef enum {
00184         FREENECT_LOG_FATAL = 0,     
00185         FREENECT_LOG_ERROR,         
00186         FREENECT_LOG_WARNING,       
00187         FREENECT_LOG_NOTICE,        
00188         FREENECT_LOG_INFO,          
00189         FREENECT_LOG_DEBUG,         
00190         FREENECT_LOG_SPEW,          
00191         FREENECT_LOG_FLOOD,         
00192 } freenect_loglevel;
00193 
00203 FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx);
00204 
00212 FREENECTAPI int freenect_shutdown(freenect_context *ctx);
00213 
00215 typedef void (*freenect_log_cb)(freenect_context *dev, freenect_loglevel level, const char *msg);
00216 
00223 FREENECTAPI void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level);
00224 
00232 FREENECTAPI void freenect_set_log_callback(freenect_context *ctx, freenect_log_cb cb);
00233 
00241 FREENECTAPI int freenect_process_events(freenect_context *ctx);
00242 
00253 FREENECTAPI int freenect_process_events_timeout(freenect_context *ctx, struct timeval* timeout);
00254 
00263 FREENECTAPI int freenect_num_devices(freenect_context *ctx);
00264 
00274 FREENECTAPI int freenect_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list);
00275 
00281 FREENECTAPI void freenect_free_device_attributes(struct freenect_device_attributes* attribute_list);
00282 
00291 FREENECTAPI int freenect_supported_subdevices(void);
00292 
00303 FREENECTAPI void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs);
00304 
00316 FREENECTAPI int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index);
00317 
00329 FREENECTAPI int freenect_open_device_by_camera_serial(freenect_context *ctx, freenect_device **dev, const char* camera_serial);
00330 
00338 FREENECTAPI int freenect_close_device(freenect_device *dev);
00339 
00347 FREENECTAPI void freenect_set_user(freenect_device *dev, void *user);
00348 
00356 FREENECTAPI void *freenect_get_user(freenect_device *dev);
00357 
00359 typedef void (*freenect_depth_cb)(freenect_device *dev, void *depth, uint32_t timestamp);
00361 typedef void (*freenect_video_cb)(freenect_device *dev, void *video, uint32_t timestamp);
00362 
00369 FREENECTAPI void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb);
00370 
00377 FREENECTAPI void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb);
00378 
00389 FREENECTAPI int freenect_set_depth_buffer(freenect_device *dev, void *buf);
00390 
00401 FREENECTAPI int freenect_set_video_buffer(freenect_device *dev, void *buf);
00402 
00410 FREENECTAPI int freenect_start_depth(freenect_device *dev);
00411 
00419 FREENECTAPI int freenect_start_video(freenect_device *dev);
00420 
00428 FREENECTAPI int freenect_stop_depth(freenect_device *dev);
00429 
00437 FREENECTAPI int freenect_stop_video(freenect_device *dev);
00438 
00448 FREENECTAPI int freenect_update_tilt_state(freenect_device *dev);
00449 
00457 FREENECTAPI freenect_raw_tilt_state* freenect_get_tilt_state(freenect_device *dev);
00458 
00466 FREENECTAPI double freenect_get_tilt_degs(freenect_raw_tilt_state *state);
00467 
00480 FREENECTAPI int freenect_set_tilt_degs(freenect_device *dev, double angle);
00481 
00490 FREENECTAPI freenect_tilt_status_code freenect_get_tilt_status(freenect_raw_tilt_state *state);
00491 
00501 FREENECTAPI int freenect_set_led(freenect_device *dev, freenect_led_options option);
00502 
00514 FREENECTAPI void freenect_get_mks_accel(freenect_raw_tilt_state *state, double* x, double* y, double* z);
00515 
00521 FREENECTAPI int freenect_get_video_mode_count();
00522 
00531 FREENECTAPI freenect_frame_mode freenect_get_video_mode(int mode_num);
00532 
00541 FREENECTAPI freenect_frame_mode freenect_get_current_video_mode(freenect_device *dev);
00542 
00552 FREENECTAPI freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt);
00553 
00566 FREENECTAPI int freenect_set_video_mode(freenect_device* dev, freenect_frame_mode mode);
00567 
00573 FREENECTAPI int freenect_get_depth_mode_count();
00574 
00583 FREENECTAPI freenect_frame_mode freenect_get_depth_mode(int mode_num);
00584 
00593 FREENECTAPI freenect_frame_mode freenect_get_current_depth_mode(freenect_device *dev);
00594 
00604 FREENECTAPI freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt);
00605 
00615 FREENECTAPI int freenect_set_depth_mode(freenect_device* dev, const freenect_frame_mode mode);
00616 
00617 #ifdef __cplusplus
00618 }
00619 #endif
00620 
00621 #endif //
00622