From deaaa18131675b17ef4fa49befa80cfb09778898 Mon Sep 17 00:00:00 2001 From: zhangbo <zhangbo@qq.com> Date: 星期五, 13 六月 2025 18:09:02 +0800 Subject: [PATCH] 这是工卡机测试版本 --- keil/include/main/main.c | 78 +++++++++++++++++++++++++++++++++++--- 1 files changed, 71 insertions(+), 7 deletions(-) diff --git a/keil/include/main/main.c b/keil/include/main/main.c index e1f2361..070b989 100644 --- a/keil/include/main/main.c +++ b/keil/include/main/main.c @@ -46,6 +46,9 @@ #define UWB_MEASUREMENT_INTERVAL 5 #define UWB_MEASUREMENT_INTERVAL_SLEEP 30 +#define INACTIVE_TIMEOUT 30 + +uint8_t input5v_flag=0; extern uint8_t mUsartReceivePack[100]; extern uint8_t mUsart2ReceivePack[150]; extern uint8_t state5V_prase_flag,gps_prase_flag; @@ -273,6 +276,7 @@ } } +uint16_t gaodu; uint8_t guanjiflag; uint8_t heartbeasend_flag; uint32_t guanjiflagtime; @@ -364,6 +368,7 @@ HIDO_TimerTick(); // if(nomove_count<=g_com_map[NOMOVESLEEP_TIME])//防止溢出 nomove_count++; + gaodu=GetPressAndHeight()*100; // else{ // nomove_count=g_com_map[NOMOVESLEEP_TIME]+1; // } @@ -422,6 +427,57 @@ delaysleep_count--; } +#ifdef JIBU_XIUMIAN + +uint16_t sleep_time=0; +uint32_t state_start_time_jibu=0; +uint8_t exercise_state=0; +uint32_t step_count = 0; // 步数计数 +uint32_t last_step_count = 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_jibu = uwb_time_count; + state_start_time=uwb_time_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; + exercise_state=1; + last_step_count = step_count; + + } + else + { + // 步数没有变化,检查是否需要切换到休眠状态 + if (current_state == STATE_NORMAL) + { + uint32_t inactive_time = uwb_time_count - state_start_time_jibu; + if (inactive_time >= INACTIVE_TIMEOUT) + { // 30秒后切换到休眠状态 + current_state = STATE_SLEEP; + exercise_state=2; + state_start_time_jibu=uwb_time_count; + } + } + } +} +#endif static void pca_handler(enum IO_PIN_T pin) { PCA9555_readdata(PCA9555_DEVICE_ADDR,pca9555writedata_input);//读输入寄存器的值 @@ -533,7 +589,7 @@ // } g_com_map[MODBUS_MODE] = 0; log_4g_enable_flag=g_com_map[LOG_4G_ENABLE]; - g_com_map[VERSION] = (1<<8)|22; + g_com_map[VERSION] = (1<<8)|23; LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); @@ -574,6 +630,10 @@ { if(read_5v_input_pca()) { + if(input5v_flag==0) + { + NVIC_SystemReset(); + } if(state5v==0) { state5v=1; @@ -780,7 +840,7 @@ else if(current_state==STATE_SLEEP) { elapsed_time_jibu = uwb_time_count - state_start_time; - switch(elapsed_time_jibu==1) + switch(elapsed_time_jibu) { case UWB_OPEN_COUNT: CloseUWB(); @@ -849,7 +909,6 @@ int test1,test3; uint32_t test4; extern uint8_t receive_flag; -uint16_t gaodu; static void app_wdt_callback(void *dev, uint32_t status) { ASSERT(status, "WDT TIMEOUT,程序复位"); @@ -868,14 +927,15 @@ boot_deinit(); board_pins_config(); gpio_open(); - IIC2_Init(); - Accelerometer_Init(); + IIC2_Init(); + Accelerometer_Init(); // delay_ms(100); BarInit(); // delay_ms(100); // gaodu=GetPressAndHeight(); PCA9555_init(); - board_debug_console_open_baud(TRACE_PORT_UART1,BAUD_115200); + board_debug_console_open_baud(TRACE_PORT_UART1,BAUD_921600); + pca_input_detection_init(pca_handler);//pca检测输入 // while(1); // Reset reason reset_cause_get(); @@ -933,6 +993,7 @@ delay_ms(500); Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF); } + g_com_map[MODBUS_MODE] = 0; state5v=0; state5V_prase_flag=state5v; @@ -947,8 +1008,10 @@ sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 PCA9555_Set_One_Value_Output(ADC_MINIUS,0);//拉低 adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 - pca_input_detection_init(pca_handler);//pca检测输入 + gaodu=GetPressAndHeight()*100; + if(read_init_5v_input_pca()) + {input5v_flag=1;} while (1) { @@ -969,5 +1032,6 @@ } IMUTask(); IdleTask(); + check_step_and_update_state(); } } -- Gitblit v1.9.3