All of lore.kernel.org
 help / color / mirror / Atom feed
* General question about IR remote signals  from USB DVB tuner
@ 2012-02-10 16:34 Jan Panteltje
  2012-02-10 18:25 ` Tony Houghton
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Panteltje @ 2012-02-10 16:34 UTC (permalink / raw)
  To: linux-media

I recently bought a Terratec cinergy S2 USB  HD receiver.
I got everything working just fine in Linux and get excellent
reception.
This thing came with a small remote controller, and I notice
that the  output of this remote appears as ASCII characters on stdin,
on any terminal that I open...
Wrote a small GUI application that sets the input focus to a hidden
input field, and can process the numbers from this remote that way,
but of course this only works if the mouse has selected that application.

Thinking about this I think that the driver dumps the received remote
control characters simply to stdout.
If this is so, does there perhaps exists a /dev/dvb/adapterX/remoteX
interface in the specs so I could modify that driver to send the codes
there?
If not how about adding such a thing?
The application can then in a separate thread for example open
this device and use those codes.
This little remote has it all:
 numbers 0 to 9, ENTER, channel up /down, power, mute, EPG,
volume, what not.
Sorry I a am bit rusty, been many years since I did any programming
for DVB, so may be this already exists?
So much seems to have changed.
 
Any suggestions would be appreciated


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: General question about IR remote signals  from USB DVB tuner
  2012-02-10 16:34 General question about IR remote signals from USB DVB tuner Jan Panteltje
@ 2012-02-10 18:25 ` Tony Houghton
  0 siblings, 0 replies; 3+ messages in thread
From: Tony Houghton @ 2012-02-10 18:25 UTC (permalink / raw)
  To: Jan Panteltje, linux-media

