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

Post Reply
Guest

Re: Cleaned-up patch for lirc-0.8.0 and kernel 2.6.15

Post by Guest » Fri Mar 24, 2006 10:09 pm

IndieRockSteve wrote: SiliconFiend, your patch fails 7 of 9 hunks for a clean 0.8.0 source.

but I applied it manually and it builds fine.

Is there a way to easily disable the mouse mode so it only works in the "keyboard" mode? I'm using it my case with MythTV so I have no need for the mouse mode and if I can easily disable it I'd like to.

thanks!
Hmm... Well, my Myth computer is down right now (power supply is out on RMA) so I can't try the patch, but I generated it from source downloaded through Gentoo portage. I assumed it was the same as the original (typically Gentoo applies custom patches after the source tarball is unpacked), but maybe it's not. When I get the computer back up, I'll try it again and see if I can clean it up and repost. Disabling the mouse/keyboard button shouldn't be a big deal, but I don't know why you don't just ignore it if you don't want to use it...

Guest

Re: Cleaned-up patch for lirc-0.8.0 and kernel 2.6.15

Post by Guest » Sat Mar 25, 2006 11:22 am

Anonymous wrote:Hmm... Well, my Myth computer is down right now (power supply is out on RMA) so I can't try the patch, but I generated it from source downloaded through Gentoo portage. I assumed it was the same as the original (typically Gentoo applies custom patches after the source tarball is unpacked), but maybe it's not. When I get the computer back up, I'll try it again and see if I can clean it up and repost. Disabling the mouse/keyboard button shouldn't be a big deal, but I don't know why you don't just ignore it if you don't want to use it...
your right, it seems to default to the cursor mode, it feels a little more finicky than the older patches in that sometimes hitting left or right tips a little to the top/bottom but that may just be my remote, I just never noticed it with the older patches.

I can make a diff from my manual edit from the source tarball. Have you thought of submitting the patch to the lirc team?

SiliconFiend

Re: Cleaned-up patch for lirc-0.8.0 and kernel 2.6.15

Post by SiliconFiend » Sat Mar 25, 2006 10:32 pm

Anonymous wrote:
Anonymous wrote:Hmm... Well, my Myth computer is down right now (power supply is out on RMA) so I can't try the patch, but I generated it from source downloaded through Gentoo portage. I assumed it was the same as the original (typically Gentoo applies custom patches after the source tarball is unpacked), but maybe it's not. When I get the computer back up, I'll try it again and see if I can clean it up and repost. Disabling the mouse/keyboard button shouldn't be a big deal, but I don't know why you don't just ignore it if you don't want to use it...
your right, it seems to default to the cursor mode, it feels a little more finicky than the older patches in that sometimes hitting left or right tips a little to the top/bottom but that may just be my remote, I just never noticed it with the older patches.

I can make a diff from my manual edit from the source tarball. Have you thought of submitting the patch to the lirc team?
I see that I didn't enter my user name for the last message. Apparently that's started to be a problem on this form, according to some of the messages I've read. Anyway, I can't claim it as my patch. I've done some minor editing to the patch (originally by DataPath, I think) and I generally understand what it's doing, but I didn't come up with the idea.

As far as submitting it to the LIRC team, I dunno. Since it creates an input device for the mouse, etc. I don't know if it fits with their general philosophy of the driver structure. This driver works for us, but it really should be factored more for general use.

SiliconFiend

Post by SiliconFiend » Thu Mar 30, 2006 2:03 pm

Okay, I got my Myth computer running again. I tried the patch I had emailed and I got the same results (7 of 9 hunks failed). However, I diffed it with the original, working patch (using the -b option to ignore changes in whitespace) and it's identical. So, it's a whitespace problem, probably for the context lines. My problem is that I can't easily send email from that box, so I cat'd it to my SSH and then pasted into a text editor in windows. I will try to re-send the original for Matteo.

SiliconFiend

Post by SiliconFiend » Thu Mar 30, 2006 2:59 pm

Aha! While I was going through this fixing the whitespace problems for my emailed patch file, I discovered a little bug with the left arrow (MOUSE_KEY_W). My wife had complained that it was sluggish moving left, and I think I found the reason why. I'll post the fixed patch in a while. The astute readers may find the problem themselves.

marioz

Post by marioz » Fri Mar 31, 2006 12:23 am

