From 232d14746937bec0a0396f764e71ceeb30f19b34 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期一, 19 九月 2022 17:50:57 +0800 Subject: [PATCH] 1 --- Src/main.c | 57 ++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Src/main.c b/Src/main.c index e9843db..89182e9 100644 --- a/Src/main.c +++ b/Src/main.c @@ -188,6 +188,7 @@ if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) { nomove_count = 0; + bat_percent=Get_Battary(); if(state5v==0) { state5v=1; @@ -282,7 +283,7 @@ { case 1: - HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET); GPIO_InitStruct.Pin = MOTOR_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -295,6 +296,8 @@ break; } } +int16_t g_commap_antdelay; +u8 active_flag,nomovesleeptime; void Program_Init(void) { float temp; uint16_t temp2; @@ -305,7 +308,27 @@ hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2); hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4); //deca_sleep(1000); - g_com_map[VERSION] = 0x0119; + g_com_map[VERSION] = (1<<8)|33; + active_flag = g_com_map[ACTIVE_INDEX]; + module_power = g_com_map[POWER]; + imu_enable=g_com_map[IMU_ENABLE]; + motor_enable=g_com_map[MOTOR_ENABLE]; + + group_id=g_com_map[GROUP_ID]; + dev_id = g_com_map[DEV_ID]; + slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3; + max_slotpos=g_com_map[COM_INTERVAL]/slottime; + tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime; + slot_startcount=tyncpoll_time*1000/LPTIMER_LSB; + lastpoll_time=tyncpoll_time; + tag_frequency = 1000/g_com_map[COM_INTERVAL]; + total_slotnum = 1000/g_com_map[COM_INTERVAL]; + nomovesleeptime = g_com_map[NOMOVESLEEP_TIME]; + if(active_flag==0) + { + imu_enable=1; + nomovesleeptime =10; + } #ifdef DEBUG_MODE // g_com_map[DEV_ROLE]=1; // g_com_map[DEV_ID]=1; @@ -321,19 +344,11 @@ {module_power=67;} if(module_power<0) {module_power=0;} - module_power = g_com_map[POWER]; - imu_enable=g_com_map[IMU_ENABLE]; - motor_enable=g_com_map[MOTOR_ENABLE]; - - group_id=g_com_map[GROUP_ID]; - dev_id = g_com_map[DEV_ID]; - slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3; - max_slotpos=g_com_map[COM_INTERVAL]/slottime; - tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime; - slot_startcount=tyncpoll_time*1000/LPTIMER_LSB; - lastpoll_time=tyncpoll_time; - tag_frequency = 1000/g_com_map[COM_INTERVAL]; - total_slotnum = 1000/g_com_map[COM_INTERVAL]; + if(g_com_map[ANT_LENGTH]>10000) + { + g_com_map[ANT_LENGTH] = 0; + } + g_commap_antdelay = -g_com_map[DIST_OFFSET]; current_slotnum=1; current_time=GetLPTime(); if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK) //system time is 1010ms 1 puls=30.518us @@ -414,7 +429,7 @@ /* USER CODE BEGIN 2 */ LED_LG_ON; Program_Init(); - LIS3DH_Data_Init(); + Accelerometer_Init(); Dw1000_Init(); Dw1000_App_Init(); HardWareTypeDiffConfig(); @@ -440,7 +455,7 @@ /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - if(g_start_send_flag) + if(g_start_send_flag&&active_flag) { static uint16_t blink_count=0; SystemClock_Config(); g_start_send_flag = 0; @@ -933,6 +948,10 @@ key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000; if(key_keeptime>=KEY_KEEPRESET_TIME) { + g_com_map[ACTIVE_INDEX]=!active_flag; + save_com_map_to_flash(); + MOTOR_ON; + HAL_Delay(2000); SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; } }else{ @@ -944,11 +963,11 @@ }else{ stationary_flag = 0; } -if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable) +if(nomove_count>=nomovesleeptime-1&&imu_enable) { tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT; } - if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable) + if(nomove_count>nomovesleeptime&&imu_enable) { mcu_sleep(); } -- Gitblit v1.9.3