git-svn-id: https://rt-thread.googlecode.com/svn/trunk@399 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
e29be4a90b
commit
881d6a82d4
|
@ -6,6 +6,7 @@
|
||||||
| Chang Logs:
|
| Chang Logs:
|
||||||
| Date Author Notes
|
| Date Author Notes
|
||||||
| 2010-01-02 aozima The bate version.
|
| 2010-01-02 aozima The bate version.
|
||||||
|
| 2010-02-10 aozima change printf string ÖÐÎÄ to english.
|
||||||
+----------------------------------------------------
|
+----------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
|
|
||||||
|
/* Öض¨Òåprintf */
|
||||||
|
#define printf rt_kprintf
|
||||||
/* 设置允许偏差,单位0.01ms */
|
/* 设置允许偏差,单位0.01ms */
|
||||||
#define remote_deviation 15
|
#define remote_deviation 15
|
||||||
#define remote_code_len_max 100
|
#define remote_code_len_max 100
|
||||||
|
@ -138,6 +141,8 @@ void rem_start(void)
|
||||||
TIM5_Configuration();
|
TIM5_Configuration();
|
||||||
|
|
||||||
p_rem_code_src = rt_malloc( sizeof(struct rem_codes_typedef)*6 );
|
p_rem_code_src = rt_malloc( sizeof(struct rem_codes_typedef)*6 );
|
||||||
|
if( p_rem_code_src != RT_NULL)
|
||||||
|
{
|
||||||
rt_memset(p_rem_code_src,0, sizeof(struct rem_codes_typedef)*6 );
|
rt_memset(p_rem_code_src,0, sizeof(struct rem_codes_typedef)*6 );
|
||||||
|
|
||||||
/* 解读红外信息 */
|
/* 解读红外信息 */
|
||||||
|
@ -149,11 +154,11 @@ void rem_start(void)
|
||||||
unsigned int read_index = 0;
|
unsigned int read_index = 0;
|
||||||
unsigned int EOF_flag = 1;
|
unsigned int EOF_flag = 1;
|
||||||
|
|
||||||
rt_kprintf("\r\n解读红外信息");
|
printf("\r\ndecode remote codes");
|
||||||
fd = open("/resource/remote.txt",O_RDONLY,0);
|
fd = open("/resource/remote.txt",O_RDONLY,0);
|
||||||
if( fd>0 )
|
if( fd>0 )
|
||||||
{
|
{
|
||||||
rt_kprintf("\r/resource/remote.txt打开成功");
|
printf("\r/resource/remote.txt open succeed");
|
||||||
while( EOF_flag )
|
while( EOF_flag )
|
||||||
{
|
{
|
||||||
/* 读取长度 */
|
/* 读取长度 */
|
||||||
|
@ -199,21 +204,28 @@ void rem_start(void)
|
||||||
{
|
{
|
||||||
/* 设置工作模式为正常识别模式 */
|
/* 设置工作模式为正常识别模式 */
|
||||||
rem_mode = 2;
|
rem_mode = 2;
|
||||||
rt_kprintf("\r红外遥控编码文件解读完成,已打开红外遥控功能\r\n");
|
printf("\r\ndecode succeed,The remote enable\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 设置工作模式为正常识别模式 */
|
/* 设置工作模式为正常识别模式 */
|
||||||
rem_mode = 0;
|
rem_mode = 0;
|
||||||
rt_kprintf("\r\n红外遥控编码文件解读失败,已关闭红外遥控功能\r\n");
|
printf("\r\nrem_codes decode fail,The remote disable\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("\r红外遥控编码文件 /resource/remote.txt 打开失败! fd:%d\r\n无法开启红外遥控功能.\r\n请执行rem_study()进行自动学习\r\n",fd);
|
printf("\rrem_codes /resource/remote.txt open fail! fd:%d\r\nThe remote disbale.\r\nplease run rem_study()\r\n",fd);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}/* 解读红外信息 */
|
}/* 解读红外信息 */
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rem_mode = 0;
|
||||||
|
printf("\r\nmalloc rem_codes[] fail!!!\r\nThe remote disable!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <rtgui/event.h>
|
#include <rtgui/event.h>
|
||||||
|
@ -238,7 +250,7 @@ void rem_encoder(struct rtgui_event_kbd * p)
|
||||||
while( rem_cmp_n )
|
while( rem_cmp_n )
|
||||||
{
|
{
|
||||||
unsigned int tmp2 = p_rem_code_src[ 6-rem_cmp_n ].len;
|
unsigned int tmp2 = p_rem_code_src[ 6-rem_cmp_n ].len;
|
||||||
//rt_kprintf("\r\nrem_cmp_n:%d tmp2:%d",rem_cmp_n,tmp2);
|
//printf("\r\nrem_cmp_n:%d tmp2:%d",rem_cmp_n,tmp2);
|
||||||
if( tmp2 )
|
if( tmp2 )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -255,13 +267,13 @@ void rem_encoder(struct rtgui_event_kbd * p)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err_flag = 1;
|
err_flag = 1;
|
||||||
rt_kprintf("\r\n解码失败");
|
printf("\r\nThe rem codes len is 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( err_flag==0 )
|
if( err_flag==0 )
|
||||||
{
|
{
|
||||||
/* 对比全部数据符合 */
|
/* 对比全部数据符合 */
|
||||||
rt_kprintf("\r\n识别到遥控按键 %s",desc_key[6-rem_cmp_n]);
|
printf("\r\nmatch key: %s",desc_key[6-rem_cmp_n]);
|
||||||
switch( rem_cmp_n )
|
switch( rem_cmp_n )
|
||||||
{
|
{
|
||||||
case 6:
|
case 6:
|
||||||
|
@ -390,15 +402,15 @@ int rem_study(void)
|
||||||
|
|
||||||
rem_mode = 1;
|
rem_mode = 1;
|
||||||
rx_count = 0;
|
rx_count = 0;
|
||||||
rt_kprintf("\r\n红外遥控自学习功能启动");
|
printf("\r\nremote studing.....");
|
||||||
fd = open("/resource/remote.txt",O_WRONLY | O_TRUNC,0);
|
fd = open("/resource/remote.txt",O_WRONLY | O_TRUNC,0);
|
||||||
if( !(fd<0) )
|
if( !(fd<0) )
|
||||||
{
|
{
|
||||||
rt_kprintf("\r\n红外遥控编码文件 /resource/remote.txt 创建成功");
|
printf("\r\n/resource/remote.txt create succeed.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("\r红外遥控编码文件 /resource/remote.txt 创建失败.\r\n学习程序中止.");
|
printf("\r/resource/remote.txt create fail.\r\nabort.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +418,7 @@ int rem_study(void)
|
||||||
for( i=0; i<6; i++)
|
for( i=0; i<6; i++)
|
||||||
{
|
{
|
||||||
unsigned int is_ok = 1;
|
unsigned int is_ok = 1;
|
||||||
rt_kprintf("\r\npress key %s",desc_key[i]);
|
printf("\r\npress key %s",desc_key[i]);
|
||||||
while( is_ok==1 )
|
while( is_ok==1 )
|
||||||
{
|
{
|
||||||
if( (rem_mode==1) && (rt_tick_get()>first_tick+10) && (rx_count > 0) )
|
if( (rem_mode==1) && (rt_tick_get()>first_tick+10) && (rx_count > 0) )
|
||||||
|
@ -414,7 +426,7 @@ int rem_study(void)
|
||||||
unsigned int a,b;
|
unsigned int a,b;
|
||||||
unsigned char * p = tmp_buf;
|
unsigned char * p = tmp_buf;
|
||||||
|
|
||||||
rt_kprintf("\r\n%s",desc_key[i]);
|
printf("\r\n%s",desc_key[i]);
|
||||||
|
|
||||||
b = rx_count;
|
b = rx_count;
|
||||||
p_rem_code_src[i].len = rx_count;
|
p_rem_code_src[i].len = rx_count;
|
||||||
|
@ -463,7 +475,7 @@ int rem_study(void)
|
||||||
size = write(fd,(char*)tmp_buf,(b+1)*7 );
|
size = write(fd,(char*)tmp_buf,(b+1)*7 );
|
||||||
if( size==((b+1)*7) )
|
if( size==((b+1)*7) )
|
||||||
{
|
{
|
||||||
rt_kprintf("文件写入成功");
|
printf(" file write succeed!");
|
||||||
is_ok++;
|
is_ok++;
|
||||||
rt_thread_delay( 2 );
|
rt_thread_delay( 2 );
|
||||||
|
|
||||||
|
@ -478,7 +490,7 @@ int rem_study(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("文件写入失败\r\n红外学习程序退出");
|
printf(" file write fail.\r\nabort.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,7 +498,7 @@ int rem_study(void)
|
||||||
}//while( is_ok==1 )
|
}//while( is_ok==1 )
|
||||||
}//for( i=0; i<6; i++)
|
}//for( i=0; i<6; i++)
|
||||||
close(fd);
|
close(fd);
|
||||||
rt_kprintf("\r\n学习完成,现在进入正常识别模式\r\n");
|
printf("\r\nremote study complete.The remote enable.\r\n");
|
||||||
rem_mode = 2;
|
rem_mode = 2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue