[media] v4l: uvcvideo: Add support for pan/tilt speed controls
authorVincent Palatin <vpalatin@chromium.org>
Thu, 4 Sep 2014 00:47:48 +0000 (21:47 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Sun, 21 Sep 2014 23:24:42 +0000 (20:24 -0300)
Map V4L2_CID_TILT_SPEED and V4L2_CID_PAN_SPEED to the standard UVC
CT_PANTILT_RELATIVE_CONTROL terminal control request.

Tested by plugging a Logitech ConferenceCam C3000e USB camera
and controlling pan/tilt from the userspace using the VIDIOC_S_CTRL ioctl.
Verified that it can pan and tilt at the same time in both directions.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/usb/uvc/uvc_ctrl.c

index 0eb8210..d2d1755 100644 (file)
@@ -309,9 +309,8 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_PANTILT_RELATIVE_CONTROL,
                .index          = 12,
                .size           = 4,
-               .flags          = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_MIN
-                               | UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES
-                               | UVC_CTRL_FLAG_GET_DEF
+               .flags          = UVC_CTRL_FLAG_SET_CUR
+                               | UVC_CTRL_FLAG_GET_RANGE
                                | UVC_CTRL_FLAG_AUTO_UPDATE,
        },
        {
@@ -391,6 +390,35 @@ static void uvc_ctrl_set_zoom(struct uvc_control_mapping *mapping,
        data[2] = min((int)abs(value), 0xff);
 }
 
+static __s32 uvc_ctrl_get_rel_speed(struct uvc_control_mapping *mapping,
+       __u8 query, const __u8 *data)
+{
+       unsigned int first = mapping->offset / 8;
+       __s8 rel = (__s8)data[first];
+
+       switch (query) {
+       case UVC_GET_CUR:
+               return (rel == 0) ? 0 : (rel > 0 ? data[first+1]
+                                                : -data[first+1]);
+       case UVC_GET_MIN:
+               return -data[first+1];
+       case UVC_GET_MAX:
+       case UVC_GET_RES:
+       case UVC_GET_DEF:
+       default:
+               return data[first+1];
+       }
+}
+
+static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping,
+       __s32 value, __u8 *data)
+{
+       unsigned int first = mapping->offset / 8;
+
+       data[first] = value == 0 ? 0 : (value > 0) ? 1 : 0xff;
+       data[first+1] = min_t(int, abs(value), 0xff);
+}
+
 static struct uvc_control_mapping uvc_ctrl_mappings[] = {
        {
                .id             = V4L2_CID_BRIGHTNESS,
@@ -676,6 +704,30 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
                .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
                .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
        },
+       {
+               .id             = V4L2_CID_PAN_SPEED,
+               .name           = "Pan (Speed)",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = UVC_CT_PANTILT_RELATIVE_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+               .get            = uvc_ctrl_get_rel_speed,
+               .set            = uvc_ctrl_set_rel_speed,
+       },
+       {
+               .id             = V4L2_CID_TILT_SPEED,
+               .name           = "Tilt (Speed)",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = UVC_CT_PANTILT_RELATIVE_CONTROL,
+               .size           = 16,
+               .offset         = 16,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+               .get            = uvc_ctrl_get_rel_speed,
+               .set            = uvc_ctrl_set_rel_speed,
+       },
        {
                .id             = V4L2_CID_PRIVACY,
                .name           = "Privacy",