Hi to all :) I'm looking for a solution of my problem. I'm a linux newbie but I falt in love with VDR and I assembled an HTPC using silverstone LC10M case with iMon remote. Now the VFD is working well but I can't configure lirc to work :cry: . I already tried a lot of stuff (download, compile etc.) The situation right now is. I can load the module and lircd is working but using irw I can see a stange (at least for me) behaviour when I press a button (and eventually I hold it) I get the right code but when I release it I get a different (just 1 byte) code so I can't configure VDR to work
I also tried to applied the patch posted here but I had some errors
patching file lirc_imon.c
Hunk #1 FAILED at 53.
Hunk #2 FAILED at 69.
Hunk #3 succeeded at 688 with fuzz 2 (offset 604 lines).
Hunk #4 FAILED at 726.
Hunk #5 FAILED at 776.
Hunk #6 FAILED at 1201.
Hunk #7 FAILED at 1331.
Hunk #8 FAILED at 1799.
patch unexpectedly ends in middle of line
Hunk #9 FAILED at 1897.
8 out of 9 hunks FAILED -- saving rejects to file lirc_imon.c.rej
My actual configuration is linvdr with 2.6.15 kernel and lirc 0.8

thanks in advance for any help

michaelb
Posts: 10
Joined: Tue Mar 28, 2006 11:04 pm

Post by michaelb » Sun Apr 02, 2006 1:56 am

IndieRockSteve wrote:would it be possible to get a patch like the one "notz" posted, with no mouse support, and only 4 direction pad control with whatever updated changes/fixes the newer patches have? I'm using it with MythTV so I don't need a mouse, and I only need 4 directions, but I'd like to be able to use the other mouse buttons by remapping them for other functions.

thanks!
Try this: http://brakemeier.de/ below LIRC iMON Patches.
Please report all bugs.

@all: I'd like to mention the original author of this patch...but who is the original author :?:

SiliconFiend
Posts: 40
Joined: Sun Apr 02, 2006 5:45 pm

Patch with fixed left arrow

Post by SiliconFiend » Sun Apr 02, 2006 5:48 pm

SiliconFiend wrote:Aha! While I was going through this fixing the whitespace problems for my emailed patch file, I discovered a little bug with the left arrow (MOUSE_KEY_W). My wife had complained that it was sluggish moving left, and I think I found the reason why. I'll post the fixed patch in a while. The astute readers may find the problem themselves.
Okay, here's the patch yet again with the left arrow bug fixed.

Code: Select all

diff -NarU5 lirc-0.8.0/drivers/lirc_imon/lirc_imon.c lirc-0.8.0.newpatch/drivers/lirc_imon/lirc_imon.c
--- lirc-0.8.0/drivers/lirc_imon/lirc_imon.c	2005-12-03 07:18:07.000000000 -0800
+++ lirc-0.8.0.newpatch/drivers/lirc_imon/lirc_imon.c	2006-03-30 22:59:19.000000000 -0800
@@ -51,10 +51,11 @@
 
 #include <linux/config.h>
 
 #include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/input.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <asm/uaccess.h>
 #include <linux/usb.h>
@@ -66,11 +67,11 @@
 
 
 #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
 #define DEVFS_NAME	LIRC_DEVFS_PREFIX "lcd%d"
 
@@ -81,10 +82,11 @@
 
 #define SUCCESS		0
 #define	TRUE		1
 #define FALSE		0
 
+#define CURSOR_LIMIT	16	    
 
 /* ------------------------------------------------------------
  *                     P R O T O T Y P E S
  * ------------------------------------------------------------
  */
@@ -116,10 +118,18 @@
 
 /* Driver init/exit prototypes */
 static int __init imon_init (void);
 static void __exit imon_exit (void);
 
+typedef enum {
+  MOUSE_KEY_NONE,
+  MOUSE_KEY_N,
+  MOUSE_KEY_E,
+  MOUSE_KEY_S,
+  MOUSE_KEY_W
+} pad_key_t;
+
 /* ------------------------------------------------------------
  *                     G L O B A L S
  * ------------------------------------------------------------
  */
 
@@ -158,11 +168,21 @@
 	struct tx_t {
 		unsigned char data_buf [35]; /* user data buffer          */
 		struct completion finished;  /* wait for write to finish  */
 		atomic_t busy;		     /* write in progress         */
 		int status;		     /* status of tx completion   */
+
 	} tx;
+	int key_x;
+	int key_y;
+	int mode_kbd;			     /* keyboard/mouse mode       */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
+	struct input_dev mouse;		     /* mouse interface           */
+#else
+	struct input_dev * mouse;	     /* mouse interface           */
+#endif
+	int last_count;			     /* number of times pressed   */
 };
 
 #define LOCK_CONTEXT	down (&context ->sem)
 #define UNLOCK_CONTEXT	up (&context ->sem)
 
@@ -572,10 +592,15 @@
 
 	/* initial IR protocol decode variables */
 	context ->rx.count = 0;
 	context ->rx.initial_space = 1;
 	context ->rx.prev_bit = 0;
+	context ->key_x = 0;                        
+	context ->key_y = 0;                     
+	context ->last_count = 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),
 		context ->usb_rx_buf, sizeof (context ->usb_rx_buf),
