cun
This commit is contained in:
@ -8,9 +8,9 @@
|
||||
#include "le_client_demo.h"
|
||||
#include "le_common.h"
|
||||
#include "./ble_handler/client_handler.h"
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
// 宏定义与日志
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
#define RC_LOG_ENABLE 1
|
||||
#if RC_LOG_ENABLE
|
||||
@ -19,14 +19,14 @@
|
||||
#define rc_log(format, ...)
|
||||
#endif
|
||||
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
// 外部函数声明
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
extern void TYPE_V_EVENT(char* uid);
|
||||
extern void TYPE_A_EVENT(char* uid);
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
// 静态函数声明
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
static RFID_Device_Type_t get_rfid_device_type(const u8* uid);
|
||||
|
||||
@ -35,9 +35,12 @@ static void rc_ble_state_set_connecting(void);
|
||||
static void rc_ble_state_set_connected(void);
|
||||
static void rc_ble_state_set_disconnected(void);
|
||||
|
||||
// =================================================================================
|
||||
//进程名称
|
||||
static char control_key_task_name[] = "control_key";
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 全局变量
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
static RC_Context_t g_rc_context; // 全局上下文实例
|
||||
static u16 g_rfid_timer_id = 0; // RFID 定时器ID
|
||||
@ -46,9 +49,9 @@ static u8 current_board_mac[MAIN_BOARD_MAC_ADDR_LENGTH] = {0}; //当前连接
|
||||
|
||||
|
||||
|
||||
// =================================================================================
|
||||
// 核心回调函数 (Core Callback Handlers)
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
// rfid功能相关
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief RFID回调处理函数 (由定时器周期性调用)
|
||||
@ -121,6 +124,11 @@ void rc_rfid_callback_handler(void *priv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// ble功能相关
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief BLE回调处理函数 (由定时器周期性调用)s
|
||||
*/
|
||||
@ -195,9 +203,95 @@ static RFID_Device_Type_t get_rfid_device_type(const u8* uid)
|
||||
|
||||
return RFID_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
// =================================================================================
|
||||
// 辅助函数 (Helper Functions)
|
||||
// =================================================================================
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 遥感按键相关
|
||||
// ==================================================================================================================================================================
|
||||
/**
|
||||
* @brief 遥感按键初始化
|
||||
*
|
||||
*/
|
||||
void control_key_init(void){
|
||||
//Yout
|
||||
adc_add_sample_ch(AD_CH_PG5);
|
||||
gpio_set_die(IO_PORTG_05, 0);
|
||||
gpio_set_direction(IO_PORTG_05, 1);
|
||||
gpio_set_pull_down(IO_PORTG_05, 0);
|
||||
gpio_set_pull_up(IO_PORTG_05, 0);
|
||||
|
||||
//Xout
|
||||
adc_add_sample_ch(AD_CH_PG7);
|
||||
gpio_set_die(IO_PORTG_07, 0);
|
||||
gpio_set_direction(IO_PORTG_07, 1);
|
||||
gpio_set_pull_down(IO_PORTG_07, 0);
|
||||
gpio_set_pull_up(IO_PORTG_07, 0);
|
||||
|
||||
//key 1:默认为高,按下为低
|
||||
gpio_set_die(IO_PORTG_06, 1);
|
||||
gpio_set_direction(IO_PORTG_06, 1);
|
||||
gpio_set_pull_down(IO_PORTG_06, 0);
|
||||
gpio_set_pull_up(IO_PORTG_06, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取遥感按键值
|
||||
*
|
||||
* @param Xout_adc x轴遥感adc
|
||||
* @param Yout_adc y轴遥感adc
|
||||
* @param key1_state 按键1值
|
||||
* @param key2_state 按键2值
|
||||
*/
|
||||
void control_key_get_value(u16* Xout_adc, u16* Yout_adc, u8* key1_state, u8* key2_state){
|
||||
*Xout_adc = (u16)adc_get_value(AD_CH_PG5);
|
||||
*Yout_adc = (u16)adc_get_value(AD_CH_PG7);
|
||||
|
||||
*key1_state = gpio_read(IO_PORTG_06);
|
||||
rc_log("adc_get_value: Xout = %d, Yout = %d, key1_state = %d, key2_state = %d\n", *Xout_adc , *Yout_adc, *key1_state, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 按键的处理任务
|
||||
*
|
||||
*/
|
||||
void contol_key_task(void){
|
||||
static u16 vbat_value = 0; //当前剩余电量
|
||||
static u16 Xout_adc = 0;
|
||||
static u16 Yout_adc = 0;
|
||||
static u8 key1_state = 1;
|
||||
u8 ble_data_buff[13] = {0xBE, 0xBB, 0x0A, 0x01, //0-3
|
||||
0x00, 0x00, 0x00, 0x00, //4-7 遥感值:上下、左右
|
||||
0x00, 0x00, //8、9 两个按键
|
||||
0x00, 0x00, //10、11 vbat adc值
|
||||
0x0C}; //12 校验和
|
||||
|
||||
control_key_init(); //遥感按键初始化
|
||||
|
||||
while(1){
|
||||
extern u16 get_vbat_level(void);
|
||||
vbat_value = get_vbat_level(); //当前电量
|
||||
control_key_get_value(&Xout_adc, &Yout_adc, &key1_state, NULL); //遥感值
|
||||
ble_data_buff[4] = (u8)(Yout_adc & 0xFF);
|
||||
ble_data_buff[5] = (u8)((Yout_adc >> 8) & 0xFF);
|
||||
|
||||
ble_data_buff[6] = (u8)(Xout_adc & 0xFF);
|
||||
ble_data_buff[7] = (u8)((Xout_adc >> 8) & 0xFF);
|
||||
|
||||
ble_data_buff[8] = key1_state;
|
||||
ble_data_buff[9] = 0x01;
|
||||
|
||||
ble_data_buff[10] = (u8)(vbat_value & 0xFF);
|
||||
ble_data_buff[11] = (u8)((vbat_value >> 8) & 0xFF);
|
||||
|
||||
g_send_data_to_ble_server(ble_data_buff, sizeof(ble_data_buff));
|
||||
os_time_dly(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ==================================================================================================================================================================
|
||||
// 辅助函数
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief 进入 CONNECTING 状态的逻辑
|
||||
@ -237,8 +331,9 @@ static void rc_ble_state_set_disconnected(void)
|
||||
// 在这里控制LED灯效,例如黄灯呼吸闪烁
|
||||
}
|
||||
|
||||
// 初始化函数 (Initialization Function)
|
||||
// =================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
// 初始化函数
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
/**
|
||||
* @brief 遥控器应用主初始化函数
|
||||
@ -255,13 +350,13 @@ void rc_app_main_init(void)
|
||||
|
||||
// 2. 检查并启动RFID处理定时器
|
||||
if (g_rfid_timer_id == 0) {
|
||||
g_rfid_timer_id = sys_timer_add(NULL, rc_rfid_callback_handler, RC_RFID_CALLBACK_INTERVAL_MS);
|
||||
// g_rfid_timer_id = sys_timer_add(NULL, rc_rfid_callback_handler, RC_RFID_CALLBACK_INTERVAL_MS);
|
||||
rc_log("RFID handler timer started (ID: %d).\n", g_rfid_timer_id);
|
||||
}
|
||||
|
||||
// 3. 检查并启动BLE处理定时器
|
||||
if (g_ble_timer_id == 0) {
|
||||
g_ble_timer_id = sys_timer_add(NULL, rc_ble_callback_handler, RC_BLE_CALLBACK_INTERVAL_MS);
|
||||
// g_ble_timer_id = sys_timer_add(NULL, rc_ble_callback_handler, RC_BLE_CALLBACK_INTERVAL_MS);
|
||||
rc_log("BLE handler timer started (ID: %d).\n", g_ble_timer_id);
|
||||
}
|
||||
}
|
||||
@ -288,5 +383,7 @@ void test_task(void){
|
||||
void test_func_main(void){
|
||||
#if TEST_FUNCTION == 1
|
||||
// os_task_create(test_task, NULL, 1, 1024, 128, "rfid_test");
|
||||
os_task_create(contol_key_task, NULL, 1, 2048, 128, control_key_task_name);
|
||||
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user