From 34a46bcbc3a65ff69369a697c7a10d5992be6161 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期三, 02 八月 2023 17:06:11 +0800 Subject: [PATCH] V1.37 --- Src/main.c | 80 +++++++++++++++++++++++++--------------- 1 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Src/main.c b/Src/main.c index e9843db..b5c4dae 100644 --- a/Src/main.c +++ b/Src/main.c @@ -75,7 +75,7 @@ static void MX_LPTIM1_Init(void); static void MX_USART1_UART_Init(void); static void MX_SPI1_Init(void); -static void MX_ADC_Init(void); +void MX_ADC_Init(void); static void MX_DMA_Init(void); static void MX_TIM2_Init(void); /* USER CODE BEGIN PFP */ @@ -188,6 +188,7 @@ if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) { nomove_count = 0; + bat_percent=Get_VDDVlotage(); if(state5v==0) { state5v=1; @@ -226,10 +227,7 @@ } if(g_com_map[CNT_REBOOT]==1) { - g_com_map[CNT_REBOOT]=0; - g_com_map[MAP_SIGN_INDEX]=0; - save_com_map_to_flash(); - delay_ms(100); + ReturnFactory(); SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader } if(g_com_map[CNT_RESTART]==1) @@ -282,7 +280,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 +293,8 @@ break; } } +int16_t g_commap_antdelay; +u8 active_flag,nomovesleeptime; void Program_Init(void) { float temp; uint16_t temp2; @@ -305,7 +305,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)|37; + 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 +341,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 @@ -374,6 +386,11 @@ { //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader } +void MX_ADC_DeInit(void) +{ + HAL_ADC_DeInit(&hadc); + HAL_ADCEx_DisableVREFINT(); +} /* USER CODE END 0 */ /** @@ -405,16 +422,15 @@ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_LPTIM1_Init(); - MX_DMA_Init(); + MX_DMA_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); MX_ADC_Init(); - -// MX_TIM2_Init(); + MX_TIM2_Init(); /* USER CODE BEGIN 2 */ LED_LG_ON; Program_Init(); - LIS3DH_Data_Init(); + Accelerometer_Init(); Dw1000_Init(); Dw1000_App_Init(); HardWareTypeDiffConfig(); @@ -440,7 +456,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; @@ -453,7 +469,7 @@ // } // LED_TR_BLINK;s - bat_percent=Get_Battary(); + bat_percent=Get_VDDVlotage(); if(bat_percent>15) { LED_TB_ON; Tag_App(); @@ -549,7 +565,7 @@ * @param None * @retval None */ -static void MX_ADC_Init(void) +void MX_ADC_Init(void) { /* USER CODE BEGIN ADC_Init 0 */ @@ -586,7 +602,7 @@ } /** Configure for the selected ADC regular channel to be converted. */ - sConfig.Channel = ADC_CHANNEL_1; + sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { @@ -933,6 +949,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 +964,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