@@ -701,11 +726,96 @@
 	}
 #endif
 
 	if (context ->ir_onboard_decode) {
 
-		/* The signals have been decoded onboard the iMON controller */
+	/* The signals have been decoded onboard the iMON controller */
+
+		/* mouse pad */
+	  	if(buf[0] & 0x40) {
+			pad_key_t key;
+			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( context->last_count > 32 )
+				{  /* Hopefully eliminate drift*/
+					context->last_count=0;
+					context->key_y=0;
+					context->key_x=0;
+				}
+				context->last_count++;
+				if(buf[1] & 0x01 || buf[1] >> 2 & 0x01) {
+				//	warn("press\n");
+				/* mouse pressed */
+				}
+
+				if(abs(context->key_x) > CURSOR_LIMIT
+				|| abs(context->key_y) > CURSOR_LIMIT ) {
+					if(abs(context->key_y)> abs(context->key_x)) { 
+					/* mouse s/n */
+						if(context->key_y > 0 && rel_y > 0) { /* mouse s */
+							key = MOUSE_KEY_S;
+							buf[0] = 0x68;
+							buf[1] = 0x82;
+							buf[2] = 0x91;
+						} else if(context->key_y < 0 && rel_y < 0) { /* mouse n */
+							key = MOUSE_KEY_N;
+							buf[0] = 0x69;
+							buf[1] = 0x02;
+							buf[2] = 0x81;
+						}
+					} else {
+					/*mouse e/w*/
+						if(context->key_x > 0 && rel_x > 0) { /* mouse e */
+							key = MOUSE_KEY_E;
+							buf[0] = 0x68;
+							buf[1] = 0x8A;
+							buf[2] = 0x81;
+						} else if(context->key_x < 0 && rel_x < 0) { /* mouse w */
+							key = MOUSE_KEY_W;
+							buf[0] = 0x6A;
+							buf[1] = 0x82;
+							buf[2] = 0x81;
+						}
+					}
+				}
+				else {
+					context->key_x += rel_x;
+					context->key_y += rel_y;
+					return; /* discard those key codes */
+				}
+			} else {
+			/* mouse emulation */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
+				struct input_dev *mouse = &context->mouse;
+#else
+				struct input_dev *mouse = context->mouse;
+#endif
+				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;
+			}
+		}
+
+		/* a key was pressed or a synthetic mouse key let through,
+		 * so reset count */
+		context->key_x = 0;
+		context->key_y = 0;
+		context->last_count = 0;
+		/* 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,10 +1192,43 @@
 					__FUNCTION__);
 		}
 #endif
 	}
 
+	/* register with kernel input system for PAD mouse */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
+	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);
+#else
+	context->mouse = input_allocate_device();
+	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);
+#endif
 	info ("%s: iMON device on usb<%d:%d> initialized",
 			__FUNCTION__, dev ->bus ->busnum, dev ->devnum);
 
 	UNLOCK_CONTEXT;
 exit:
@@ -1147,10 +1290,15 @@
 		if (context ->devfs)
 			devfs_unregister (context ->devfs);
 #endif
 	}
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
+	input_unregister_device (&context ->mouse);
+#else
+	input_unregister_device (context ->mouse);
+#endif
 	UNLOCK_CONTEXT;
 
 	if (!context ->ir_isopen && !context ->vfd_isopen)
 		delete_context (context);

IndieRockSteve
Posts: 16
Joined: Tue Nov 15, 2005 9:13 am

Post by IndieRockSteve » Tue Apr 04, 2006 6:32 pm

michaelb wrote:
IndieRockSteve wrote:would it be possible to get a patch like the one "notz" posted, with no mouse support, and only 4 direction pad control with whatever updated changes/fixes the newer patches have? I'm using it with MythTV so I don't need a mouse, and I only need 4 directions, but I'd like to be able to use the other mouse buttons by remapping them for other functions.

thanks!
Try this: http://brakemeier.de/ below LIRC iMON Patches.
Please report all bugs.

@all: I'd like to mention the original author of this patch...but who is the original author :?:
your patch seems to completely disable the cursor...

IndieRockSteve
Posts: 16
Joined: Tue Nov 15, 2005 9:13 am

Re: Patch with fixed left arrow

Post by IndieRockSteve » Tue Apr 04, 2006 7:03 pm

SiliconFiend wrote:
SiliconFiend wrote:Aha! While I was going through this fixing the whitespace problems for my emailed patch file, I discovered a little bug with the left arrow (MOUSE_KEY_W). My wife had complained that it was sluggish moving left, and I think I found the reason why. I'll post the fixed patch in a while. The astute readers may find the problem themselves.
Okay, here's the patch yet again with the left arrow bug fixed.
ok, I took your patch and made it work for the tarball release. I've uploaded it here:
http://www.jobs-khakis-chicks.com/MythTV/lirc-imon/

