Find the answer to your Linux question:
Results 1 to 3 of 3
Hello. I created virtual mouse driver according to Essential Linux Device Drivers book. After i wrote coordinates echo x y > /sys/ ... /coordinates into sysfs node, my program generates ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    3

    Virtual mouse driver, possible problems with X11


    Hello. I created virtual mouse driver according to Essential Linux Device Drivers book. After i wrote coordinates echo x y > /sys/ ... /coordinates into sysfs node, my program generates event packets through event interface /dev/input/event5 (i checked this). This event interface is attached to the GPM gpm -m /dev/input/event5 -t evdev. So the code is OK. But mouse don't move. After checking Xorg.0.log i catched this:

    [ 666.521] (II) config/udev: Adding input device (/dev/input/event5)
    [ 666.521] (II) No input driver/identifier specified (ignoring)


    Maybe this is the error which affects my module work? But i don't know how to fix it ... Thanks.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,159
    Review some existing mouse driver code to figure this out. Most drivers have some sort of identification that the kernel can use to map devices to applications that need to use them (such as xorg in your case). Sorry, but this generality is as far as I can advise you...

    P.S. I last wrote a mouse driver for Linux X-windows to control an analog joystick about 10-15 years ago. My remembery is fuzzy...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    May 2013
    Posts
    3
    Thanks for reply. This is the code:

    Code:
    /*
     * A Virtual Mouse Driver to send fake events from userspace.
     *
     * Written by Fred Chien <fred@ullab.org>
     *
     */
    #include <linux/fs.h>
    #include <asm/uaccess.h>
    #include <linux/pci.h>
    #include <linux/input.h>
    #include <linux/platform_device.h>
    
    struct input_dev *virmouse_input_dev;
    static struct platform_device *virmouse_dev; /* Device structure */
    
    /* Sysfs method to input simulated coordinates */
    static ssize_t write_virmouse(struct device *dev,
                                  struct device_attribute *attr,
                                  const char *buffer, size_t count)
    {
            int x, y, key;
    
            /* parsing input data */
            sscanf(buffer, "%d %d", &x, &y);
    
            /* Report relative coordinates */
            input_report_rel(virmouse_input_dev, REL_X, x);
            input_report_rel(virmouse_input_dev, REL_Y, y);
    
            printk ("virmouse_event: X:%d Y:%d\n", x, y);
    
            input_sync(virmouse_input_dev);
    
            return count;
    
    }
    
    /* Attach the sysfs write method */
    DEVICE_ATTR(vmevent, 0644, NULL, write_virmouse);
    
    /* Attribute Descriptor */
    static struct attribute *virmouse_attrs[] = {
            &dev_attr_vmevent.attr,
            NULL
    };
    
    /* Attribute group */
    static struct attribute_group virmouse_attr_group = {
            .attrs = virmouse_attrs,
    };
    
    /* Driver Initializing */
    int __init virmouse_init(void)
    {
            /* Register a platform device */
            virmouse_dev = platform_device_register_simple("virmouse", -1, NULL, 0);
            if (IS_ERR(virmouse_dev)){
                    printk ("virmouse_init: error\n");
                    return PTR_ERR(virmouse_dev);
            }
    
            /* Create a sysfs node to read simulated coordinates */
            sysfs_create_group(&virmouse_dev->dev.kobj, &virmouse_attr_group);
    
            /* Allocate an input device data structure */
            virmouse_input_dev = input_allocate_device();
            if (!virmouse_input_dev) {
                    printk("Bad input_allocate_device()\n");
                    return -ENOMEM;
            }
    
            /* Announce that the virtual mouse will generate relative coordinates */
            set_bit(EV_REL, virmouse_input_dev->evbit);
            set_bit(REL_X, virmouse_input_dev->relbit);
            set_bit(REL_Y, virmouse_input_dev->relbit);
    
            /* Register with the input subsystem */
            input_register_device(virmouse_input_dev);
    
            /* print messages in the dmesg */
            printk("Virtual Mouse Driver Initialized.\n");
    
            return 0;
    }
    
    /* Driver Uninitializing */
    void virmouse_uninit(void)
    {
            /* Unregister from the input subsystem */
            input_unregister_device(virmouse_input_dev);
    
            /* Remove sysfs node */
            sysfs_remove_group(&virmouse_dev->dev.kobj, &virmouse_attr_group);
    
            /* Unregister driver */
            platform_device_unregister(virmouse_dev);
    
            return;
    }
    
    module_init(virmouse_init);
    module_exit(virmouse_uninit);
    
    MODULE_AUTHOR("Fred Chien <fred@ullab.org>");
    MODULE_DESCRIPTION("Virtual Mouse Driver");
    MODULE_LICENSE("GPL");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •