2010-02-02 03:53:57 +08:00
|
|
|
|
/*
|
2010-03-25 12:51:55 +08:00
|
|
|
|
+----------------------------------------------------
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
|
| <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰң<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
| Chang Logs:
|
|
|
|
|
| Date Author Notes
|
|
|
|
|
| 2010-01-02 aozima The bate version.
|
2010-02-10 14:31:27 +08:00
|
|
|
|
| 2010-02-10 aozima change printf string <EFBFBD><EFBFBD><EFBFBD><EFBFBD> to english.
|
2010-03-25 12:51:55 +08:00
|
|
|
|
| 2010-03-25 aozima add remote_fn define.
|
2010-02-02 03:53:57 +08:00
|
|
|
|
+----------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
#include <dfs_posix.h>
|
|
|
|
|
#include <stm32f10x.h>
|
|
|
|
|
|
2010-02-10 14:31:27 +08:00
|
|
|
|
/* <20>ض<EFBFBD><D8B6><EFBFBD>printf */
|
|
|
|
|
#define printf rt_kprintf
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>,<2C><>λ0.01ms */
|
|
|
|
|
#define remote_deviation 15
|
|
|
|
|
#define remote_code_len_max 100
|
2010-03-25 12:51:55 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȫ·<C8AB><C2B7> */
|
|
|
|
|
#define remote_fn "/resource/remote.txt"
|
2010-02-02 15:10:13 +08:00
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ģʽ 0:û<><C3BB><EFBFBD><EFBFBD>,1:<3A><>ѧϰ,2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
unsigned int rem_mode = 0;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
static unsigned int first_tick = 0;
|
|
|
|
|
static unsigned int rx_count = 0;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
static unsigned short rm_code[remote_code_len_max];
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
struct rem_codes_typedef
|
|
|
|
|
{
|
|
|
|
|
unsigned int len;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
unsigned short rem_code[remote_code_len_max];
|
2010-02-02 03:53:57 +08:00
|
|
|
|
};
|
|
|
|
|
struct rem_codes_typedef * p_rem_code_src = RT_NULL;
|
|
|
|
|
|
|
|
|
|
static const char str1[]="KEY_UP"; /* <20><> */
|
|
|
|
|
static const char str2[]="KEY_DOWN"; /* <20><> */
|
|
|
|
|
static const char str3[]="KEY_LEFT"; /* <20><> */
|
|
|
|
|
static const char str4[]="KEY_RIGHT"; /* <20><> */
|
|
|
|
|
static const char str5[]="KEY_ENTER"; /* ȷ<><C8B7> */
|
|
|
|
|
static const char str6[]="KEY_RETURN"; /* <20><><EFBFBD><EFBFBD> */
|
|
|
|
|
static const char * desc_key[6]= {str1,str2,str3,str4,str5,str6};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* tim5 configure */
|
|
|
|
|
static void TIM5_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
/* ʱ<>Ӽ<EFBFBD><D3BC><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD> */
|
|
|
|
|
{
|
|
|
|
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
|
|
|
|
/* Time Base configuration */
|
|
|
|
|
/* 72M/720 = 0.01ms */
|
|
|
|
|
TIM_TimeBaseStructure.TIM_Prescaler = 720-1;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ģʽ:<3A><><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
|
|
|
|
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
|
|
|
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
|
|
|
|
|
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
|
|
|
|
//<2F><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
|
|
|
|
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
|
|
|
|
|
|
|
|
|
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
{
|
|
|
|
|
TIM_ICInitTypeDef TIM_ICInitStructure;
|
|
|
|
|
|
|
|
|
|
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;/* ÿ<>μ<EFBFBD><CEBC><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>һ<EFBFBD>β<EFBFBD><CEB2><EFBFBD> */
|
|
|
|
|
TIM_ICInitStructure.TIM_ICFilter = 8;/* <20>˲<EFBFBD> */
|
|
|
|
|
|
|
|
|
|
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;//ѡ<><D1A1>ͨ<EFBFBD><CDA8>3
|
|
|
|
|
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;//<2F>½<EFBFBD><C2BD><EFBFBD>
|
|
|
|
|
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
TIM_ICInit(TIM5, &TIM_ICInitStructure);
|
|
|
|
|
|
|
|
|
|
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;//ѡ<><D1A1>ͨ<EFBFBD><CDA8>3
|
|
|
|
|
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
TIM_ICInit(TIM5, &TIM_ICInitStructure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD>봥<EFBFBD><EBB4A5>Դѡ<D4B4><D1A1>:<3A>ⲿ<EFBFBD><E2B2BF><EFBFBD>봥<EFBFBD><EBB4A5> */
|
|
|
|
|
TIM_SelectInputTrigger(TIM5, TIM_TS_ETRF);//TIM_TS_ETRF <20>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>
|
|
|
|
|
/* <20><>ģʽ-<2D><>λģʽ */
|
|
|
|
|
/* TIM_SlaveMode_Reset 4:ѡ<>еĴ<D0B5><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(TRGI)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>¼Ĵ<C2BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> */
|
|
|
|
|
TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset);
|
|
|
|
|
TIM_SelectMasterSlaveMode(TIM5, TIM_MasterSlaveMode_Enable);
|
|
|
|
|
|
|
|
|
|
/* TIM enable counter */
|
|
|
|
|
TIM_Cmd(TIM5, ENABLE);
|
|
|
|
|
|
|
|
|
|
/* Enable the CC3 and CC4 Interrupt Request */
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC3, ENABLE);
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC4, ENABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void NVIC_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
|
|
|
|
|
|
/* Enable the TIM5 global Interrupt */
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RCC_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
|
|
|
|
|
|
|
|
|
|
/* TIM5 clock enable */
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
|
|
|
|
|
|
|
|
|
|
/* clock enable */
|
|
|
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA ,ENABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void GPIO_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
|
|
/* TIM5 channel 3 pin (PA.02) configuration */
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
|
|
|
|
|
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rem_start(void)
|
|
|
|
|
{
|
|
|
|
|
RCC_Configuration();
|
|
|
|
|
GPIO_Configuration();
|
|
|
|
|
|
|
|
|
|
/* configure TIM5 for remote and encoder */
|
|
|
|
|
NVIC_Configuration();
|
|
|
|
|
TIM5_Configuration();
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p_rem_code_src = rt_malloc( sizeof(struct rem_codes_typedef)*6 );
|
2010-02-10 14:31:27 +08:00
|
|
|
|
if( p_rem_code_src != RT_NULL)
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
rt_memset(p_rem_code_src,0, sizeof(struct rem_codes_typedef)*6 );
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
int fd,size;
|
|
|
|
|
char buf[7];/* <20>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> #####\r\n */
|
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned short tmp;
|
|
|
|
|
unsigned int read_index = 0;
|
|
|
|
|
unsigned int EOF_flag = 1;
|
|
|
|
|
|
|
|
|
|
printf("\r\ndecode remote codes");
|
2010-03-25 12:51:55 +08:00
|
|
|
|
fd = open(remote_fn,O_RDONLY,0);
|
2010-02-10 14:31:27 +08:00
|
|
|
|
if( fd>0 )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r/resource/remote.txt open succeed");
|
|
|
|
|
while( EOF_flag )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
/* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> */
|
|
|
|
|
size = read(fd,buf,7);
|
|
|
|
|
if( (size == 7) && (buf[5]=='\r') && buf[6]=='\n' )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
/* ת<><D7AA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
|
|
|
|
tmp = (buf[0]-'0')*10000
|
|
|
|
|
+ (buf[1]-'0')*1000
|
|
|
|
|
+ (buf[2]-'0')*100
|
|
|
|
|
+ (buf[3]-'0')*10
|
|
|
|
|
+ (buf[4]-'0');
|
|
|
|
|
if( tmp<100 )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
unsigned int code_len = tmp;
|
|
|
|
|
p_rem_code_src[read_index].len = code_len;
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD> <20>Ϳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
for(i=0; i<code_len; i++)
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
size = read(fd,buf,7);
|
|
|
|
|
if( (size == 7) && (buf[5]=='\r') && buf[6]=='\n' )
|
|
|
|
|
{
|
|
|
|
|
/* ת<><D7AA><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
tmp = (buf[0]-'0')*10000
|
|
|
|
|
+ (buf[1]-'0')*1000
|
|
|
|
|
+ (buf[2]-'0')*100
|
|
|
|
|
+ (buf[3]-'0')*10
|
|
|
|
|
+ (buf[4]-'0');
|
|
|
|
|
p_rem_code_src[read_index].rem_code[i] = tmp;
|
|
|
|
|
}
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
2010-02-10 14:31:27 +08:00
|
|
|
|
read_index++;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-10 14:31:27 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EOF_flag = 0;
|
|
|
|
|
}
|
|
|
|
|
}//while( EOF_flag )
|
|
|
|
|
|
|
|
|
|
/* <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> */
|
|
|
|
|
if ( p_rem_code_src[0].len > 0 && p_rem_code_src[0].len < remote_code_len_max )
|
|
|
|
|
{
|
|
|
|
|
/* <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>ģʽΪ<CABD><CEAA><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>ģʽ */
|
|
|
|
|
rem_mode = 2;
|
|
|
|
|
printf("\r\ndecode succeed,The remote enable\r\n");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
/* <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>ģʽΪ<CABD><CEAA><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>ģʽ */
|
|
|
|
|
rem_mode = 0;
|
|
|
|
|
printf("\r\nrem_codes decode fail,The remote disable\r\n");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
2010-02-02 15:10:13 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\rrem_codes /resource/remote.txt open fail! fd:%d\r\nThe remote disbale.\r\nplease run rem_study()\r\n",fd);
|
2010-02-02 15:10:13 +08:00
|
|
|
|
}
|
2010-02-10 14:31:27 +08:00
|
|
|
|
close(fd);
|
|
|
|
|
}/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ */
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rem_mode = 0;
|
|
|
|
|
printf("\r\nmalloc rem_codes[] fail!!!\r\nThe remote disable!");
|
|
|
|
|
}
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <rtgui/event.h>
|
|
|
|
|
void rem_encoder(struct rtgui_event_kbd * p)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_kbd * p_kbd_event = p;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD> */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
if( (rem_mode==2) && (rt_tick_get()>first_tick+10) && (rx_count > 0) )
|
|
|
|
|
{
|
|
|
|
|
/* <20>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
rm_code[0] = 0;
|
|
|
|
|
rx_count = 0;
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* ƥ<>䲶<EFBFBD><E4B2B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned int tmp;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
unsigned int err_flag = 0;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
unsigned int rem_cmp_n = 6;
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* ѭ<><D1AD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>KEY */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
while( rem_cmp_n )
|
|
|
|
|
{
|
|
|
|
|
unsigned int tmp2 = p_rem_code_src[ 6-rem_cmp_n ].len;
|
2010-02-10 14:31:27 +08:00
|
|
|
|
//printf("\r\nrem_cmp_n:%d tmp2:%d",rem_cmp_n,tmp2);
|
2010-02-02 03:53:57 +08:00
|
|
|
|
if( tmp2 )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for(tmp=0; tmp<tmp2; tmp++)
|
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* <20>жϲ<D0B6><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7> */
|
|
|
|
|
if( !( (rm_code[tmp] < p_rem_code_src[6-rem_cmp_n].rem_code[tmp]+remote_deviation)
|
|
|
|
|
&& (rm_code[tmp] > p_rem_code_src[6-rem_cmp_n].rem_code[tmp]-remote_deviation)) )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
err_flag = 1;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
err_flag = 1;
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\nThe rem codes len is 0.");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
if( err_flag==0 )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* <20>Ա<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD> */
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\nmatch key: %s",desc_key[6-rem_cmp_n]);
|
2010-02-02 03:53:57 +08:00
|
|
|
|
switch( rem_cmp_n )
|
|
|
|
|
{
|
|
|
|
|
case 6:
|
|
|
|
|
p_kbd_event->key = RTGUIK_UP;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
p_kbd_event->key = RTGUIK_DOWN;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
p_kbd_event->key = RTGUIK_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
p_kbd_event->key = RTGUIK_RIGHT;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
p_kbd_event->key = RTGUIK_RETURN;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
p_kbd_event->key = RTGUIK_HOME;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
rem_cmp_n = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* <20>ԱȲ<D4B1><C8B2><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ζԱ<CEB6> */
|
|
|
|
|
err_flag = 0;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rem_cmp_n --;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}//<2F><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>ƥ<EFBFBD><C6A5>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remote isr */
|
|
|
|
|
void remote_isr(void)
|
|
|
|
|
{
|
|
|
|
|
static unsigned int clr_flag = 1;
|
|
|
|
|
unsigned int tick_now = rt_tick_get();
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD>½<EFBFBD><C2BD><EFBFBD> */
|
|
|
|
|
if(TIM_GetITStatus(TIM5, TIM_IT_CC3) == SET)
|
|
|
|
|
{
|
|
|
|
|
switch( rem_mode )
|
|
|
|
|
{
|
|
|
|
|
case 0://δ<><CEB4><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case 1://<2F><>ѧϰ
|
|
|
|
|
if( (rx_count==0) || (rx_count>90) || (tick_now>first_tick+10) )
|
|
|
|
|
{
|
|
|
|
|
//<2F><>Ҫ<EFBFBD><D2AA>0
|
|
|
|
|
rx_count = 0;
|
|
|
|
|
clr_flag = 1;
|
|
|
|
|
}
|
2010-02-02 15:10:13 +08:00
|
|
|
|
if( rx_count < remote_code_len_max )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
|
|
|
|
rm_code[rx_count++] = TIM_GetCapture3(TIM5);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if( (rx_count>90) || tick_now>first_tick+10 )
|
|
|
|
|
{
|
|
|
|
|
rx_count = 0;
|
|
|
|
|
clr_flag = 1;
|
|
|
|
|
}
|
2010-02-02 15:10:13 +08:00
|
|
|
|
if(rx_count < remote_code_len_max )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
|
|
|
|
rm_code[rx_count++] = TIM_GetCapture3(TIM5);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
rem_mode = 0;//<2F><><EFBFBD><EFBFBD>ģʽΪδ<CEAA><CEB4><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
TIM_ClearITPendingBit(TIM5, TIM_IT_CC3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
if(TIM_GetITStatus(TIM5, TIM_IT_CC4) == SET)
|
|
|
|
|
{
|
|
|
|
|
switch( rem_mode )
|
|
|
|
|
{
|
|
|
|
|
case 0://δ<><CEB4><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case 1://<2F><>ѧϰ
|
2010-02-02 15:10:13 +08:00
|
|
|
|
if( rx_count < remote_code_len_max )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
|
|
|
|
rm_code[rx_count++] = TIM_GetCapture4(TIM5);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2010-02-02 15:10:13 +08:00
|
|
|
|
if( rx_count < remote_code_len_max )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
|
|
|
|
rm_code[rx_count++] = TIM_GetCapture4(TIM5);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
rem_mode = 0;//<2F><><EFBFBD><EFBFBD>ģʽΪδ<CEAA><CEB4><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
TIM_ClearITPendingBit(TIM5, TIM_IT_CC4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
first_tick = tick_now;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if( clr_flag )
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
TIM_SetCounter(TIM5,0);
|
|
|
|
|
clr_flag = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <finsh.h>
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<D1A7><CFB0><EFBFBD><EFBFBD> */
|
|
|
|
|
int rem_study(void)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
int fd,size;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
unsigned char tmp_buf[ (remote_code_len_max+1)*7 ];
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
rem_mode = 1;
|
|
|
|
|
rx_count = 0;
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\nremote studing.....");
|
2010-03-25 12:51:55 +08:00
|
|
|
|
fd = open(remote_fn,O_WRONLY | O_TRUNC,0);
|
2010-02-02 03:53:57 +08:00
|
|
|
|
if( !(fd<0) )
|
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\n/resource/remote.txt create succeed.");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r/resource/remote.txt create fail.\r\nabort.");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* ѧϰ6<CFB0><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
for( i=0; i<6; i++)
|
|
|
|
|
{
|
|
|
|
|
unsigned int is_ok = 1;
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\npress key %s",desc_key[i]);
|
2010-02-02 03:53:57 +08:00
|
|
|
|
while( is_ok==1 )
|
|
|
|
|
{
|
|
|
|
|
if( (rem_mode==1) && (rt_tick_get()>first_tick+10) && (rx_count > 0) )
|
|
|
|
|
{
|
|
|
|
|
unsigned int a,b;
|
|
|
|
|
unsigned char * p = tmp_buf;
|
|
|
|
|
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\n%s",desc_key[i]);
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
b = rx_count;
|
|
|
|
|
p_rem_code_src[i].len = rx_count;
|
|
|
|
|
|
|
|
|
|
/* TIM disable counter */
|
|
|
|
|
TIM_Cmd(TIM5, DISABLE);
|
|
|
|
|
/* disable the CC3 and CC4 Interrupt Request */
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC3, DISABLE);
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC4, DISABLE);
|
|
|
|
|
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[0] = rx_count / 10000 +'0';
|
|
|
|
|
rx_count = rx_count % 10000;
|
|
|
|
|
p[1] = rx_count / 1000 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rx_count = rx_count % 1000;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[2] = rx_count / 100 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rx_count = rx_count % 100;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[3] = rx_count / 10 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rx_count = rx_count % 10;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[4] = rx_count +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rx_count = 0;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[5] = '\r';
|
|
|
|
|
p[6] = '\n';
|
|
|
|
|
p += 7;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
|
|
|
|
|
rm_code[0] = 0;
|
|
|
|
|
|
|
|
|
|
for( a=0; a<b; a++)
|
|
|
|
|
{
|
2010-02-02 15:10:13 +08:00
|
|
|
|
/* <20>ѵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>д<EFBFBD><D0B4><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD> */
|
2010-02-02 03:53:57 +08:00
|
|
|
|
p_rem_code_src[i].rem_code[a] = rm_code[a];
|
2010-02-02 15:10:13 +08:00
|
|
|
|
|
|
|
|
|
/* Ȼ<><C8BB>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ #####\r\n */
|
|
|
|
|
p[0] = rm_code[a] / 10000 +'0';
|
|
|
|
|
rm_code[a] = rm_code[a] % 10000;
|
|
|
|
|
p[1] = rm_code[a] / 1000 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rm_code[a] = rm_code[a] % 1000;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[2] = rm_code[a] / 100 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rm_code[a] = rm_code[a] % 100;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[3] = rm_code[a] / 10 +'0';
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rm_code[a] = rm_code[a] % 10;
|
2010-02-02 15:10:13 +08:00
|
|
|
|
p[4] = rm_code[a] +'0';
|
|
|
|
|
p[5] = '\r';
|
|
|
|
|
p[6] = '\n';
|
|
|
|
|
p += 7;
|
2010-02-02 03:53:57 +08:00
|
|
|
|
}
|
2010-02-02 15:10:13 +08:00
|
|
|
|
size = write(fd,(char*)tmp_buf,(b+1)*7 );
|
|
|
|
|
if( size==((b+1)*7) )
|
2010-02-02 03:53:57 +08:00
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf(" file write succeed!");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
is_ok++;
|
|
|
|
|
rt_thread_delay( 2 );
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD> TIM5 <20><><EFBFBD>в<EFBFBD><D0B2><EFBFBD> */
|
|
|
|
|
TIM_ClearITPendingBit(TIM5, TIM_IT_CC3);
|
|
|
|
|
TIM_ClearITPendingBit(TIM5, TIM_IT_CC4);
|
|
|
|
|
/* TIM ENABLE counter */
|
|
|
|
|
TIM_Cmd(TIM5, ENABLE);
|
|
|
|
|
/* ENABLE the CC3 and CC4 Interrupt Request */
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC3, ENABLE);
|
|
|
|
|
TIM_ITConfig(TIM5, TIM_IT_CC4, ENABLE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf(" file write fail.\r\nabort.");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rt_thread_delay(1);
|
|
|
|
|
}//while( is_ok==1 )
|
|
|
|
|
}//for( i=0; i<6; i++)
|
|
|
|
|
close(fd);
|
2010-02-10 14:31:27 +08:00
|
|
|
|
printf("\r\nremote study complete.The remote enable.\r\n");
|
2010-02-02 03:53:57 +08:00
|
|
|
|
rem_mode = 2;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
FINSH_FUNCTION_EXPORT(rem_study, rem_study);
|