From 7b8a137768f244173209f115738366efa7878b2f Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期五, 28 十月 2022 10:32:55 +0800
Subject: [PATCH] V1.36 1.增加UWB芯片电量检测 2.解决基站轮流丢包的问题。

---
 Src/main.c |  371 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 281 insertions(+), 90 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 5eb9090..21dc8d0 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -29,6 +29,10 @@
 #include "global_param.h"
 #include "TrackingDiff.h"
 #include "dw_app.h"
+#include "Flash.h"
+#define NSH1 0x0001
+#define GP   0x0002
+#define FLASH_HARDWARE_VERSION_MAP		(uint32_t)0x08004F00    //硬件版本号和批次信息位置
 //#define DEBUG_MODE
 /* USER CODE END Includes */
 
@@ -40,8 +44,7 @@
 /* Private define ------------------------------------------------------------*/
 /* USER CODE BEGIN PD */
 //#define DEBUG_MODE
-#define Period               (uint32_t) 32768 - 1
-#define Timeout              (uint32_t) 32768 - 1//(32768 - 1)
+
 /* USER CODE END PD */
 
 /* Private macro -------------------------------------------------------------*/
@@ -55,6 +58,8 @@
 LPTIM_HandleTypeDef hlptim1;
 
 SPI_HandleTypeDef hspi1;
+
+TIM_HandleTypeDef htim2;
 
 UART_HandleTypeDef huart1;
 DMA_HandleTypeDef hdma_usart1_rx;
@@ -72,6 +77,7 @@
 static void MX_SPI1_Init(void);
 static void MX_ADC_Init(void);
 static void MX_DMA_Init(void);
+static void MX_TIM2_Init(void);
 /* USER CODE BEGIN PFP */
 
 /* USER CODE END PFP */
@@ -87,6 +93,7 @@
 uint16_t slottime,max_slotpos;
 uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
 extern uint8_t module_power;
+extern float nomove_count;
 uint8_t imu_enable,motor_enable;	
 u16 GetLPTime(void)
 {
@@ -103,7 +110,9 @@
 	 Error_Handler();
 	}
 }
+uint16_t hardware_version,hardware_pici,hardware_type;
 uint8_t state5v;
+float motor_keeptime;
 void IdleTask(void)
 {u16 current_time;
 	
@@ -122,33 +131,64 @@
 //	LED_TR_OFF;
 	current_time=GetLPTime();
 	//motor_state=2;
-		if(g_com_map[MOTOR_ONTIME]>0)
-	{
-		g_com_map[MOTOR_ONTIME]--;
-		motor_state = 1;
-	}
+//		if(g_com_map[MOTOR_ONTIME]>0)
+//	{
+//		g_com_map[MOTOR_ONTIME]--;
+//		motor_state = 1;
+//	}
+if(0)//g_com_map[MOTOR_ENABLE])
+{
+    
+
 	switch(motor_state)
 		{case 0:
-			MOTOR_OFF;
+			if(hardware_type==NSH1)
+			{MOTOR_OFF;
+			}else if(hardware_type==GP)
+			{
+			HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
+			}
 			break;
 		case 1:
 			if(current_time<MOTOR_ONTIME)
 			{
-				MOTOR_ON;		
+				if(hardware_type==NSH1)
+				{MOTOR_ON;
+				}else if(hardware_type==GP)
+				{
+				HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
+				}	
 			}else{
-				MOTOR_OFF;	
-			}	
-				
+				if(hardware_type==NSH1)
+				{MOTOR_OFF;
+				}else if(hardware_type==GP)
+				{
+				HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
+				}	
+			}				
 			break;
 		case 2:
-			MOTOR_ON;	
+			if(hardware_type==NSH1)
+				{MOTOR_ON;
+				}else if(hardware_type==GP)
+				{
+				HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
+				}	
 			break;
 		case 3:
-			MOTOR_OFF;
+			if(hardware_type==NSH1)
+				{MOTOR_OFF;
+				}else if(hardware_type==GP)
+				{
+				HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
+				}	
 			break;	
 	}
+}
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
+		nomove_count = 0;
+       // bat_percent=Get_Battary();
 		if(state5v==0)
 		{
 			state5v=1;
@@ -200,64 +240,116 @@
 			delay_ms(100);
 				SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 		}
