From 950676ea7305bb90e08ec88bcac40e4c47fcefca Mon Sep 17 00:00:00 2001 From: zhangbo <zhangbo@qq.com> Date: 星期四, 15 五月 2025 11:06:38 +0800 Subject: [PATCH] 添加计步以及测距 --- keil/include/main/main.c | 97 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 70 insertions(+), 27 deletions(-) diff --git a/keil/include/main/main.c b/keil/include/main/main.c index 231750a..b4b0ad5 100644 --- a/keil/include/main/main.c +++ b/keil/include/main/main.c @@ -94,12 +94,15 @@ /****************************************************************引脚宏定义**************************************************/ -#define UWB_OPEN_COUNT 1 -#define UWB_MEASUREMENT_INTERVAL 3 -#define UWB_MEASUREMENT_INTERVAL_SLEEP 60 +#define UWB_OPEN_COUNT 1 // UWB每次开启持续时间(秒) +#define UWB_MEASUREMENT_INTERVAL 3 // 正常状态测距周期 +#define UWB_MEASUREMENT_INTERVAL_SLEEP 60 // 休眠状态测距周期 +#define INACTIVE_TIMEOUT 30 // 无步数变化超时时间(秒) +bool uwb_is_on = false; // UWB当前状态标记 void test_Delay_us(uint16_t time); void Lora_UploadHeartBeartPoll(void); +void upload_apppoll(); extern uint8_t mUsartReceivePack[100]; extern uint8_t mUsart2ReceivePack[150]; extern uint8_t state5V_prase_flag,gps_prase_flag; @@ -338,15 +341,14 @@ HIDO_TimerTick(); // lora_tx_flag++; uwb_time_count++; - if(uwb_time_count>10000) - { - uwb_time_count=0; - } + upload_apppoll(); + step_count = mir3da_get_step(); // 获取步数 + if (current_state == STATE_NORMAL) { sleep_time++; } - step_count = mir3da_get_step(); // 获取步数 + if(!read_5v_input_pca()) { @@ -390,28 +392,43 @@ } uint16_t sleep_time=0; +uint32_t state_start_time_jibu=0; void check_step_and_update_state(void) { if ((step_count != last_step_count)) { // 步数有变化,重置状态为正常状态 + last_step_count = step_count; if(current_state == STATE_SLEEP) { - state_start_time = uwb_time_count; + state_start_time_jibu = uwb_time_count; + state_start_time=uwb_time_count; } - current_state = STATE_NORMAL; - last_step_count = step_count; +// if (current_state != STATE_NORMAL) +// { +// // 关闭可能正在运行的UWB +// if (uwb_is_on) { +// CloseUWB(); +// UWB_LED_OFF; +// uwb_is_on = false; +// } +// current_state = STATE_NORMAL; +// state_start_time = uwb_time_count; // 重置测距周期 +// } + current_state = STATE_NORMAL; + last_step_count = step_count; + } else { // 步数没有变化,检查是否需要切换到休眠状态 if (current_state == STATE_NORMAL) { -// sleep_time = uwb_time_count - state_start_time; - if (sleep_time >= 30) + uint32_t inactive_time = uwb_time_count - state_start_time_jibu; + if (inactive_time >= INACTIVE_TIMEOUT) { // 30秒后切换到休眠状态 -// current_state = STATE_SLEEP; - sleep_time = 0; + current_state = STATE_SLEEP; + state_start_time_jibu=uwb_time_count; } } } @@ -476,9 +493,9 @@ ip2 = (g_com_map[TCP_IP_2]>>12&0xf)*1000+(g_com_map[TCP_IP_2]>>8&0xf)*100+(g_com_map[TCP_IP_2]>>4&0xf)*10+(g_com_map[TCP_IP_2]&0xf); ip3 = (g_com_map[TCP_IP_3]>>12&0xf)*1000+(g_com_map[TCP_IP_3]>>8&0xf)*100+(g_com_map[TCP_IP_3]>>4&0xf)*10+(g_com_map[TCP_IP_3]&0xf); port = g_com_map[TCP_PORT]; - g_com_map[VERSION] = (1<<8)|11; + g_com_map[VERSION] = (1<<8)|12; LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); - LOG_INFO(TRACE_MODULE_APP,"固件版本:BGK-mk+蓝牙V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); + LOG_INFO(TRACE_MODULE_APP,"固件版本:BGK-mk+蓝牙薄工卡V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port); } @@ -522,9 +539,15 @@ break; } } - NVIC_SystemReset(); + sys_reset(0); +// NVIC_SystemReset(); // input5vflag=1; } + else + { + +// sys_reset(0); + } } int bind_check(void) @@ -643,6 +666,7 @@ //串口1 io_pin_mux_set(UART1_RX, IO_FUNC4); io_pin_mux_set(UART1_TX, IO_FUNC4); + board_debug_console_open(TRACE_PORT_UART1,BAUD_115200); } void spi_init() @@ -734,13 +758,14 @@ { case UWB_OPEN_COUNT: UWB_LED_OFF; + LORA_LED_OFF; + LoraReportPoll(); CloseUWB(); break; case UWB_MEASUREMENT_INTERVAL: - UWB_LED_ON; - OpenUWB(); - LoraReportPoll(); + PCA9555_Set_One_Value_Output(BT_IRQ ,0); + OpenUWB(); state_start_time = uwb_time_count; break; } @@ -752,13 +777,14 @@ { case UWB_OPEN_COUNT: UWB_LED_OFF; + LORA_LED_OFF; + LoraReportPoll(); CloseUWB(); break; case UWB_MEASUREMENT_INTERVAL_SLEEP: - UWB_LED_ON; - OpenUWB(); - LoraReportPoll(); + PCA9555_Set_One_Value_Output(BT_IRQ ,0); + OpenUWB(); state_start_time = uwb_time_count; break; } @@ -811,16 +837,33 @@ //#endif Uwbinit(); // boot_deinit(); - -// OpenUWB(); while (1) { BT_LED_OFF; // Lora_Tx_Poll(); // uwb_app_poll(); check_step_and_update_state(); - upload_apppoll(); + IdleTask(); IMUTask(); +// if(1) +// { +//// test1=gpio_pin_get_val(_4G_USART_RX_Pin); +// uint32_t lock; +// //flag_4guart_needinit = 1; +//// Internet_Poll(); +//// HIDO_ATLitePoll(); +//// HIDO_TimerPoll(); +//// TCPClient_Poll(); +// +// // delay_us(300000); +// trace_flush(); +// lock = int_lock(); +// power_enter_power_down_mode(0); +// uart_receive(UART_ID0,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart0_receive_callback); +//// test3=gpio_pin_get_val(_4G_USART_RX_Pin); +// //LOG_INFO(TRACE_MODULE_APP, "进入休眠\r\n"); +// int_unlock(lock); +// } } } -- Gitblit v1.9.3