Skip to main content

Posts

Showing posts from May, 2009

Logitech Pan/Tilt Python C Extension

I just started learning C++ in earnest about a month ago. This weekend I felt like I knew enough to start looking at Python C extensions, so I wrote one to control the pan and tilt functions of my Logitech Orbit . I used this camera previously for my OLPC telepresence project. There's already a similar module out there, called lpantilt , that does this using Cython . But, I wanted to take a crack at it myself and do it with straight C. #include <Python.h> #include <errno.h> #include <sys/ioctl.h> #include <fcntl.h> #include "linux/videodev2.h" #include "uvcvideo.h" static int pantilt(int pan, int tilt, int reset) { struct v4l2_ext_control xctrls[2]; struct v4l2_ext_controls ctrls; if (reset) { xctrls[0].id = V4L2_CID_PAN_RESET; xctrls[0].value = 1; xctrls[1].id = V4L2_CID_TILT_RESET; xctrls[1].value = 1; } else { xctrls[0].id = V4L2_CID_PAN_RELATIVE; xctrls[0].value = pan; xctrls[1].id = V4L2_CID_TILT_RELATIVE;
Read more