MAX_CARLINK_A270S/MXC_A27-PCB4.5-270T/app/moto/protocol/gear_protocol.c

131 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "awtk.h"
#include "key_protocol.h"
#include "gpio_protocol.h"
#include "board.h"
#include "chip.h"
#include "data_port.h"
#include "gear_protocol.h"
// 定义定时器句柄
TimerHandle_t xTimer;
uint8_t GPIO_value_high[7];
#define IO_KEEP 4
void grade_key(void){
uint8_t Gear_value = 7;
//数据顺序 N 1 2 3 4 5 6 ABS TCS FAN ENG YG R L RMT
//挡位高电平触发, 灯光、ABS、TCS、FAN ENG 低电平触发
if(gpio_get_value(GPIO_GRADE_N))
{
GPIO_value_high[GPIO_N]++;
if(GPIO_value_high[GPIO_N] == IO_KEEP)
{
Gear_value = 0;
printf("N\r\n");
}
}
else
GPIO_value_high[GPIO_N] = 0;
if(gpio_get_value(GPIO_GRADE_D1))
{
GPIO_value_high[GPIO_D1]++;
if(GPIO_value_high[GPIO_D1] == IO_KEEP)
{
Gear_value = 1;
printf("D1\r\n");
}
}
else
GPIO_value_high[GPIO_D1] = 0;
if(gpio_get_value(GPIO_GRADE_D2))
{
GPIO_value_high[GPIO_D2]++;
if(GPIO_value_high[GPIO_D2] == IO_KEEP)
{
Gear_value = 2;
printf("D2\r\n");
}
}
else
GPIO_value_high[GPIO_D2] = 0;
if(gpio_get_value(GPIO_GRADE_D3))
{
GPIO_value_high[GPIO_D3]++;
if(GPIO_value_high[GPIO_D3] == IO_KEEP)
{
Gear_value = 3;
printf("D3\r\n");
}
}
else
GPIO_value_high[GPIO_D3] = 0;
if(gpio_get_value(GPIO_GRADE_D4))
{
GPIO_value_high[GPIO_D4]++;
if(GPIO_value_high[GPIO_D4] == IO_KEEP)
{
Gear_value = 4;
printf("D4\r\n");
}
}
else
GPIO_value_high[GPIO_D4] = 0;
if(gpio_get_value(GPIO_GRADE_D5))
{
GPIO_value_high[GPIO_D5]++;
if(GPIO_value_high[GPIO_D5] == IO_KEEP)
{
Gear_value = 5;
printf("D5\r\n");
}
}
else
GPIO_value_high[GPIO_D5] = 0;
if(gpio_get_value(GPIO_GRADE_D6))
{
GPIO_value_high[GPIO_D6]++;
if(GPIO_value_high[GPIO_D6] == IO_KEEP)
{
Gear_value = 6;
printf("D6\r\n");
}
}
else
GPIO_value_high[GPIO_D6] = 0;
Set_sys_grade(Gear_value);
}
// 定时器回调函数
void vTimerCallback(TimerHandle_t xTimer) {
// 定时器到期时执行的代码
//按键检测
check_key();
//档位检测
grade_key();
}
void Moto_gpio_timer(void) {
// 创建定时器
xTimer = xTimerCreate("MyTimer", // 定时器名称
pdMS_TO_TICKS(20), // 定时器周期1000毫秒
pdTRUE, // 自动重载定时器
(void *)0, // 定时器 ID
vTimerCallback); // 回调函数
// 启动定时器
if (xTimerStart(xTimer, 0) != pdPASS) {
// 启动定时器失败的处理
printf("xTimer error!!!!!!!!!!!!!!!!!.\r\n");
}
}