+			if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0)
+		{
+				SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
+		}
 
 	}
 
 
 u16 total_slotnum,current_slotnum;
 extern int32_t offsettimeus;
-
+u16 last_lpcount = 0;
 void SetNextPollTime(u16 time)
 {
   int32_t lpcount,lptime,target_time;
 
-	if(current_slotnum>=total_slotnum)
-		current_slotnum-=total_slotnum;
-	
-	target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
-	//if(target_time<90000)
-	{
-		lptime=target_time-offsettimeus;
-		lpcount = lptime/LPTIMER_LSB;
-	if(lpcount>LPTIMER_1S_COUNT)
-		lpcount-=LPTIMER_1S_COUNT;
-	if(lpcount<0)
-	{
-	lpcount+=LPTIMER_1S_COUNT;
-	}
+//	if(current_slotnum>=total_slotnum)
+//		current_slotnum-=total_slotnum;
+//	
+//	target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
+//	//if(target_time<90000)
+//	{
+//		lptime=target_time-offsettimeus;
+//		lpcount = lptime/LPTIMER_LSB;
+//	if(lpcount>LPTIMER_1S_COUNT)
+//		lpcount-=LPTIMER_1S_COUNT;
+//	if(lpcount<0)
+//	{
+//	lpcount+=LPTIMER_1S_COUNT;
+//	}
+    lpcount = last_lpcount+g_com_map[COM_INTERVAL]*32.768;
+    while(lpcount>LPTIMER_1S_COUNT)
+    {
+        lpcount-=LPTIMER_1S_COUNT;
+    }
+    last_lpcount = lpcount;
 	__HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
+
 }
+
+void HardWareTypeDiffConfig(void)
+{
+GPIO_InitTypeDef GPIO_InitStruct = {0};
+//hardware_type=2;
+if(hardware_type == 0)
+    hardware_type = 1;
+	switch(hardware_type)
+		{
+        case 1:
+	  
+		 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;
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+			break;
+		case 2:
+			MX_TIM2_Init();
+		//BarInit();
+			break;
+		}
 }
+u8 active_flag,nomovesleeptime;
 void Program_Init(void)
 {	float temp;
 	uint16_t temp2;
 	uint16_t i;
 	Usart1ParseDataCallback = UsartParseDataHandler;
 	parameter_init();
+    hardware_version = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP);
+	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] = 0x010f;
-#ifdef DEBUG_MODE
-//	g_com_map[DEV_ROLE]=1;
-//		g_com_map[DEV_ID]=1;
-	g_com_map[COM_INTERVAL]=100;
-//	g_com_map[MAX_REPORT_ANC_NUM]=1;
-	g_com_map[NOMOVESLEEP_TIME]=10;
-#endif
-		
-	
-	module_power = g_com_map[POWER];
+	g_com_map[VERSION] = (1<<8)|36;
+    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]*0.4)+2;
+	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];
+    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;
+//	g_com_map[COM_INTERVAL]=100;
+//	g_com_map[MAX_REPORT_ANC_NUM]=1;
+//	g_com_map[NOMOVESLEEP_TIME]=10;
+#endif
+		if(g_com_map[COM_INTERVAL]==0)
+	{
+	  g_com_map[COM_INTERVAL]=100;
+	}
+	 if(module_power>67)
+		{module_power=67;}
+		if(module_power<0)
+		{module_power=0;}
+
 	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
@@ -304,12 +396,44 @@
   * @brief  The application entry point.
   * @retval int
   */
