2013-04-22, 19:07
The following C program is using the lirc interface to display the min & max timeout of the ir driver.
When given an argument it can change the current timeout within those bounds.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/include/media/lirc.h>
#define DEVICE "/dev/lirc0"
int main(int argc, char**argv)
{
int ok ;
int fd ;
unsigned min_timeout = 0 ;
unsigned max_timeout = 0 ;
unsigned timeout = 0 ;
fd = open( DEVICE , O_RDWR) ;
if (fd<0) {
fprintf(stderr,"Failed to open device\n");
exit(1) ;
}
ok = ioctl(fd, LIRC_GET_MIN_TIMEOUT, &min_timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_GET_MINAX_TIMEOUT\n");
exit(1) ;
}
printf("get LIRC_GET_MIN_TIMEOUT = %u\n",min_timeout) ;
ok = ioctl(fd, LIRC_GET_MAX_TIMEOUT, &max_timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_GET_MINAX_TIMEOUT\n");
exit(1) ;
}
printf("get LIRC_GET_MAX_TIMEOUT = %u\n",max_timeout) ;
if (argc>1) {
timeout = atoi(argv[1]) ;
ok = ioctl(fd, LIRC_SET_REC_TIMEOUT, &timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_SET_REC_TIMEOUT\n");
exit(1) ;
}
printf("set LIRC_SET_REC_TIMEOUT = %u\n",timeout) ;
}
return 0;
}
When given an argument it can change the current timeout within those bounds.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/include/media/lirc.h>
#define DEVICE "/dev/lirc0"
int main(int argc, char**argv)
{
int ok ;
int fd ;
unsigned min_timeout = 0 ;
unsigned max_timeout = 0 ;
unsigned timeout = 0 ;
fd = open( DEVICE , O_RDWR) ;
if (fd<0) {
fprintf(stderr,"Failed to open device\n");
exit(1) ;
}
ok = ioctl(fd, LIRC_GET_MIN_TIMEOUT, &min_timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_GET_MINAX_TIMEOUT\n");
exit(1) ;
}
printf("get LIRC_GET_MIN_TIMEOUT = %u\n",min_timeout) ;
ok = ioctl(fd, LIRC_GET_MAX_TIMEOUT, &max_timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_GET_MINAX_TIMEOUT\n");
exit(1) ;
}
printf("get LIRC_GET_MAX_TIMEOUT = %u\n",max_timeout) ;
if (argc>1) {
timeout = atoi(argv[1]) ;
ok = ioctl(fd, LIRC_SET_REC_TIMEOUT, &timeout) ;
if ( ok!=0 ) {
fprintf(stderr,"Failed LIRC_SET_REC_TIMEOUT\n");
exit(1) ;
}
printf("set LIRC_SET_REC_TIMEOUT = %u\n",timeout) ;
}
return 0;
}