25 package org.openkinect.freenect;
28 import com.sun.jna.ptr.PointerByReference;
30 import java.io.IOException;
31 import java.nio.ByteOrder;
32 import java.nio.ByteBuffer;
33 import java.nio.DoubleBuffer;
38 NativeLibrary.addSearchPath(
"freenect",
"/usr/local/lib");
39 NativeLibrary instance = NativeLibrary.getInstance(
"freenect");
40 System.err.println(
"Loaded " + instance.getName() +
" from " + instance.getFile().getCanonicalPath());
41 Native.register(instance);
42 }
catch (IOException e) {
43 throw new AssertionError(e);
51 PointerByReference ctxPtr =
new PointerByReference();
58 throw new IllegalStateException(
"init() returned " + rval);
82 if (logHandler == null) {
101 PointerByReference devicePtr =
new PointerByReference();
104 throw new IllegalStateException(
"freenect_open_device() returned " + rval);
114 if (eventThread == null || !eventThread.isAlive()) {
121 if (eventThread != null) {
143 private final DoubleBuffer accelX = DoubleBuffer.allocate(1);
144 private final DoubleBuffer accelY = DoubleBuffer.allocate(1);
145 private final DoubleBuffer accelZ = DoubleBuffer.allocate(1);
156 public void callback (Pointer dev, Pointer
depth,
int timestamp) {
163 public void callback (Pointer dev, Pointer
depth,
int timestamp) {
175 this.accel =
new double[3];
207 if (mode.isValid()) {
209 depthBuffer = ByteBuffer.allocateDirect(mode.getFrameSize());
210 depthBuffer.order(ByteOrder.nativeOrder());
212 this.depthMode = mode;
219 if (mode.isValid()) {
221 videoBuffer = ByteBuffer.allocateDirect(mode.getFrameSize());
222 videoBuffer.order(ByteOrder.nativeOrder());
224 this.videoMode = mode;
250 this.accel[0] = accelX.get(0);
251 this.accel[1] = accelY.get(0);
252 this.accel[2] = accelZ.get(0);
272 return new double[]{accelX.get(0), accelY.get(0), accelZ.get(0)};
286 this.videoHandler = null;
301 this.depthHandler = null;
308 private volatile boolean alive =
true;
313 setName(
"FreenectEventThread");
354 private static native
int freenect_init (PointerByReference
ctx, Pointer usb_ctx);
void onMessage(Device dev, LogLevel level, String msg)
static native FrameMode.ByValue freenect_find_video_mode(int res, int fmt)
int startDepth(DepthHandler handler)
static native TiltState freenect_get_tilt_state(NativeDevice dev)
static native void freenect_set_log_callback(NativeContext ctx, NativeLogCallback cb)
static native Pointer freenect_get_user(NativeDevice dev)
static native FrameMode.ByValue freenect_find_depth_mode(int res, int fmt)
static TiltStatus fromInt(int value)
static native FrameMode.ByValue freenect_get_video_mode(int mode_num)
static native int freenect_shutdown(NativeContext ctx)
static native int freenect_set_video_buffer(NativeDevice dev, ByteBuffer buf)
void setVideoFormat(VideoFormat fmt, Resolution res)
DepthHandler depthHandler
static native int freenect_set_depth_mode(NativeDevice dev, FrameMode.ByValue mode)
static native FrameMode.ByValue freenect_get_current_video_mode(NativeDevice dev)
int setTiltAngle(double angle)
static native int freenect_num_devices(NativeContext ctx)
static native int freenect_process_events(NativeContext ctx)
NativeDevice(Pointer ptr, int index)
static native int freenect_stop_video(NativeDevice dev)
static native int freenect_init(PointerByReference ctx, Pointer usb_ctx)
static native void freenect_set_log_level(NativeContext ctx, int level)
static native int freenect_update_tilt_state(NativeDevice dev)
static native void freenect_set_user(NativeDevice dev, Pointer user)
NativeContext(Pointer ptr)
static native int freenect_start_depth(NativeDevice dev)
void setDepthFormat(DepthFormat fmt)
void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp)
VideoHandler videoHandler
static native int freenect_open_device(NativeContext ctx, PointerByReference dev, int index)
static native double freenect_get_tilt_degs(TiltState tiltState)
void setDeviceIndex(int index)
static native byte freenect_get_tilt_status(TiltState tiltState)
static native int freenect_set_video_mode(NativeDevice dev, FrameMode.ByValue mode)
static native int freenect_set_tilt_degs(NativeDevice dev, double angle)
static native int freenect_stop_depth(NativeDevice dev)
static native void freenect_set_video_callback(NativeDevice dev, NativeVideoCallback cb)
EventThread(NativeContext ctx)
static native int freenect_set_led(NativeDevice dev, int option)
Device openDevice(int index)
static native void freenect_get_mks_accel(TiltState tiltState, DoubleBuffer x, DoubleBuffer y, DoubleBuffer z)
static native int freenect_get_video_mode_count()
static freenect_context * ctx
static native int freenect_close_device(NativeDevice dev)
static native int freenect_select_subdevices(NativeContext ctx, int flag)
void setLogHandler(LogHandler handler)
int setLed(LedStatus status)
final NativeLogCallback logCallback
static native int freenect_get_depth_mode_count()
static Context createContext()
static native int freenect_start_video(NativeDevice dev)
static native FrameMode.ByValue freenect_get_current_depth_mode(NativeDevice dev)
static LogLevel fromInt(int value)
static native FrameMode.ByValue freenect_get_depth_mode(int mode_num)
def handler(signum, frame)
void onFrameReceived(FrameMode mode, ByteBuffer frame, int timestamp)
void setLogLevel(LogLevel level)
void setVideoFormat(VideoFormat fmt)
TiltStatus getTiltStatus()
void setDepthFormat(DepthFormat fmt, Resolution res)
int startVideo(VideoHandler handler)
static native void freenect_set_depth_callback(NativeDevice dev, NativeDepthCallback cb)
static native int freenect_set_depth_buffer(NativeDevice dev, ByteBuffer buf)