+uint16_t temp2; 
+float dw_vbat,last_vbat;
+uint8_t Get_Battary_UWB(void)
+{
+    static uint8_t first = 1;
+    static float last_value = 100;   
+    static uint16_t bat_count = 0;
+    //if(bat_count++%600==0)
+    {
+	temp2=dwt_readtempvbat(1);
+	dw_vbat=(float)((temp2&0xff)-173)/173+3.3;
+    if(fabs(dw_vbat-dw_vbat)>0.2)
+    {
+        last_vbat = dw_vbat;
+        return last_value;
+    }
+    last_vbat = dw_vbat;      
+	if(dw_vbat>=3.0)
+	{
+		if(first)
+		{
+            first = 0;			
+			last_value =(dw_vbat-3.0)*167;//(bat_volt-3.5)/0.6*100
+		}
+		last_value = 0.9*last_value + (dw_vbat-3.0)*16.7;
+	if(last_value>100)
+		last_value = 100;
+	if(last_value<0)
+		last_value = 0;
+    }
+    }
+	return last_value;	       
+}
 int main(void)
 {
   /* USER CODE BEGIN 1 */
 
   /* USER CODE END 1 */
-  
 
   /* MCU Configuration--------------------------------------------------------*/
 
@@ -330,19 +454,21 @@
   /* 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_ADC_Init();
+ 
+//  MX_TIM2_Init();
   /* USER CODE BEGIN 2 */
 	LED_LG_ON;
 	Program_Init();
-	LIS3DH_Data_Init();	
+//	LIS3DH_Data_Init();	
 	Dw1000_Init();
 	Dw1000_App_Init();
-	
+//	HardWareTypeDiffConfig();
 	dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
-	//dwt_entersleep();
+	dwt_entersleep();
 	waitusart_timer=tag_frequency*USART_KEEPWAKE_TIME;;
 	DW_DISABLE;
 	 if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
@@ -363,7 +489,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;	
@@ -374,9 +500,9 @@
 //		}else{
 //		HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET);
 //		}
-//		LED_TR_BLINK;
+//		LED_TR_BLINK;s
 		
-			bat_percent=Get_Battary();
+			
 		if(bat_percent>15)
 		{	LED_TB_ON;
 			Tag_App();
@@ -394,7 +520,8 @@
 		}
 			if(m_bEUARTTxEn==0&&waitusart_timer==0)
 			{	
-#ifndef DEBUG_MODE				
+#ifndef DEBUG_MODE	
+if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
 				HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
 #endif
 			}
@@ -422,14 +549,14 @@
   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
 
-  /** Configure the main internal regulator output voltage 
+  /** Configure the main internal regulator output voltage
   */
   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
-  /** Configure LSE Drive Capability 
+  /** Configure LSE Drive Capability
   */
   HAL_PWR_EnableBkUpAccess();
   __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
-  /** Initializes the CPU, AHB and APB busses clocks 
+  /** Initializes the CPU, AHB and APB busses clocks
   */
   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
   RCC_OscInitStruct.LSEState = RCC_LSE_ON;
@@ -443,7 +570,7 @@
   {
     Error_Handler();
   }
-  /** Initializes the CPU, AHB and APB busses clocks 
+  /** Initializes the CPU, AHB and APB busses clocks
   */
   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
@@ -483,7 +610,7 @@
   /* USER CODE BEGIN ADC_Init 1 */
 
   /* USER CODE END ADC_Init 1 */
-  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
+  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
   */
   hadc.Instance = ADC1;
   hadc.Init.OversamplingMode = DISABLE;
@@ -506,7 +633,7 @@
   {
     Error_Handler();
   }
-  /** Configure for the selected ADC regular channel to be converted. 
+  /** Configure for the selected ADC regular channel to be converted.
   */
   sConfig.Channel = ADC_CHANNEL_1;
   sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
@@ -594,6 +721,69 @@
 }
 
 /**
+  * @brief TIM2 Initialization Function
+  * @param None
+  * @retval None
+  */
+static void MX_TIM2_Init(void)
+{
+
+  /* USER CODE BEGIN TIM2_Init 0 */
+
+  /* USER CODE END TIM2_Init 0 */
+
+  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+  TIM_MasterConfigTypeDef sMasterConfig = {0};
+  TIM_OC_InitTypeDef sConfigOC = {0};
+
+  /* USER CODE BEGIN TIM2_Init 1 */
+
+  /* USER CODE END TIM2_Init 1 */
+  htim2.Instance = TIM2;
+  htim2.Init.Prescaler = 9;
+  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+  htim2.Init.Period = 1171;
+  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
+  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sConfigOC.OCMode = TIM_OCMODE_PWM1;
+  sConfigOC.Pulse = 599;
+  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
+  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
+  if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN TIM2_Init 2 */
+//if(HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3) != HAL_OK)
+//  {
+//    /* Starting Error */
+//    Error_Handler();
+//  }
+  /* USER CODE END TIM2_Init 2 */
+  HAL_TIM_MspPostInit(&htim2);
+
+}
+
+/**
   * @brief USART1 Initialization Function
   * @param None
   * @retval None
@@ -640,10 +830,10 @@
 
 }
 
-/** 
+/**
   * Enable DMA controller clock
   */
