[media] gspca_cpia1: Add support for button

Not only the qx3 microscope has a button, but some cameras too. Tested
with the Trust sp@cecam 100 (and with a creative and ezcam without button).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans de Goede 2011-03-13 12:26:14 -03:00 committed by Mauro Carvalho Chehab
parent c05df8b32a
commit c2f644aeeb
1 changed files with 26 additions and 5 deletions

View File

@ -28,6 +28,7 @@
#define MODULE_NAME "cpia1"
#include <linux/input.h>
#include "gspca.h"
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
@ -653,10 +654,15 @@ static int do_command(struct gspca_dev *gspca_dev, u16 command,
break;
case CPIA_COMMAND_ReadMCPorts:
if (!sd->params.qx3.qx3_detected)
break;
/* test button press */
sd->params.qx3.button = ((gspca_dev->usb_buf[1] & 0x02) == 0);
a = ((gspca_dev->usb_buf[1] & 0x02) == 0);
if (a != sd->params.qx3.button) {
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
input_report_key(gspca_dev->input_dev, KEY_CAMERA, a);
input_sync(gspca_dev->input_dev);
#endif
sd->params.qx3.button = a;
}
if (sd->params.qx3.button) {
/* button pressed - unlock the latch */
do_command(gspca_dev, CPIA_COMMAND_WriteMCPort,
@ -1738,6 +1744,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
static void sd_stopN(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
command_pause(gspca_dev);
/* save camera state for later open (developers guide ch 3.5.3) */
@ -1748,6 +1756,17 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
/* Update the camera status */
do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
/* If the last button state is pressed, release it now! */
if (sd->params.qx3.button) {
/* The camera latch will hold the pressed state until we reset
the latch, so we do not reset sd->params.qx3.button now, to
avoid a false keypress being reported the next sd_start */
input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
input_sync(gspca_dev->input_dev);
}
#endif
}
/* this function is called at probe and resume time */
@ -1852,8 +1871,7 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev)
/* Update our knowledge of the camera state */
do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
if (sd->params.qx3.qx3_detected)
do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
}
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
@ -2085,6 +2103,9 @@ static const struct sd_desc sd_desc = {
.dq_callback = sd_dq_callback,
.pkt_scan = sd_pkt_scan,
.querymenu = sd_querymenu,
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
.other_input = 1,
#endif
};
/* -- module initialisation -- */