[-- Attachment #1: Type: text/plain, Size: 1778 bytes --]

On Fri, 10 Feb 2012 08:34:49 -0800 (PST)
Jan Panteltje <panteltje@yahoo.com> wrote:

> I recently bought a Terratec cinergy S2 USB  HD receiver.
> I got everything working just fine in Linux and get excellent
> reception.
> This thing came with a small remote controller, and I notice
> that the  output of this remote appears as ASCII characters on stdin,
> on any terminal that I open...
> Wrote a small GUI application that sets the input focus to a hidden
> input field, and can process the numbers from this remote that way,
> but of course this only works if the mouse has selected that
> application.
> 
> Thinking about this I think that the driver dumps the received remote
> control characters simply to stdout.

Something fairly low level processes the input events and converts them
to keyboard events. IIRC this happens on the console as well as in X.

> If this is so, does there perhaps exists a /dev/dvb/adapterX/remoteX
> interface in the specs so I could modify that driver to send the codes
> there?

The events can be read from /dev/input/eventX. You can do something like
parse /proc/bus/input/devices to work out which device corresponds to
your remote. The structure of the events etc is defined in
/usr/include/linux/input.h. The EVIOCGRAB ioctl is useful to grab the
events exclusively for your application and stop them appearing on the
console.

I don't know exactly what the fields in input_event are supposed to
mean, and IME their significance can vary with remote and with kernel
version. If you can find more information about this, please send a copy
to me because I'm about to unsubscribe from linux-media. If you can't
find the information you'll probably find it useful to experiment with
the attached python script (treat as Public Domain).

[-- Attachment #2: testdevinput.py --]
[-- Type: text/x-python, Size: 886 bytes --]

#!/usr/bin/env python

import os
import struct
import sys

SIZEOF_INPUT_EVENT = struct.calcsize('llHHi')
# time (2 * long), type, code, value

quiet = False

def main_loop(fd):
    while True:
        s = os.read(fd, SIZEOF_INPUT_EVENT)
        if len(s) != SIZEOF_INPUT_EVENT:
            print >>sys.stderr, "Read %d bytes, expected %d" % \
                    (len(s), SIZEOF_INPUT_EVENT)
            break
        [tsec, tusec, type, code, value] = struct.unpack('llHHi', s)
        if not quiet or type:
            print "T:%10.2f t:%02x c:%02x v:%02x" % \
                    (tsec + float(tusec) / 1000000, type, code, value)

def main():
    if sys.argv[1] == '-q':
        global quiet
        quiet = True
        filename = sys.argv[2]
    else:
        filename = sys.argv[1]
    fd = os.open(filename, os.O_RDONLY)
    main_loop(fd)

if __name__ == '__main__':
    main()

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: General question about IR remote signals  from USB DVB tuner
@ 2012-02-11 19:01 Jan Panteltje
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Panteltje @ 2012-02-11 19:01 UTC (permalink / raw)
  To: Tony Houghton; +Cc: linux-media

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

This little demo C program looks for the IR input device,
parses the IR output and can start any application on any remote key press
or release.
Compile with gcc -o test50 test50.c
I have added a start xterm, a start firefox, and a kill firefox
as example.
add your own as needed.
Have fun:-)


[-- Attachment #2: test50.c --]
[-- Type: application/octet-stream, Size: 4159 bytes --]

/*
Copyright Jan Panteltje 2012-always
released under the GPL.
This is a small program that grabs keys from the Terratec Cinergy S2 USB HD remote and starts some applications.
This just demo code, no special purpose,
but it shows that little remote can be used to do anything your PC can do, not just TV.
Should be easy to adapt this for other DVB IR remote controllers.
You can find the key values by pressing the keys on the remote and watching the output of this program,
then add your own code for each key press and release as needed.

filename test50.c
compile with: gcc -o test50 test50.c
run with:
./test50
pres keys on IR remote,
key '1' starts an xterm
ENTER starts firefox
key 2 kills firefox
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>
#include <signal.h>
#include <pwd.h>
#include <math.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/poll.h>
#include <stdint.h>
#include <locale.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/io.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <linux/dvb/frontend.h>
#include <linux/dvb/dmx.h>

#include <linux/input.h>

/*
looking for something like:
/dev/input/by-path/pci-0000:04:00.0-event-ir
*/


int main(int argc, char **argv)
{
int a, b, c, i, j;
int fd;
FILE *fptr;
int data[1024];
char temp[1024];
char ir_device[1024];
FILE *pptr;
int found_flag = 0;
int key_code, key_pressed;

/* going to parse the result of ls in /dev/input/by-path/ */
pptr = popen("ls --color=none /dev/input/by-path/", "r");
temp[0] = 0;
j = 0;
for(i = 0; i < 1024; i++)
	{
	c = fgetc(pptr);
	if( feof(pptr) )
		{
		ir_device[i] = 0;
		break;
		}	

	if(c == 10) // LF
		{
		temp[j] = 0;
		j = 0;
		if(strstr(temp, "event-ir") != 0)
			{
//			fprintf(stderr, "found it, i=%d temp=%s\n", i, temp);
			found_flag = 1;
			break;
			}
		j = 0;				
		}
	else
		{
		temp[j] = c;
		j++;
		}
	}
pclose(pptr);

if(! found_flag)
	{
	fprintf(stderr, "could not find event-ir device, aborting.\n");
	
	exit(1);
	}

//fprintf(stderr, "temp=%s\n", temp);

sprintf(ir_device, "/dev/input/by-path/%s", temp);
fprintf(stderr, "trying ir_device=%s\n", ir_device);

fptr = fopen(ir_device, "r");
if(! fptr)
	{
	fprintf(stderr, "could not open /dev/input/event13 for read,aborting.\n");
	
	exit(1);
	}

/* grab the device for us alone, this prevents output to other applications, as that would cause havoc */
a = ioctl(fileno(fptr), EVIOCGRAB);
if(a < 0)
	{
	fprintf(stderr, "ioctl EVIOCGRAB failed because ");
	perror("");
	
	exit(1);
	}

//fprintf(stderr, "fptr=%p\n", fptr);

/*
read the correct number of bytes from the device for one key event.
**** NOTE: this number 48 is empirical and works for my TerratecCinery S2 USB remote, other remotes may perhaps require  adifferent value. ****
maybe read it with an ioctlfrom input_keymap_entry ? see /usr/include/linux/input.h 
*/

FILE *pptr1;
FILE *pptr2;

while(1)
	{
	for(i = 0; i < 48; i++)
		{
		c = fgetc(fptr);
		if(feof(fptr) )break;

		/*
		field 18 has the key value 
		field 20 has the key pressed- released flag
		*/ 
		if(i == 18) key_code = data[18];
		if(i == 20) key_pressed = data[20];

		data[i] = c;	
		} /* end for eachbyte in a field */

	do_keys(key_code, key_pressed);
		
	fprintf(stderr, "\n");
	} /*end while read fields resulting from akey press */

exit(0);
} /* end function main */
	


do_keys(int key_code, int key_pressed)
{
FILE *pptr;

/* do your things here, this can be used to do anything on a key press and key release, just some silly examples */
if(key_pressed)
	{
	fprintf(stderr, "key %02x pressed\n", key_code);

	switch(key_code)
		{
		case 0x02: // key '1'
			popen("xterm", "w");
			/* no pclose, exiting xterm will do that */  
		break;
					
		case 0x60: // ENTER
			popen("firefox &", "w");
			break;
				
		}


	} /* end if key pressed */
else
	{		
	fprintf(stderr, "key %02x released\n", key_code);		
		
	switch(key_code)
		{
		case 0x03: // key '2'			
			popen("killall -KILL firefox-bin", "r");
			break;
		}

	} /* andif key released */

} /* end function do_keys */






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-11 19:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10 16:34 General question about IR remote signals from USB DVB tuner Jan Panteltje
2012-02-10 18:25 ` Tony Houghton
2012-02-11 19:01 Jan Panteltje

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.