-static void MX_DMA_Init(void) 
+static void MX_DMA_Init(void)
 {
 
   /* DMA controller clock enable */
@@ -675,7 +865,7 @@
   HAL_GPIO_WritePin(GPIOA, SCL_Pin|SDA_Pin|SPI_CS_Pin, GPIO_PIN_SET);
 
   /*Configure GPIO pin Output Level */
-  HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|MOTOR_Pin, GPIO_PIN_SET);
+  HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|PWR_CTL_Pin, GPIO_PIN_SET);
 
   /*Configure GPIO pin Output Level */
   HAL_GPIO_WritePin(GPIOB, LED1_G_Pin|LED1_R_Pin|LED2_R_Pin, GPIO_PIN_RESET);
@@ -688,12 +878,6 @@
   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
-  /*Configure GPIO pin : BAT_MEAS_Pin */
-  GPIO_InitStruct.Pin = BAT_MEAS_Pin;
-  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
-  GPIO_InitStruct.Pull = GPIO_NOPULL;
-  HAL_GPIO_Init(BAT_MEAS_GPIO_Port, &GPIO_InitStruct);
 
   /*Configure GPIO pins : SCL_Pin SDA_Pin */
   GPIO_InitStruct.Pin = SCL_Pin|SDA_Pin;
@@ -722,18 +906,18 @@
   GPIO_InitStruct.Pull = GPIO_PULLUP;
   HAL_GPIO_Init(USER_KEY_GPIO_Port, &GPIO_InitStruct);
 
-  /*Configure GPIO pins : MOTOR_Pin LED1_G_Pin LED1_R_Pin LED2_R_Pin */
-  GPIO_InitStruct.Pin = MOTOR_Pin|LED1_G_Pin|LED1_R_Pin|LED2_R_Pin;
-  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-  GPIO_InitStruct.Pull = GPIO_NOPULL;
-  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
   /*Configure GPIO pin : INPUT_5V_Pin */
   GPIO_InitStruct.Pin = INPUT_5V_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
   GPIO_InitStruct.Pull = GPIO_PULLDOWN;
   HAL_GPIO_Init(INPUT_5V_GPIO_Port, &GPIO_InitStruct);
+
+  /*Configure GPIO pins : LED1_G_Pin LED1_R_Pin LED2_R_Pin PWR_CTL_Pin */
+  GPIO_InitStruct.Pin = LED1_G_Pin|LED1_R_Pin|LED2_R_Pin|PWR_CTL_Pin;
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
   /*Configure GPIO pins : DW_WKUP_Pin DW_CTRL_Pin LED2_G_Pin */
   GPIO_InitStruct.Pin = DW_WKUP_Pin|DW_CTRL_Pin|LED2_G_Pin;
@@ -780,7 +964,6 @@
   HAL_PWR_EnterSTANDBYMode();	
 }
 extern uint8_t tx_near_msg[80],stationary_flag;
-extern float nomove_count;
 float key_keeptime;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
@@ -790,30 +973,38 @@
 	current_slotnum++;
 	SetNextPollTime(tyncpoll_time);
 	nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
+    if(motor_keeptime>0)
+	{	
+	motor_keeptime-=(float)g_com_map[COM_INTERVAL]/1000;
+	}
 	if(!GET_USERKEY)
 	{
 		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{
 		key_keeptime=0;
 	}
-	if(nomove_count>STATIONARY_TIME)
-	{
-		stationary_flag = 1;
-	}else{
-		stationary_flag = 0;
-	}
-if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
-	{
-		tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
-	}
-	if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
-	{
-		mcu_sleep();
-	}
+//	if(nomove_count>STATIONARY_TIME)
+//	{
+//		stationary_flag = 1;
+//	}else{
+//		stationary_flag = 0;
+//	}
+//if(nomove_count>=nomovesleeptime-1&&imu_enable)
+//	{
+//		tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
+//	}
+//	if(nomove_count>nomovesleeptime&&imu_enable)
+//	{
+//		mcu_sleep();
+//	}
 }
 /* USER CODE END 4 */
 
@@ -838,7 +1029,7 @@
   * @retval None
   */
 void assert_failed(uint8_t *file, uint32_t line)
-{ 
+{
   /* USER CODE BEGIN 6 */
   /* User can add his own implementation to report the file name and line number,
      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

--
Gitblit v1.9.3