patch to make the imon PAD generate mouse events

Linux support for Soundgraph iMON USB IR/VFD modules used in Ahanix, Silverstone, Uneed, Accent and other cases.

Moderator: Venky

Setting repeat to 0

Postby Tillo » Sat Jul 23, 2005 6:04 pm

Anonymous wrote: ...
begin
prog = freevo
button = Up
config = UP
repeat = 0
end

that stops any repeats from happening at all, when pressing Up within


I wonder why you want to disable repeat completely. I had a problem with the very fast repeats as well and for me a good solution was e.g.:

begin
prog = mythtv
button = right
repeat = 4
delay = 10
config = Right
end

The repeat 4 reduces the speed of the repeats to a useful value and the delay added a nice delay before the first repeat takes place. This way e.g. scrolling through long games lists in mythgame still works like a charm while menus can be controlled as well.
Tillo
 

Combined keyboard/mouse patch for PAD

Postby Tillo » Mon Jul 25, 2005 5:12 am

Hi,

i just combined both patches. The keyboard/mouse button now isn't reported to lirc anymore but it is used to switch between mouse and keyboard mode.

The default start state is keyboard mode (since my box boots directly into mythtv). I agree with datapath, that doing all this inside the imon driver isn't the right way. But it works ... and most people using the pad remote will in fact be doing this with the imon it came with so this approach seems to be acceptible to me.

Anyway, here's the patch (which changes the behaviour of the keyboard emulation a little bit to make it more "responsive"):

Code: Select all
--- lirc_imon.c.old     2005-04-16 20:10:02.000000000 +0200
+++ lirc_imon.c 2005-07-25 01:04:04.406805182 +0200
@@ -53,6 +53,7 @@

#include <linux/errno.h>
#include <linux/init.h>
+#include <linux/input.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -68,7 +69,7 @@
#define MOD_AUTHOR     "Venky Raju <dev@venky.ws>"
#define MOD_DESC       "Driver for Soundgraph iMON MultiMedian IR/VFD"
#define MOD_NAME       "lirc_imon"
-#define MOD_VERSION    "0.3"
+#define MOD_VERSION    "0.3M"

#define VFD_MINOR_BASE 144     /* Same as LCD */
#define DEVFS_MODE     S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
@@ -83,6 +84,7 @@
#define        TRUE            1
#define FALSE          0

+#define CURSOR_LIMIT    2

/* ------------------------------------------------------------
  *                     P R O T O T Y P E S
@@ -160,7 +162,11 @@
                struct completion finished;  /* wait for write to finish  */
                atomic_t busy;               /* write in progress         */
                int status;                  /* status of tx completion   */
+
        } tx;
+
+        int mode_kbd;                        /* keyboard/mouse mode       */
+        struct input_dev mouse;              /* mouse interface           */
};

#define LOCK_CONTEXT   down (&context ->sem)
@@ -573,6 +579,8 @@
        context ->rx.initial_space = 1;
        context ->rx.prev_bit = 0;

