pwc
[Top] [All Lists]

[pwc] [PATCH] Input device support for webcams

To: Philips Webcam Linux Driver <>
Subject: [pwc] [PATCH] Input device support for webcams
From: Gregor Jasny <>
Date: Mon, 23 Apr 2007 17:23:00 +0200
Hi,

This patch creates an input device for every connected camera.
At the moment key events are only reported if the v4l device is open.

A possible improvement for the future is the control of the LED
via the input framework.

Gregor
This patch creates an input device for every connected camera.
At the moment key events are only reported if the device is open.

A possible improvement for the future is the control of the LED
via the input framework.

Signed-off-by: Gregor Jasny <>
---
Index: pwc.h
===================================================================
--- pwc.h       (revision 142)
+++ pwc.h       (working copy)
@@ -26,6 +26,7 @@
 #define PWC_H
 
 #include <linux/autoconf.h>
+#include <linux/input.h>
 #include <linux/module.h>
 #include <linux/usb.h>
 #include <linux/spinlock.h>
@@ -265,6 +266,7 @@
    int snapshot_button_status;         /* set to 1 when the user push the 
button, reset to 0 when this value is read */
 
    /*** Misc. data ***/
+   struct input_dev *input;                    /* input handle */
    wait_queue_head_t frameq;           /* When waiting for a frame to 
finish... */
 #if PWC_INT_PIPE
    void *usb_int_handler;              /* for the interrupt endpoint */
Index: pwc-if.c
===================================================================
--- pwc-if.c    (revision 142)
+++ pwc-if.c    (working copy)
@@ -65,6 +65,7 @@
 #include <linux/version.h>
 #include <asm/io.h>
 #include <linux/moduleparam.h>
+#include <linux/usb/input.h>
 
 #include "pwc.h"
 #include "pwc-ioctl.h"
@@ -173,6 +174,8 @@
        .minor =        -1,
 };
 
+static const unsigned int BUTTON = BTN_MISC;
+
 /***************************************************************************/
 
 /* Okay, this is some magic that I worked out and the reasoning behind it...
@@ -618,6 +621,22 @@
                                pdev->vframe_count);
 }
 
+static void pwc_snapshot_button(struct pwc_device *pdev, int down)
+{
+       if (down) {
+               PWC_TRACE("Snapshot button pressed.\n");
+               pdev->snapshot_button_status = 1;
+       }
+       else {
+               PWC_TRACE("Snapshot button released.\n");
+       }
+
+       if (pdev->input) {
+               input_report_key(pdev->input, BUTTON, !!down);
+               input_sync(pdev->input);
+       }
+}
+
 static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct 
pwc_frame_buf *fbuf)
 {
        int awake = 0;
@@ -635,13 +654,7 @@
                        pdev->vframes_error++;
                }
                if ((ptr[0] ^ pdev->vmirror) & 0x01) {
-                       if (ptr[0] & 0x01) {
-                               pdev->snapshot_button_status = 1;
-                               PWC_TRACE("Snapshot button pressed.\n");
-                       }
-                       else {
-                               PWC_TRACE("Snapshot button released.\n");
-                       }
+                       pwc_snapshot_button(pdev, ptr[0] & 0x01);
                }
                if ((ptr[0] ^ pdev->vmirror) & 0x02) {
                        if (ptr[0] & 0x02)
@@ -665,12 +678,7 @@
        else if (pdev->type == 740 || pdev->type == 720) {
                unsigned char *ptr = (unsigned char *)fbuf->data;
                if ((ptr[0] ^ pdev->vmirror) & 0x01) {
-                       if (ptr[0] & 0x01) {
-                               pdev->snapshot_button_status = 1;
-                               PWC_TRACE("Snapshot button pressed.\n");
-                       }
-                       else
-                               PWC_TRACE("Snapshot button released.\n");
+                       pwc_snapshot_button(pdev, ptr[0] & 0x01);
                }
                pdev->vmirror = ptr[0] & 0x03;
        }
@@ -1776,6 +1784,21 @@
        pwc_set_leds(pdev, 0, 0);
        pwc_camera_power(pdev, 0);
 
+       /* register input device */
+       pdev->input = input_allocate_device();
+       if (pdev->input) {
+               pdev->input->name = name;
+               usb_to_input_id(pdev->udev, &(pdev->input->id) );
+
+               pdev->input->evbit[0] = BIT(EV_KEY);
+               pdev->input->keybit[LONG(BUTTON)] = BIT(BUTTON);
+
+               if (input_register_device(pdev->input) != 0) {
+                       input_free_device(pdev->input);
+                       pdev->input = 0;
+               }
+       }
+
        return 0;
 }
 
@@ -1817,6 +1840,12 @@
        pwc_remove_sysfs_files(pdev->vdev);
        video_unregister_device(pdev->vdev);
 
+       if (pdev->input) {
+               input_unregister_device(pdev->input);
+               input_free_device(pdev->input);
+               pdev->input = 0;
+       }
+
        /* Free memory (don't set pdev to 0 just yet) */
        kfree(pdev);
 
_______________________________________________
pwc mailing list

http://lists.saillard.org/mailman/listinfo/pwc
<Prev in Thread] Current Thread [Next in Thread>
  • [pwc] [PATCH] Input device support for webcams, Gregor Jasny <=
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU