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

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Post by dacorsa » Sat Oct 13, 2007 10:48 am

this patch works for lirc 0.8.3 and kernel 2.6.23.1:

Code: Select all

--- lirc_imon.c	2007-09-30 11:58:45.000000000 +0200
+++ lirc_imon.c	2007-10-11 17:17:56.000000000 +0200
@@ -68,14 +68,32 @@
 #include "drivers/lirc_dev/lirc_dev.h"
 
 
+// imon pad2keys patch
+//
+// make PAD and mouse buttons available for use with VDR,
+// based on pad-mouse-emu patch from venky's forum
+//
+// M.Brakemeier 2006-03-31
+//
+// generated PAD key codes:
+// Mouse_N                  0x690281B7
+// Mouse_S                  0x688291B7
+// Mouse_W                  0x6A8281B7
+// Mouse_E                  0x688A81B7
+//
+// mouse buttons (non-synthetic):
+// MouseRightClick          0x688481B7
+// MouseLeftClick           0x688301B7
+
+
+
 #define MOD_AUTHOR	"Venky Raju <dev@venky.ws>"
-#define MOD_DESC	"Driver for Soundgraph iMON MultiMedia IR/VFD"
+#define MOD_DESC	"Driver for Soundgraph iMON MultiMedian IR/VFD w/imon pad2keys patch"
 #define MOD_NAME	"lirc_imon"
-#define MOD_VERSION	"0.3"
+#define MOD_VERSION	"0.3p2k"
 
 #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_MODE	S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
 #define DEVFS_NAME	LIRC_DEVFS_PREFIX "lcd%d"
 
 #define BUF_CHUNK_SIZE	4
@@ -87,6 +105,8 @@
 #define	TRUE		1
 #define FALSE		0
 
+#define CURSOR_LIMIT    16
+
 
 /* ------------------------------------------------------------
  *		     P R O T O T Y P E S
@@ -169,9 +189,13 @@
 		atomic_t busy;			/* write in progress */
 		int status;			/* status of tx completion */
 	} tx;
+
+    int key_x;
+    int key_y;
+    int last_count;                      /* number of times pressed   */
 };
 
-#define LOCK_CONTEXT	down(&context->sem)
+#define LOCK_CONTEXT	down (&context ->sem)
 #define UNLOCK_CONTEXT	up(&context->sem)
 
 /* VFD file operations */
@@ -258,6 +282,7 @@
 
 MODULE_AUTHOR(MOD_AUTHOR);
 MODULE_DESCRIPTION(MOD_DESC);
+MODULE_VERSION(MOD_VERSION);    /* MBr: was missing */
 MODULE_LICENSE("GPL");
 MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
 module_param(debug, int, 0);
@@ -684,6 +709,11 @@
 	context->rx.initial_space = 1;
 	context->rx.prev_bit = 0;
 
+        /* init pad context */
+        context ->key_x = 0;
+        context ->key_y = 0;
+        context ->last_count = 0;
+
 	usb_fill_int_urb(context->rx_urb, context->dev,
 		usb_rcvintpipe(context->dev,
 				context->rx_endpoint->bEndpointAddress),
@@ -834,6 +864,76 @@
 
 	if (context->ir_onboard_decode) {
 		/* The signals have been decoded onboard the iMON controller */
+    	        /* encode mouse pad as key events */
+    	        /* we like pad events, not mouse button events*/
+    	        if((buf[0] & 0x40) &&
+                   !(buf[1] & 0x01 || buf[1] >> 2 & 0x01))
+                {
+                    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->last_count > 32 )
+                    {  /* Hopefully eliminate drift*/
+                        context->last_count=0;
+                        context->key_y=0;
+                        context->key_x=0;
+                    }
+                    context->last_count++;
+
+                    /* limit decoded events */
+                    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 */
+                                buf[0] = 0x68;
+                               buf[1] = 0x82;
+                                buf[2] = 0x91;
+                            }
+                            else if(context->key_y < 0 && rel_y < 0)
+                            { /* mouse n */
+                                buf[0] = 0x69;
+                                buf[1] = 0x02;
+                                buf[2] = 0x81;
+                            }
+                        }
+                        else
+                        { /* mouse e/w*/
+                            if(context->key_x > 0 && rel_x > 0 )
+                            { /* mouse e */
+                                buf[0] = 0x68;
+                                buf[1] = 0x8A;
+                                buf[2] = 0x81;
+                            }
+                            else if(context->key_x < 0 && rel_x < 0  )
+                            { /* mouse 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 */
+                    }
+                }
+
+                /* a key was pressed, reset count */
+                context->key_x = 0;
+                context->key_y = 0;
+                context->last_count = 0;
+
 		lirc_buffer_write_1(context->plugin->rbuf, buf);
 		wake_up(&context->plugin->rbuf->wait_poll);
 		return;