+        context ->mode_kbd = 1;                        /* init keyboard mode       */
+
        usb_fill_int_urb (context ->rx_urb, context ->dev,
                usb_rcvintpipe (context ->dev,
                                context ->rx_endpoint-> bEndpointAddress),
@@ -616,7 +624,7 @@

        LOCK_CONTEXT;

-       usb_unlink_urb (context ->rx_urb);
+       usb_kill_urb (context ->rx_urb);
        context ->ir_isopen = FALSE;
        MOD_DEC_USE_COUNT;
        info ("IR port closed");
@@ -701,11 +709,72 @@

        if (context ->ir_onboard_decode) {

-               /* The signals have been decoded onboard the iMON controller */
+         /* The signals have been decoded onboard the iMON controller */

-               lirc_buffer_write_1 (context ->plugin ->rbuf, buf);
-               wake_up (&context ->plugin ->rbuf ->wait_poll);
-               return;
+         if(buf[0] & 0x40) {
+                 int rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6;
+                 int rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6;
+                 if(buf[0] & 0x02) rel_x |= ~0x10+1;
+                 if(buf[0] & 0x01) rel_y |= ~0x10+1;
+
+                 /* keyboard direction key emulation */
+                 if(context->mode_kbd) {
+
+                         if(buf[1] & 0x01 || buf[1] >> 2 & 0x01) {
+                           //              warn("press\n");
+                                 /* mouse pressed */
+                         }
+
+                         if(abs(rel_y) > abs(rel_x)) {
+                                 if(rel_y > CURSOR_LIMIT) { /* mouse s */
+                                         buf[0] = 0x68;
+                                         buf[1] = 0x82;
+                                         buf[2] = 0x91;
+                                 } else if(rel_y < -CURSOR_LIMIT) { /* mouse n */
+                                         buf[0] = 0x69;
+                                         buf[1] = 0x02;
+                                         buf[2] = 0x81;
+                                 } else {
+                                         return; /* discard those key codes */
+                                 }
+
+                         } else {
+                                 if(rel_x > CURSOR_LIMIT) { /* mouse e */
+                                         buf[0] = 0x68;
+                                         buf[1] = 0x8A;
+                                         buf[2] = 0x81;
+                                  } else if(rel_x < -CURSOR_LIMIT) { /* mouse w */
+                                         buf[0] = 0x6A;
+                                         buf[1] = 0x82;
+                                         buf[2] = 0x81;
+                                  } else {
+                                         return; /* discard those key codes */
+                                  }
+                         }
+
+                 } else {
+
+                         /* mouse emulation */
+                          struct input_dev *mouse = &context->mouse;
+                          input_report_key(mouse, BTN_LEFT,   buf[1] & 0x01);
+                          input_report_key(mouse, BTN_RIGHT,  buf[1] >> 2 & 0x01);
+                          input_report_rel(mouse, REL_X,     rel_x);
+                          input_report_rel(mouse, REL_Y,     rel_y);
+                          input_sync(mouse);
+                         return;
+                 }
+         }
+
+         /* mouse/kbd button 29 91 15 b7 */
+         if((buf[0] == 0x29) && (buf[1] == 0x91) && (buf[2] == 0x15) && (buf[3] == 0xb7)) {
+           //            warn("toggle kbd %d -> %d\n", context->mode_kbd, !context->mode_kbd);
+                 context->mode_kbd = !context->mode_kbd;
+                 return;
+         }
+
+         lirc_buffer_write_1 (context ->plugin ->rbuf, buf);
+         wake_up (&context ->plugin ->rbuf ->wait_poll);
+         return;
        }

        /*
@@ -1082,6 +1151,22 @@
#endif
        }

+       /* register with kernel input system for PAD mouse */
+       context->mouse.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+       context->mouse.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
+       context->mouse.relbit[0] = BIT(REL_X) | BIT(REL_Y);
+       context->mouse.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA);
+       context->mouse.relbit[0] |= BIT(REL_WHEEL);
+       context->mouse.private = context;
+
+       context->mouse.id.bustype = BUS_USB;
+       context->mouse.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
+       context->mouse.id.product = le16_to_cpu(dev->descriptor.idProduct);
+       context->mouse.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
+       context->mouse.dev = &dev->dev;
+
+       input_register_device(&context->mouse);
+
        info ("%s: iMON device on usb<%d:%d> initialized",
                        __FUNCTION__, dev ->bus ->busnum, dev ->devnum);

@@ -1125,12 +1210,12 @@
        context ->dev_present = FALSE;

        /* Stop reception */
-       usb_unlink_urb (context ->rx_urb);
+       usb_kill_urb (context ->rx_urb);

        /* Abort ongoing write */
        if (atomic_read (&context ->tx.busy)) {

-               usb_unlink_urb (context ->tx_urb);
+               usb_kill_urb (context ->tx_urb);
                wait_for_completion (&context ->tx.finished);
        }

@@ -1147,6 +1232,8 @@
#endif
        }

+       input_unregister_device (&context ->mouse);
+
        UNLOCK_CONTEXT;

        if (!context ->ir_isopen && !context ->vfd_isopen)

Tillo
 

Re: Combined keyboard/mouse patch for PAD

Postby andrea_ap » Tue Jul 26, 2005 6:59 pm

I'm a newbie, can you explain to me how to apply this patch to lirc_imon.c?

andrea

Tillo wrote:Hi,
i just combined both patches. The keyboard/mouse button now isn't reported to lirc anymore but it is used to switch between mouse and keyboard mode.
andrea_ap
 

