lirc测试遥控代码
1, Reboot the box.
2, insmod /opt/lib/modules/2.6.34/extra/lirc_dev.ko
insmod /opt/lib/modules/2.6.34/extra/lnxplatLirc.ko
3, Enter /opt/bin and run irrecord, ./irrecord -d /dev/lirc0 --disable-namespace new.conf
4, Register 'power' key, '1' key and '2' key.
5, cp new.conf /etc/ lircd.conf
6, Run lircd with command ./lircd --listen=5177 --device=/dev/lirc0 -n &
7, Enter /opt/bin and run irw
8, Test the registered key.
如果使用默认的socket: mkdir /var/run/lirc./lircd --device=/dev/lirc0 -u 如果自己指定: /opt/bin/lircd --listen=5177 --device=/dev/lirc0 当然这是很理想的状况,实际上用irrecord录制时,很少有录制完全正确的时候 ................................................................................
Found gap: 292566
Please keep on pressing buttons like described above.
................................................................................
Space/pulse encoded remote control found.
Signal length is 67.
No header data.
Found trail pulse: 2670
Found repeat code: 45207 11583
Found repeat gap: 292566
Signals are space encoded.
Signal length is 33
Now enter the names for the buttons. 能得到如上的结果,已经算是非常成功的了,大多数情况下,都会是检测到raw模式,我用示波器实时观察了下遥控头的输入波形,发现遥控器和遥控头之间的角度不同,波形在同步头部分差别很大,正常情况是很长一个低电平以后接着一个稍短的高电平为同步头,但是异常的时候,这部分只有很窄一个低电平。那么在此基础上我们如何修改并使得其能工作正常呢? 首先看看生成的conf文件如下: begin remote name new2.conf
bits 33
flags SPACE_ENC
eps 30
aeps 100 one 2671 8657
zero 2671 2991
ptrail 2671
repeat 45210 11581
gap 292566
repeat_gap 292566
toggle_bit_mask 0x0 begin codes
end codes end remote bit 33显然是不对的,应该是32,修改为32以后,我们把它copy到/etc/lirc.conf并且修改receive.c中的函数receive_decode(): LOGPRINTF(1,"code: %llx",code); -> logprintf(1,"code: %llx",code); 然后运行: ./lircd --listen=5177 --device=/dev/lirc0 -n & ./irw 这是按键以后,你会看到code会打印出来,code的值就是实际的遥控器代码: lircd: code: 608f807f lircd: code: 608fe01f 由此我们可以返回去修改conf文件如下: begin remote bits 16
flags SPACE_ENC|CONST_LENGTH|REPEAT_HEADER
eps 30
aeps 100 one 2671 8657
zero 2671 2991
repeat 45207 11581
ptrail 2671
pre_data_bits 16
pre_data 0x608f
gap 292566
toggle_bit_mask 0x0 begin codes
0 0x00FF
1 0x807F
2 0x40BF
3 0xC03F
4 0x20DF
5 0xA05F
6 0x609F
7 0xE01F
8 0x10EF
9 0x906F
* 0x14EB
# 0xF807
CHAN_UP 0x23DC
CHAN_DOWN 0xA35C
VOL_UP 0x639C
VOL_DOWN 0xE31C
STANDBY 0xD02F
MUTE 0x28D7
CHANNEL 0x30CF
HOME 0xCC33
FAVORITE 0xE41B
MENU 0x708F
BACK 0x946B
OK 0xA857
UP 0x38C7
LEFT 0xB04F
RIGHT 0xB847
DOWN 0x7887
STOP 0x58A7
PALY 0xD827
FASTBACKWARD 0x08F7
FASTFORWARD 0x48B7
DEL 0x44BB
PAGE_UP 0xE817
PAGE_DOWN 0x50AF
LOCAL 0x4CB3
RED 0x847B
GREEN 0x9867
YELLOW 0x18E7
BLUE 0x04FB
F1 0x649B
F2 0xA45B
F3 0x24DB
F4 0xC43B
end codes end remote 然后再用irw测试,一切工作正常。但是repeat键检测不到,偶然一次遥控协议配置成SEJIN的时候用irrecord试了下,居然一次就得到正确的代码了: It is very important that you press many different buttons and hold them
down for approximately one second. Each button should generate at least one
dot but in no case more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have been
generated. Press RETURN now to start recording.
................................................................................
Found const length: 107221
Please keep on pressing buttons like described above.
................................................................................
Space/pulse encoded remote control found.
Signal length is 67.
Found possible header: 8953 4441
Found trail pulse: 595
Found repeat code: 8955 2204
Signals are space encoded.
Signal length is 32
Now enter the names for the buttons. 生成的文件如下:
# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.8.4a(default) on Thu Jan 1 01:05:46 1970
#
# contributed by
#
# brand: /etc/lircd.conf
# model no. of remote control:
# devices being controlled by this remote:
# begin remote name /etc/lircd.conf
bits 16
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100 header 8953 4441
one 594 1630
zero 594 515
ptrail 595
repeat 8955 2204
pre_data_bits 16
pre_data 0x608F
gap 107221
toggle_bit_mask 0x0
begin codes
KEY_0 0x00FF
KEY_1 0x807F
KEY_2 0x40BF
KEY_3 0xC03F
KEY_4 0x20DF
KEY_5 0xA05F
KEY_6 0x609F
KEY_7 0xE01F
KEY_8 0x10EF
KEY_9 0x906F
KEY_SWITCHVIDEOMODE 0x14EB
KEY_KBDILLUMTOGGLE 0xF807
KEY_CHANNELUP 0x23DC
KEY_CHANNELDOWN 0xA35C
KEY_VOLUMEUP 0x639C
KEY_VOLUMEDOWN 0xE31C
KEY_POWER 0xD02F
KEY_MUTE 0x28D7
KEY_CHANNEL 0x30CF
KEY_MENU 0xCC33
KEY_FAVORITES 0xE41B
KEY_HOME 0x708F
KEY_BACK 0x946B
KEY_ENTER 0xA857
KEY_UP 0x38C7
KEY_LEFT 0xB04F
KEY_RIGHT 0xB847
KEY_DOWN 0x7887
KEY_STOP 0x58A7
KEY_PLAY 0xD827
KEY_REWIND 0x08F7
KEY_FORWARD 0x48B7
KEY_DELETE 0x44BB
KEY_PAGEUP 0xE817
KEY_PAGEDOWN 0x50AF
LOCAL 0x4CB3
KEY_F1 0x847B
KEY_F2 0x9867
KEY_F3 0x18E7
KEY_F4 0x04FB
KEY_RED 0x649B
KEY_GREEN 0xA45B
KEY_YELLOW 0x24DB
KEY_BLUE 0xC43B
end codes end remote flags SPACE_ENC|CONST_LENGTH|REPEAT_HEADER有了REPEAT_HEADER以后repeat键反而检测不到.
但是SEJIN的协议仍然有点小问题,就是第一次按键往往都检测不到,有时候要连续按几次才能检测到一次
查看代码,发现SEJIN和NEC的区别只是采样时钟的定义不同:
#if (REMOTE_PROTOCOL == REMOTE_PROTOCOL_SEJIN)
#define IRRX_CLK_CTRL 55
#define IR_FILTER_VALUE 0x320
#else
/* NEC RC5 */
#define IRRX_CLK_CTRL (((CRYSTAL_FREQUENCY / (16 * 38222 )) - 1)/8)
#define IR_FILTER_VALUE ((CRYSTAL_FREQUENCY / 1000000 )* 400 )
#endif
NEC的频率应该是38KHz,所以改为38000,然后再用irrecord
Press RETURN now to start recording.
................................................................................
Found const length: 352410
Please keep on pressing buttons like described above.
................................................................................
Space/pulse encoded remote control found.
Signal length is 67.
Found possible header: 45585 22623
Found trail pulse: 3033
Found repeat code: 45585 11230
Signals are space encoded.
Signal length is 32
Now enter the names for the buttons.
生成文件如下:
# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.8.7(default) on Wed Dec 31 17:06:14 1969
#
# contributed by
#
# brand: new.conf
# model no. of remote control:
# devices being controlled by this remote:
#
begin remote
name new.conf
bits 32
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100
header 45585 22623
one 3033 8297
zero 3033 2631
ptrail 3033
repeat 45585 11230
gap 352410
toggle_bit_mask 0x0
begin codes
end codes
end remote
头基本上都对了,具体键值,可用打印的办法测出
# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.8.7(default) on Wed Dec 31 17:06:20 1969
#
# contributed by
#
# brand: new.conf
# model no. of remote control:
# devices being controlled by this remote:
#
begin remote
name new.conf
bits 16
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100
header 45566 22645
one 3005 8325
zero 3005 2661
ptrail 3007
repeat 45566 11247
pre_data_bits 16
pre_data 0x608f
gap 352399
toggle_bit_mask 0x0
begin codes
KEY_0 0x00FF
KEY_1 0x807F
KEY_2 0x40BF
KEY_3 0xC03F
KEY_4 0x20DF
KEY_5 0xA05F
KEY_6 0x609F
KEY_7 0xE01F
KEY_8 0x10EF
KEY_9 0x906F
KEY_SWITCHVIDEOMODE 0x14EB
KEY_KBDILLUMTOGGLE 0xF807
KEY_CHANNELUP 0x23DC
KEY_CHANNELDOWN 0xA35C
KEY_VOLUMEUP 0x639C
KEY_VOLUMEDOWN 0xE31C
KEY_POWER 0xD02F
KEY_MUTE 0x28D7
KEY_CHANNEL 0x30CF
KEY_MENU 0xCC33
KEY_FAVORITES 0xE41B
KEY_HOME 0x708F
KEY_BACK 0x946B
KEY_ENTER 0xA857
KEY_UP 0x38C7
KEY_LEFT 0xB04F
KEY_RIGHT 0xB847
KEY_DOWN 0x7887
KEY_STOP 0x58A7
KEY_PLAY 0xD827
KEY_REWIND 0x08F7
KEY_FORWARD 0x48B7
KEY_DELETE 0x44BB
KEY_PAGEUP 0xE817
KEY_PAGEDOWN 0x50AF
LOCAL 0x4CB3
KEY_F1 0x847B
KEY_F2 0x9867
KEY_F3 0x18E7
KEY_F4 0x04FB
KEY_RED 0x649B
KEY_GREEN 0xA45B
KEY_YELLOW 0x24DB
KEY_BLUE 0xC43B
end codes
end remote
如果发现有些键值irw能接收到,但是input系统没有收到:
lircd.c
int setup_uinputfd(const char *name)
{
#if defined(__linux__)
int fd;
int key;
struct uinput_user_dev dev;
fd = open("/dev/input/uinput", O_RDWR);
if(fd == -1)
{
fd = open("/dev/uinput", O_RDWR);
if(fd == -1)
{
fd = open("/dev/misc/uinput", O_RDWR);
if(fd == -1)
{
fprintf(stderr, "could not open %s\n",
"uinput");
perror(NULL);
return -1;
}
}
}
memset(&dev, 0, sizeof(dev));
strncpy(dev.name, name, sizeof(dev.name));
dev.name[sizeof(dev.name)-1] = 0;
if(write(fd, &dev, sizeof(dev)) != sizeof(dev) ||
ioctl(fd, UI_SET_EVBIT, EV_KEY) != 0 )/*||
ioctl(fd, UI_SET_EVBIT, EV_REP) != 0) */
{
goto setup_error;
}
for(key = KEY_RESERVED; key <= KEY_UNKNOWN; key++)
{
if(ioctl(fd, UI_SET_KEYBIT, key) != 0)
{
goto setup_error;
}
}
if(ioctl(fd, UI_DEV_CREATE) != 0)
{
goto setup_error;
}
return fd;
setup_error:
fprintf(stderr, "could not setup %s\n", "uinput");
perror(NULL);
close(fd);
#endif
return -1;
}
由于在input_map.inc
{"KEY_UNKNOWN", 240},
所以大于240(0xF0)的键都被屏蔽掉了