I didn't bother fixing the spacing to make it pretty, but it compiles and works.

SiliconFiend, I'm going to PM u my email as I don't mind hosting the patch to make it easy for people to grab.

michaelb
Posts: 10
Joined: Tue Mar 28, 2006 11:04 pm

Post by michaelb » Tue Apr 04, 2006 11:44 pm

IndieRockSteve wrote:
michaelb wrote:
IndieRockSteve wrote:would it be possible to get a patch like the one "notz" posted, with no mouse support, and only 4 direction pad control ...
Try this: http://brakemeier.de/ below LIRC iMON Patches.
Please report all bugs.

@all: I'd like to mention the original author of this patch...but who is the original author :?:
your patch seems to completely disable the cursor...
Disable the cursor? The Mouse cursor?

I've removed the mouse input device support, so it possibly does
exactly what it was supposed to do... ?

Using VDR it works perfectly as Up-/Down-/.. and additionally makes the
MouseKeyboard, MouseLeft and MouseRight-Keys available.

IndieRockSteve
Posts: 16
Joined: Tue Nov 15, 2005 9:13 am

Post by IndieRockSteve » Wed Apr 05, 2006 4:39 am

michaelb wrote:
IndieRockSteve wrote:
michaelb wrote: Try this: http://brakemeier.de/ below LIRC iMON Patches.
Please report all bugs.

@all: I'd like to mention the original author of this patch...but who is the original author :?:
your patch seems to completely disable the cursor...
Disable the cursor? The Mouse cursor?

I've removed the mouse input device support, so it possibly does
exactly what it was supposed to do... ?

Using VDR it works perfectly as Up-/Down-/.. and additionally makes the
MouseKeyboard, MouseLeft and MouseRight-Keys available.
irw produced no events from the cursor, so its basically useless to me, the other patch works though, and if I ever decide to use it as a mouse, I'd be able to do that too...

michaelb
Posts: 10
Joined: Tue Mar 28, 2006 11:04 pm

Post by michaelb » Wed Apr 05, 2006 9:46 am

irw produced no events from the cursor, so its basically useless to me, the other patch works though, and if I ever decide to use it as a mouse, I'd be able to do that too...
hm...? something seems to be wrong with your patched version
or lircd.conf. irw output looks exactly as expected here...
azrael ~ # irw /dev/lircd
00000000690281b7 00 Mouse_N iMON-PAD
000000006a8281b7 00 Mouse_W iMON-PAD
00000000688291b7 00 Mouse_S iMON-PAD
00000000688a81b7 00 Mouse_E iMON-PAD
00000000299115b7 00 MouseKeyboard iMON-PAD
00000000688301b7 00 MouseLeftClick iMON-PAD
00000000688481b7 00 MouseRightClick iMON-PAD

but anyway...if you like the mouse stuff, use the "full" version.

IndieRockSteve
Posts: 16
Joined: Tue Nov 15, 2005 9:13 am

Post by IndieRockSteve » Wed Apr 05, 2006 2:10 pm

michaelb wrote:
irw produced no events from the cursor, so its basically useless to me, the other patch works though, and if I ever decide to use it as a mouse, I'd be able to do that too...
hm...? something seems to be wrong with your patched version
or lircd.conf. irw output looks exactly as expected here...
azrael ~ # irw /dev/lircd
00000000690281b7 00 Mouse_N iMON-PAD
000000006a8281b7 00 Mouse_W iMON-PAD
00000000688291b7 00 Mouse_S iMON-PAD
00000000688a81b7 00 Mouse_E iMON-PAD
00000000299115b7 00 MouseKeyboard iMON-PAD
00000000688301b7 00 MouseLeftClick iMON-PAD
00000000688481b7 00 MouseRightClick iMON-PAD

but anyway...if you like the mouse stuff, use the "full" version.
its not that I like the mouse stuff, its that the other patch works. your patch "succeeds", but irw does not output anything for the directional pad or click, the other buttons work fine though...

hayabusajerry
Posts: 15
Joined: Tue Mar 28, 2006 6:19 pm

Post by hayabusajerry » Mon Apr 10, 2006 9:09 pm

Hello all,

I think I must be missing something silly. I have tried both the patches most recently above (with and without mouse) against lirc-0.8.0, both of which have compiled fine with my 2.6.16.1 kernel (updated Fedora 5) having removed the 'owner' line from 'strict usb'.

With both versions I do not seem to get any output from the pad using irw, well thats not entirly true, I did get a mouse_s twice after many presses of the button. All the other buttons except the red power button work fine. The remote is not broken as it works fine in windoze.

I have modprobed the drivers (lirc_dev, lirc_imon) and even rebooted to make sure the new drivers are loaded after compile time.

I would prefere to use the keyboard and mouse version, but would be happy if I could get either to work.

What am I missing?

Cheers

Jerry

Post Reply