Re: Combined keyboard/mouse patch for PAD

Postby Tillo » Wed Jul 27, 2005 4:48 am

andrea_ap wrote:I'm a newbie, can you explain to me how to apply this patch to lirc_imon.c?


Usually you take a .patch file and go to the directory with the original file and do a "patch -p0 <filename.patch".

But this may perhaps not work with patches sent though this forum, since they loose their exact formatting when being posted. I currently don't have access to the original patch file but will upload it to some server once i am home again.

Till
Tillo
 

Patch download

Postby Tillo » Mon Aug 01, 2005 4:04 am

Hi,

you can get my combined imon mouse/keyboard patch from http://www.harbaum.org/till/twonky/pad_mouse_kbd.patch.

To apply the patch get the lirc-0.7.1 source tarball, copy the patch to the drivers/lirc_imon directory. Change to that directory, type patch -p0 <pad_mouse_kbd.patch and continue with the installation of lirc as usual.

Tillo
Tillo
 

Postby DataPath » Mon Aug 01, 2005 10:32 pm

Here's my current plan - Venky, let me know what you think.

Move most of the work of the USB driver into a driver below the lirc_imon driver.

So we have a usbimon driver that is neither lcdproc-specific on the VFD side, nor lirc-specific on the IR side.

The usbimon driver allows client drivers to register to receive IR data, giving a callback, a bitmask, and a match-value. It allows the client driver to say "I accept all remotes whose data looks like this".

lirc_imon would be a client to this that says "I accept *ALL* remotes".
imon_pad would be a client to this that says "I accept remotes where when this bitmask is applied, this match-value results"

usbimon counts up the size of the mask, and assigns a priority to the client. Very specific clients have higher priority, and very broad clients have lower priority.

usbimon receives some IR data, and goes down the chain of registered clients, highest priority first.


Code: Select all
current_handler = imon_pad
if((data & bit_mask) == match_value)
{
    current_handler(buffer);
}
current_handler = lirc_imon
if((data & bit_mask) == match_value)
{
    current_handler(buffer);
}


Pros:
* It gets VFD code out of the lirc_imon driver
* The lirc_imon driver gets very simple
* It's very easy to gain access to the remote by other means than lirc

Cons:
* I think the lirc_imon driver gets TOO simple, very thin wrapper
* Too many drivers getting loaded into the kernel - yeah, they're small, but do you really need (for example) 5 different drivers to support a single USB device?

One thing that I think would be interesting in the long run is a replacement for lirc that uses DBUS. But that's WAAY too big a project for me to be trying to pick up anytime soon[/quote]
DataPath
 
Posts: 34
Joined: Thu Mar 24, 2005 2:16 pm
Location: ::1

Postby Venky » Sat Aug 20, 2005 10:56 am

Hi DataPath,
Sorry about the delay in responding. Just to make sure we're on the same page you are proposing a 2-level driver structure - the lower level driver just interfaces with the imon device at the USB level, and there may be multiple upper level drivers, e.g. lirc, mouse, vfd, etc. And the lirc_dev driver is a driver above this 2-level structure.

I think it is a good idea. At the moment my day job doesn't leave me with any time to work on this new idea - if you would like to take it up I will be happy to assist in testing, etc. Let's leave the current driver as is and set this up as new set of drivers.

Cheers,
Venky
Venky
 
Posts: 145
Joined: Tue Jun 29, 2004 7:55 pm

Postby DataPath » Tue Aug 23, 2005 8:53 am

No problem.

I'd be happy to work on it. In fact, it shouldn't be too much work, as it would be essentially the current lirc_imon driver, with the lirc interface stripped out, and a reservation and callback system added in in place of it.

One really nice advantage to this is a chance at inclusion in the kernel source tree.
DataPath
 
Posts: 34
Joined: Thu Mar 24, 2005 2:16 pm
Location: ::1

Postby Pivert » Sun Sep 04, 2005 3:10 pm

Hi !

Why do I have this error ?