dacorsa dacorsa dacorsa

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

Post by SiliconFiend » Wed Jan 30, 2008 9:32 pm

If you're using Gentoo or another portage-based distribution, you can just use that lirc package and set LIRC_DEVICES="imon_pad2keys" in your make.conf file. If you're using a different distro, you can copy the patch from that package (it's derived from the original patch, but without the mouse support) and build lirc yourself.

oliver
Posts: 6
Joined: Thu Sep 07, 2006 6:46 pm

Post by oliver » Sun Mar 09, 2008 6:33 pm

Hi, i just upgraded to lirc 0.8.3 (some pre version) on my gentoo box, and found that my pads stopped working properly (up and left seem to work, right and down require a very gentle touch, or they just wont' work) i tried all combinations, including the recently? added option 'activate_pads2keys' option as module parameter.

So I figured screw the pad, i'll have it work as a joystick (which does have potential btw. depending on the pressure you can go faster through a list/movie etc, it just requires a UI (freevo) to actually work right with it), and use the buttons just around it for directional pad. So as i play around with it, I noticed that all of a sudden, right mouse down release produces the down signal as well, and the left mouse release dupes the left. Here a quick irrecording of the offending keys (plus 1 and 2 as normal keys).

begin remote

name dirpad
bits 24
eps 30
aeps 100

one 0 0
zero 0 0
post_data_bits 8
post_data 0xB7
gap 203991
toggle_bit_mask 0x4000

begin codes
1 0x28B595
2 0x2BB195
up 0x6902B9
down 0x688281
right 0x68C281
left 0x6AFA81
leftmousedown 0x688301
leftmouseup 0x688281
rightmousedown 0x688481
rightmouseup 0x688281
end codes

end remote

I'm changing the bytes in the patch to something not found in my config yet, so I suppose it needed to be changed in the patches (and inform the gentoo folk who use these or patches as well)

edit:
get's worse, i look in the patch, and i'll be damned, down should be returning:
+ { /* mouse s */
+ buf[0] = 0x68;
+ buf[1] = 0x82;
+ buf[2] = 0x91;
+ }
so why is my remote/lirc returning 68 82 81 for 'south' instead of 68 82 91? This only started happening with the upgrade to 0.8.3 (pre2) i suppose i'll try roling back one of these days to 8.1 and see if i can get the old behaviour back. I doubt it's my remote suddenly returning different values all of a sudden ...

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Mon Jul 28, 2008 4:45 am

hi,

after some month that my remote imon doesn't works i have understand that have to insert this line in /etc/modprobe.conf:

options lirc_imon pad2keys_active=1

so till today works!!

but now, with new kernel 2.6.26:

root@SiduxBox:/usr/src/lirc# modprobe lirc_imon
FATAL: Error inserting lirc_imon (/lib/modules/2.6.26-0.slh.5-sidux-686/misc/lirc_imon.ko): Unknown symbol in module, or unknown parameter (see dmesg)

do you know how resolve??

thanks
dacorsa dacorsa dacorsa

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

Re: patch to make the imon PAD generate mouse events

Post by SiliconFiend » Fri Aug 08, 2008 3:51 pm

Take a look here: http://codeka.com/forums/viewtopic.php?f=3&t=40 They don't say which kernel version it's for, but maybe it will help you. I'm still on 2.6.25, so I don't know.

evil_core
Posts: 7
Joined: Tue Nov 04, 2008 7:29 am

Mouse support backported !

Post by evil_core » Mon Nov 17, 2008 6:02 pm

Finally i rewritten/backported Mouse patch with scrollwheel emulation(Channel buttons) and changed it a bit to look like kernel ati_remote2 module using EVDEV(currently only for mouse input) subsystem. It works with :

Code: Select all

15c2:ffdc SoundGraph Inc. iMON PAD Remote Controller
I succesfully(i am not talking about score ;) played Quake 3 Arena using iMON remote :D
There is attached lircd.conf and lircrc working with VDR and MPlayer.

Here it is, and will be new versions:
http://artemis.wszib.edu.pl/~kkrakowi/l ... ouse.patch

Enter lirc source root directory and apply it using:

Code: Select all

patch -p1 < $PATH_TO_PATCH/lirc-imon-mouse.patch
This patch is against lirc 0.8.4a and 2.6.27.
Remember to add this to /etc/modprobe.conf:

Code: Select all

options lirc_imon pad2keys_active=1
And optionally you can play with is_lcd={0,1} option if you cannot get LCD/VFD working.

This patch is shitty like previous and still needs that irw(or another lirc client) connected to get mouse working :/
There are lirc configs:
http://artemis.wszib.edu.pl/~kkrakowi/lircd.conf
http://artemis.wszib.edu.pl/~kkrakowi/lircrc


And there is tar archive containing PLD SPEC for lcdproc 0.5.2, including imon-patch, currently working config files and init scripts(/etc/init.d) (Its all you need to build RPMs :)
http://artemis.wszib.edu.pl/~kkrakowi/lcdproc.tgz
It generally works, except contrast and OnExit function. I dont have time/interest to deal with it.

IMHO much more better for iMON is MythTVImonServer
http://www.ronfrazier.net/mythtv/#MythTVImonServer
It slides text much more smooth, and has capabilities that are not implemented in LCDproc(which is too much more generic).

Mine case dont works as HPTC yet. I am playing it more for fun, and I really want it to work as ALSA Sound Visualiser, but I am not programmer, especially perl one. MythTVImonServer inlcudes set of libraries that doesnt need MythTV at all. Another thing I want to do, is porting ascii-invaders and moon-buggy to this small LCD :D I believe it will be much more easier that this visualiser (where programming skills are needed).

Original thread on Codeka forum, and please move there with this topic:
http://codeka.com/forums/viewtopic.php?f=3&t=79
I am really not connected in any way with Codeka forum, or admins. But its easier to keep discussion in one place. I choosed Codeka, because Codeka admin quicker accepted my registration request :P
Last edited by evil_core on Wed Nov 19, 2008 1:51 pm, edited 3 times in total.

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Tue Nov 18, 2008 12:21 pm

hi evil,

i have used your patch and now lirc works with 2.6.27 kernel, but my LCDd doesn't works!

i read this in log:

SiduxBox kernel: lirc_imon: lcd_write: invalid payload size: 32 (expecting 8)
SiduxBox kernel: ofo requeuing : rcv_next BD67098D seq BD67098D - BD670995
SiduxBox kernel: lirc_imon: lcd_write: invalid payload size: 32 (expecting 8)
SiduxBox kernel: ofo requeuing : rcv_next BD67099D seq BD67099D - BD670A35
SiduxBox kernel: lirc_imon: lcd_write: invalid payload size: 32 (expecting 8)


do you have a solution??

thanks i hope see you soon!
dacorsa dacorsa dacorsa

evil_core
Posts: 7
Joined: Tue Nov 04, 2008 7:29 am

Re: patch to make the imon PAD generate mouse events

Post by evil_core » Tue Nov 18, 2008 2:12 pm

@dacorsa: I added lcdproc patch(to previous posts), that I am using. Probably gentoo one.

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Tue Nov 18, 2008 11:45 pm

ohhhhh, i'm very stupid!!!

excuse me for the lapsus!

thanks!
dacorsa dacorsa dacorsa

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Wed Nov 19, 2008 1:16 am

ok i have compiled... this is result:

root@SiduxBox:/usr/src/lcdproc# LCDd
LCDd version 0.5.2 starting
Built on Nov 19 2008, protocol version 0.3, API version 0.5
Using Configuration File: /usr/local/etc/LCDd.conf
Set report level to 4, output to stderr
Server forking to background
Listening for queries on 127.0.0.1:13666
imonlcd: using Device /dev/lcd0
imonlcd: allocating 192 bytes for framebuffer.
Key "Escape" is now reserved in exclusive mode by client [-1]
Key "Enter" is now reserved in shared mode by client [-1]
Key "Up" is now reserved in shared mode by client [-1]
Key "Down" is now reserved in shared mode by client [-1]
screenlist_switch: switched to screen [_server_screen]
root@SiduxBox:/usr/src/lcdproc#


i don't see LCD working....how have to do now???

i want use with vdr and plugin lcdproc
dacorsa dacorsa dacorsa

evil_core
Posts: 7
Joined: Tue Nov 04, 2008 7:29 am

Re: patch to make the imon PAD generate mouse events

Post by evil_core » Wed Nov 19, 2008 2:17 pm

Run it please from init scipts using config files i have provided, and remember that LCDd is lcdproc server that is driven by clients connected on socket. So you must run also lcdproc after running LCDd to get anything on the screen.

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Wed Nov 19, 2008 3:34 pm

hi evil,

thanks for your reply, i have made all you have said, but i have new error

./LCDd: line 9: /etc/rc.d/init.d/functions: No such file or directory


i don't have rc.d dir and i don't have in rc0.d or rc1.d the functions directory.

how can i resolve? i use sidux distro.
dacorsa dacorsa dacorsa

evil_core
Posts: 7
Joined: Tue Nov 04, 2008 7:29 am

Re: patch to make the imon PAD generate mouse events

Post by evil_core » Wed Nov 19, 2008 4:09 pm

Make sure that there no other instance of LCDd od lcdproc running:

Code: Select all

killall LCDd lcdproc
ps aux | grep -i lcd 
And later start it using:

Code: Select all

LCDd -c /etc/lcdproc/LCDd.conf
lcdproc -c /etc/lcdproc/lcdproc.conf
You can also use any other config path. The scripts are really simply, they are especially designed for PLD, but are easy to read and understand. I simply copy pasted it from them. You can also run them in foreground by adding '-f' as command parameter, it will help finding problems.

dacorsa
Posts: 26
Joined: Wed May 17, 2006 3:58 pm

Re: patch to make the imon PAD generate mouse events

Post by dacorsa » Thu Nov 20, 2008 12:47 am

i don't know...:

root@SiduxBox:~# killall LCDd lcdproc
LCDd: no process killed
lcdproc: no process killed


root@SiduxBox:~# ps aux | grep -i lcd
root 3930 0.0 0.0 4700 736 pts/0 S+ 09:46 0:00 grep -i lcd


root@SiduxBox:~# LCDd -c /etc/lcdproc/LCDd.conf
Could not open driver module /usr/lib/lcdproc/imonlcd.so: /usr/lib/lcdproc/imonlcd.so: cannot open shared object file: No such file or directory
Driver [imonlcd] binding failed
Could not load driver imonlcd
There is no output driver
Critical error while initializing, abort.


root@SiduxBox:~# lcdproc -c /etc/lcdproc/lcdproc.conf
Error connecting to LCD server localhost on port 13666.
Check to see that the server is running and operating normally.
root@SiduxBox:~#
dacorsa dacorsa dacorsa

evil_core
Posts: 7
Joined: Tue Nov 04, 2008 7:29 am

Re: patch to make the imon PAD generate mouse events

Post by evil_core » Thu Nov 20, 2008 7:27 am

@dacorsa: Omg, please think a bit. If you installed it using prefix=/usr/local, than you must also change Path in config files. You can use this to change all path's in all lcdproc config files:

Code: Select all

sed -i s@/usr/@/usr/local/@g /etc/lcdproc/* 

Post Reply