diff options
Diffstat (limited to 'freenect-server--kinect.c')
-rw-r--r-- | freenect-server--kinect.c | 38 |
1 files changed, 33 insertions, 5 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; |