homer lirc_imon # patch lirc_imon.c lirc_imon_plus_mouse.patch
patching file lirc_imon.c
Hunk #2 FAILED at 162.
Hunk #3 FAILED at 619.
Hunk #4 FAILED at 703.
Hunk #5 FAILED at 1102.
Hunk #6 FAILED at 1161.
Hunk #7 FAILED at 1183.
6 out of 7 hunks FAILED -- saving rejects to file lirc_imon.c.rej
homer lirc_imon #

Regards,
Pivert
 

Postby Guest » Sun Sep 04, 2005 4:06 pm

Sorry, Was using the wrong patch.
Sometimes, at the beginning the mouse is self clicking... but it's totally usable.

Great work !
Guest
 

Repeat problems

Postby Lasse » Sat Sep 17, 2005 9:02 am

Hello, I've been having the repeat problems described in http://venky.ws/forums/viewtopic.php?p=413#413

Even with Tillo's newest patch http://venky.ws/forums/viewtopic.php?p=514#514, the problem still exists.

So I made this patch to work around the problem. I don't think it's the right way to do it, but since it's an annoyance maybe someone wants to use it until a better solution comes around :).
Lasse
 

Repeat patch

Postby Lasse » Sat Sep 17, 2005 9:04 am

well, maybe it's a good idea actually to provide the patch :)

    --- lirc_imon.c.old 2005-09-17 15:46:37.000000000 +0200
    +++ lirc_imon.c 2005-09-17 15:55:38.000000000 +0200
    @@ -676,6 +676,28 @@
    return;
    }

    +#define FLATTENER 3
    +static inline int IsGenuine(unsigned char *buf) {
    + static unsigned char flat[FLATTENER][3];
    + int count = 0;
    + int i;
    + for(i = 0; i < FLATTENER ; ++i) {
    + if(memcmp(flat[i],buf,3) == 0) {
    + count++;
    + }
    + }
    + for(i = 0 ; i < FLATTENER-1 ; ++i) {
    + memcpy(flat[i],flat[i+1],3);
    + }
    + memcpy(flat[FLATTENER-1],buf,3);
    +
    + if(count > FLATTENER/2) {
    + return 1; /* More than half of the codes should be == buf. */
    + } else {
    + return 0;
    + }
    +}
    +
    /**
    * Process the incoming packet
    */
    @@ -752,6 +774,11 @@
    }
    }

    + /* Only accept button if it's not a ``accident'', this avoid
    + problem with accidently pressed buttons. */
    + if(IsGenuine(buf) == 0) { return; }
    + buf[3] = 0xb7; /* The fourth byte sometimes varies, why?
    + this avoids problems with repeat. */
    } else {

    /* mouse emulation */
Lasse
 

Tillo

Postby Paul » Thu Oct 20, 2005 9:28 am

I have been using tillo's patch from his website when running irw i get all the keys and can switch between mouse and keyboard and the pad works fine. However when i stop running irw the mouse mode stops working. Does anybody have any info on why this is?

Cheers
Paul
 

Postby fromans4 » Fri Nov 25, 2005 11:59 pm

First let me say hello to all. I am new to this forum and LIRC. I have a Silverstone LC10M and I am running FC4 fully updated. I downloaded and installed LIRC 0.7.2 and the associated LCD drivers and installed everything as per all of the documentation. It took some effort and some help via browsing this forum, but I got the remote and the LCD display working!

I have been having a lot of problems with the imon-pad mouse function of the remote. I tried the patches referrenced in this thread but when I try to apply them it says they are already applied. I am guessing that I am using a version of LIRC that is new enough to include some or all of these patches discussed here. However the mouse functions don't work.

When I run "irw" and press the mouse=pad I onlt get intermitant output by pressing in the down direction. No other direction gives me any output.

Any help would be apreciated.

Thanks,
Brent
fromans4
 
Posts: 28
Joined: Fri Nov 25, 2005 9:49 pm
Location: Northern California

patch for CVS lirc 0.8

Postby shan » Tue Nov 29, 2005 2:01 am

I am also freevo user and really would like to have that pad work as up down left right buttons.

But I failed to apply that patch, I think it's for 7.2. Is there patch for newer lircs?
// Sami
shan
 
Posts: 5
Joined: Mon Nov 28, 2005 5:21 am
Location: Finland

PreviousNext

Return to Soundgraph iMON IR/VFD Modules

Who is online

Users browsing this forum: No registered users and 0 guests

cron