diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-03-15 19:02:07 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-03-15 19:02:07 -0400 |
commit | f2d334a486f1fb6b5a942f32a8314579cac89082 (patch) | |
tree | 7eb941a20182ad24a30b75e484f77f8a5bfd2773 | |
parent | 34aa7d88c470a96b476bc11a5aacb364cc9bfad3 (diff) |
implement the accelerometer stream
-rw-r--r-- | freenect-server--kinect.c | 38 | ||||
-rw-r--r-- | freenect-server.sh | 6 |
2 files changed, 36 insertions, 8 deletions
diff --git a/freenect-server--kinect.c b/freenect-server--kinect.c index 32b029d..e6c9e7e 100644 --- a/freenect-server--kinect.c +++ b/freenect-server--kinect.c @@ -59,11 +59,42 @@ void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp UNUSED, void *data_anon, } } + void handle_accel(freenect_device *dev UNUSED, freenect_raw_tilt_state* data) { - double x, y, z; + double x, y, z, angle; freenect_get_mks_accel(data, &x, &y, &z); - //fprintf(accel_stream, "x=%f\ty=%f\tz=%f\n", x, y, z); + angle = freenect_get_tilt_degs(data); + + const char *motor; + switch (data->tilt_status) { + case TILT_STATUS_STOPPED: + motor = "stopped"; + case TILT_STATUS_LIMIT: + motor = "limit"; + case TILT_STATUS_MOVING: + motor = "moving"; + default: + motor = "unknown"; + } + + char *json = NULL; + int len = asprintf(&json, + "{ \"x\": %f,\n" + " \"y\": %f,\n" + " \"z\": %f,\n" + " \"angle\": %f,\n" + " \"motor\": \"%s\" }\n", + x, y, z, angle, motor); + if (len < 0) + error(EXIT_FAILURE, errno, "asprintf"); + fprintf(accel_stream, + "--ffserver\r\n" + "Content-type: application/json\r\n" + "Content-length: %d\r\n" + "\r\n" + "%s\r\n", + len, json); } void handle_depth(freenect_device *dev UNUSED, void *depth, uint32_t timestamp) @@ -177,9 +208,6 @@ int main(int argc, char *argv[]) { freenect_set_depth_callback(dev, handle_depth); } - if (accel_stream) { - } - while (freenect_process_events(ctx) >= 0) { if (accel_stream) { freenect_raw_tilt_state* state; diff --git a/freenect-server.sh b/freenect-server.sh index 9328573..e88acbe 100644 --- a/freenect-server.sh +++ b/freenect-server.sh @@ -9,10 +9,10 @@ mkfifo $t/video.rgb24 mkfifo $t/depth.rgb24 mkfifo $t/video.mjpg mkfifo $t/depth.mjpg +mkfifo $t/accel.mjson -( freenect-server--kinect -v $t/video.rgb24 -d $t/depth.rgb24; echo "EXITED: freenect-server--kinect: $?") & pids+=($!) -( multipart-replace-http-server "$1" "$2" $t/video.mjpg $t/depth.mjpg; echo "EXITED: freenect-server--http: $?") & pids+=($!) -rm -f {depth,video}.{avi,mjpg} +( freenect-server--kinect -v $t/video.rgb24 -d $t/depth.rgb24 -a $t/accel.mjson; echo "EXITED: freenect-server--kinect: $?") & pids+=($!) +( multipart-replace-http-server "$1" "$2" $t/video.mjpg $t/depth.mjpg $t/accel.mjson; echo "EXITED: freenect-server--http: $?") & pids+=($!) ( ffmpeg -loglevel warning -pixel_format rgb24 -s 640x480 -f rawvideo -i $t/video.rgb24 -q:v 1 -f mpjpeg - > $t/video.mjpg; echo "EXITED: ffmpeg video: $?") & pids+=($!) ( ffmpeg -loglevel warning -pixel_format rgb24 -s 640x480 -f rawvideo -i $t/depth.rgb24 -q:v 1 -f mpjpeg - > $t/depth.mjpg; echo "EXITED: ffmpeg depth: $?") & pids+=($!) |