summaryrefslogtreecommitdiff
path: root/freenect-server--kinect.c
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-03-15 19:02:07 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-03-15 19:02:07 -0400
commitf2d334a486f1fb6b5a942f32a8314579cac89082 (patch)
tree7eb941a20182ad24a30b75e484f77f8a5bfd2773 /freenect-server--kinect.c
parent34aa7d88c470a96b476bc11a5aacb364cc9bfad3 (diff)
implement the accelerometer stream
Diffstat (limited to 'freenect-server--kinect.c')
-rw-r--r--freenect-server--kinect.c38
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;