CARPLAY版本整理
This commit is contained in:
179
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.c
Normal file
179
MXC_A27-PCB4.5-270T/app/moto/protocol/key_protocol.c
Normal file
@ -0,0 +1,179 @@
|
||||
#include "awtk.h"
|
||||
#include "key_protocol.h"
|
||||
#include "gpio_protocol.h"
|
||||
#include "board.h"
|
||||
#include "chip.h"
|
||||
#include "data_port.h"
|
||||
|
||||
KEY_DAT gs_keyDat[KEY_NUMBERS]={0};
|
||||
|
||||
bool key_readKeyPin(uint8_t keyx)
|
||||
{
|
||||
bool status;
|
||||
if(keyx==0) status = gpio_get_value(GPIO_LIGHT_SET);
|
||||
else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_MODE);
|
||||
// return (!status);//低有效
|
||||
return (status);//高有效
|
||||
}
|
||||
|
||||
void key_Scan(void)
|
||||
{
|
||||
uint8_t i;
|
||||
bool status;
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
{
|
||||
status=key_readKeyPin(i);
|
||||
if(status==0) gs_keyDat[i].flag_Pressed=KEY_ON;
|
||||
else gs_keyDat[i].flag_Pressed=KEY_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
extern uint8_t map_flag;
|
||||
static int step_about = 0;
|
||||
static int step = 0;
|
||||
|
||||
void check_key(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
key_Scan();
|
||||
for(i=0;i<KEY_NUMBERS;i++)
|
||||
{
|
||||
if(gs_keyDat[i].flag_Pressed==KEY_ON)
|
||||
{
|
||||
if(gs_keyDat[0].keyCnt>KEY_LLONGPRESS_COUNTER && gs_keyDat[1].keyCnt>KEY_LLONGPRESS_COUNTER)
|
||||
{
|
||||
gs_keyDat[0].flag_Reset=1;
|
||||
gs_keyDat[1].flag_Reset=1;
|
||||
gs_keyDat[0].keyCnt=0;
|
||||
gs_keyDat[1].keyCnt=0;
|
||||
// printf("two long key ---------------------\r\n");
|
||||
Key_Distinction(KEY_SHORT_ON,LV_KEY_OTHER1);
|
||||
}
|
||||
else if(gs_keyDat[i].keyCnt==KEY_LONGPRESS_COUNTER)
|
||||
{
|
||||
if(gs_keyDat[i].flag_Reset==0)
|
||||
{
|
||||
if(i==0 && gs_keyDat[1].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
gs_keyDat[i].flag_Reset=1;
|
||||
gs_keyDat[i].keyCnt=0;
|
||||
// printf("LV_KEY_OPTION key long key\r\n");
|
||||
Key_Distinction(KEY_LONG_ON,LV_KEY_OPTION);
|
||||
}
|
||||
if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
gs_keyDat[i].flag_Reset=1;
|
||||
gs_keyDat[i].keyCnt=0;
|
||||
// printf("LV_KEY_SELECT key long key\r\n");
|
||||
Key_Distinction(KEY_LONG_ON,LV_KEY_SELECT);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(gs_keyDat[i].flag_Reset==0) gs_keyDat[i].keyCnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(gs_keyDat[i].keyCnt>=KEY_PRESS_HOLD && gs_keyDat[i].keyCnt<KEY_LONGPRESS_COUNTER)
|
||||
{
|
||||
if(i==0 && gs_keyDat[1].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
// printf("LV_KEY_OPTION-------------------------.\r\n");
|
||||
// if(map_flag){
|
||||
// // KnobUpdate(0,0,0,0,0,1);
|
||||
// request_UI("maps:");
|
||||
// }else
|
||||
// if(Get_sys_wifi()){
|
||||
// printf("option DOWN .\r\n");
|
||||
// android_auto_send_key_event(20,1);
|
||||
// android_auto_send_key_event(20,0);
|
||||
// // android_auto_send_knob_event(19,1);
|
||||
// // android_auto_send_knob_event(19,0);
|
||||
// }else
|
||||
Key_Distinction(KEY_SHORT_ON,LV_KEY_OPTION);
|
||||
}
|
||||
else if(i==1 && gs_keyDat[0].flag_Pressed==KEY_OFF)
|
||||
{
|
||||
// printf("LV_KEY_SELECT-------------------------.\r\n");
|
||||
// if(map_flag){
|
||||
// // KnobUpdate(0,0,0,0,0,-1);
|
||||
// request_UI("maps:");
|
||||
// }else
|
||||
// if(Get_sys_wifi()){
|
||||
// printf("select ENTER .\r\n");
|
||||
// android_auto_send_key_event(66,1);
|
||||
// android_auto_send_key_event(66,0);
|
||||
// // android_auto_send_key_event(20,1);
|
||||
// // android_auto_send_key_event(20,0);
|
||||
// // android_auto_send_knob_event(20,1);
|
||||
// // android_auto_send_knob_event(20,0);
|
||||
// }else
|
||||
Key_Distinction(KEY_SHORT_ON,LV_KEY_SELECT);
|
||||
}
|
||||
}
|
||||
gs_keyDat[i].keyCnt=0;
|
||||
gs_keyDat[i].flag_Reset=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void gpio_right_handler(void)
|
||||
{
|
||||
uint8_t cph_cnt = 0;
|
||||
for(uint8_t i=0;i<IODELAY;i++)//防抖动
|
||||
{
|
||||
if(gpio_get_value(GPIO_LIGHT_R_LED_FLAG))
|
||||
cph_cnt++;
|
||||
}
|
||||
if(cph_cnt > (IODELAY-4)){
|
||||
right_led_on();
|
||||
}else{
|
||||
right_led_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void gpio_left_handler(void)
|
||||
{
|
||||
uint8_t cph_cnt = 0;
|
||||
for(uint8_t i=0;i<IODELAY;i++)//防抖动
|
||||
{
|
||||
if(gpio_get_value(GPIO_LIGHT_L_LED_FLAG))
|
||||
cph_cnt++;
|
||||
}
|
||||
if(cph_cnt > (IODELAY-4)){
|
||||
// if(gpio_get_value(GPIO_LIGHT_L_LED_FLAG)){
|
||||
left_led_on();
|
||||
}else{
|
||||
left_led_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void gpio_handler(void *param)
|
||||
{
|
||||
|
||||
for (;;) {
|
||||
// printf("gpio 10> %d gpio 11> %d.\r\n",gpio_get_value(8),gpio_get_value(9));
|
||||
if(Get_sys_power_on_self_test() == 100){
|
||||
gpio_right_handler();
|
||||
gpio_left_handler();
|
||||
check_key();//按键检测
|
||||
}
|
||||
vTaskDelay(20);
|
||||
}
|
||||
}
|
||||
|
||||
int gpio_timer(void){
|
||||
// printf("gpio_timer .\r\n");
|
||||
if (xTaskCreate(gpio_handler, "gpio_handler", configMINIMAL_STACK_SIZE, NULL,
|
||||
configMAX_PRIORITIES - 5, NULL) != pdPASS) {
|
||||
printf("create uart rx demo task fail.\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user