| | |
| | | #define UWB_MEASUREMENT_INTERVAL 5 |
| | | #define UWB_MEASUREMENT_INTERVAL_SLEEP 30 |
| | | |
| | | #define INACTIVE_TIMEOUT 30 |
| | | |
| | | extern uint8_t mUsartReceivePack[100]; |
| | | extern uint8_t mUsart2ReceivePack[150]; |
| | | extern uint8_t state5V_prase_flag,gps_prase_flag; |
| | |
| | | ////// LOG_INFO(TRACE_MODULE_APP, "从休眠出来\r\n"); |
| | | //// int_unlock(lock); |
| | | } |
| | | uint8_t jiancebat_percent_flag; |
| | | static void adc_callback(void *data, uint32_t number) |
| | | { |
| | | uint32_t *result = (uint32_t *)data; |
| | |
| | | bat_percent=100; |
| | | if(bat_percent<0) |
| | | bat_percent=0; |
| | | jiancebat_percent_flag=1; |
| | | // if(fVoltage_mv<3300) |
| | | // { |
| | | // //power_low_flag=1; |
| | |
| | | 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);//读输入寄存器的值 |
| | |
| | | // } |
| | | g_com_map[MODBUS_MODE] = 0; |
| | | log_4g_enable_flag=g_com_map[LOG_4G_ENABLE]; |
| | | g_com_map[VERSION] = (1<<8)|20; |
| | | |
| | | g_com_map[VERSION] = (1<<8)|22; |
| | | |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); |
| | | LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位工卡 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); |
| | |
| | | uint8_t bat_percent_old=100; |
| | | uint8_t input5vflag; |
| | | extern uint8_t ota_flag; |
| | | uint8_t bat_percent_only_one=1; |
| | | extern uint8_t jiancebat_percent_flag; |
| | | void IdleTask(void) |
| | | { |
| | | if(read_5v_input_pca()) |
| | |
| | | while(1) |
| | | { |
| | | nomove_count = 0; |
| | | wdt_ping(WDT_ID0);//喂狗 |
| | | // adctick = HIDO_TimerGetTick(); |
| | | if(HIDO_TimerGetTick()-adctick>600) //10分钟采样一次 电量 |
| | | { |
| | |
| | | powerled=0; |
| | | Set4LEDColor(LEDOFF,LEDOFF,LEDOFF,LEDOFF); |
| | | } |
| | | if(bat_percent<1) |
| | | if(bat_percent<1&&bat_percent_only_one&&jiancebat_percent_flag) |
| | | { |
| | | userkey_state=3; |
| | | heartbeasend_flag = 1; |
| | | guanjiflag=1; |
| | | guanjiflagtime=HIDO_TimerGetTick(); |
| | | bat_percent_only_one=0; |
| | | } |
| | | if(guanjiflag) |
| | | { |
| | |
| | | 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(); |
| | |
| | | int test1,test3; |
| | | uint32_t test4; |
| | | extern uint8_t receive_flag; |
| | | float gaodu; |
| | | uint16_t gaodu; |
| | | static void app_wdt_callback(void *dev, uint32_t status) |
| | | { |
| | | ASSERT(status, "WDT TIMEOUT,程序复位"); |
| | | //LOG_INFO(TRACE_MODULE_APP, "程序卡死,看门狗复位"); |
| | | } |
| | | struct WDT_CFG_T app_wdt_cfg = { |
| | | .timeout = 32768 * 30, |
| | | .rst_en = true, |
| | | .int_en = true, |
| | | .callback = app_wdt_callback, |
| | | }; |
| | | int main(void) |
| | | { |
| | | __enable_irq(); |
| | |
| | | boot_deinit(); |
| | | board_pins_config(); |
| | | gpio_open(); |
| | | IIC2_Init(); |
| | | Accelerometer_Init(); |
| | | BarInit(); |
| | | 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_115200); |
| | | // while(1); |
| | | // Reset reason |
| | | reset_cause_get(); |
| | | reset_cause_clear(); |
| | |
| | | TCPClient_Init_1(); |
| | | } |
| | | // HTTPClient_Init(); |
| | | |
| | | wdt_open(WDT_ID0,&app_wdt_cfg);//30s检测喂狗 |
| | | LED_output_init();//配置彩色灯引脚 |
| | | |
| | | |
| | |
| | | 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(); |
| | | gaodu=GetPressAndHeight()*100; |
| | | while (1) |
| | | { |
| | | |
| | |
| | | HIDO_TimerPoll(); |
| | | HIDO_ATLitePoll(); |
| | | TCPClient_Poll(); |
| | | wdt_ping(WDT_ID0);//喂狗 |
| | | if(g_com_map[RTCMMODE_INDEX] == RTCMMODE_TCP) |
| | | { |
| | | TCPClient_Poll_1(); |
| | |
| | | } |
| | | IMUTask(); |
| | | IdleTask(); |
| | | check_step_and_update_state(); |
| | | } |
| | | } |