From 1ed0e9100899ee15b4f5da46ff5f65db79b1fdf7 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期一, 29 六月 2020 23:23:46 +0800
Subject: [PATCH] 远程改参数测试完成

---
 Src/main.c |   94 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 64 insertions(+), 30 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 2f8c0ba..7d067a9 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -37,7 +37,7 @@
 
 /* Private define ------------------------------------------------------------*/
 /* USER CODE BEGIN PD */
-#define DEBUG_MODE
+//#define DEBUG_MODE
 #define Period               (uint32_t) 32768 - 1
 #define Timeout              (uint32_t) 32768 - 1//(32768 - 1)
 /* USER CODE END PD */
@@ -79,9 +79,20 @@
 uint32_t dev_id;
 uint16_t heartbeat_timer,poll_timer,sync_timer;
 uint8_t aRxBuffer[1],group_id;
-
-void IdleTask(void)
+uint8_t bat_percent=0,g_start_send_flag;
+extern u8 motor_state;
+uint16_t tyncpoll_time,lpsettime;
+uint16_t slottime,max_slotpos;
+uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
+extern uint8_t module_power;
+uint8_t imu_enable,motor_enable;	
+u16 GetLPTime(void)
 {
+	u16 count=HAL_LPTIM_ReadCounter(&hlptim1);
+ return count*LPTIMER_LSB/1000;
+}	
+void IdleTask(void)
+{u16 current_time;
 	
 			UART_CheckReceive();
 		UART_CheckSend();
@@ -90,16 +101,48 @@
 	{
 	SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 	}
-if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin))
-{
-	LED_TR_ON;
-	LED_TB_OFF;
-}else{
-	LED_TR_OFF;
+//if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin))
+//{
+//	LED_TR_ON;
+//	LED_TB_OFF;
+//}else{
+//	LED_TR_OFF;
+	current_time=GetLPTime();
+	//motor_state=2;
+	switch(motor_state)
+		{case 0:
+			MOTOR_OFF;
+			break;
+		case 1:
+			if(current_time<MOTOR_ONTIME)
+			{
+				MOTOR_ON;		
+			}else{
+				MOTOR_OFF;	
+			}	
+				
+			break;
+		case 2:
+			MOTOR_ON;	
+			break;
+		case 3:
+			MOTOR_OFF;
+			break;	
+	}
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
-	LED_TB_ON;
-	}
+		if(bat_percent>99)
+		{
+			LED_TR_OFF;
+			LED_TB_ON;
+		}else{
+			LED_TR_ON;
+			LED_TB_OFF;		
+		}		
+	}else{
+		LED_TR_OFF;
+		LED_TB_OFF;
+//	}
 }
 	if(g_com_map[CNT_UPDATE]==1)
 	{
@@ -136,16 +179,7 @@
 
 	}
 
-uint16_t tyncpoll_time,lpsettime;
-uint16_t slottime,max_slotpos;
-uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
-extern uint8_t module_power;
-uint8_t imu_enable,motor_enable;	
-u16 GetLPTime(void)
-{
-	u16 count=HAL_LPTIM_ReadCounter(&hlptim1);
- return count*LPTIMER_LSB/1000;
-}	
+
 u16 total_slotnum,current_slotnum;
 extern int32_t offsettimeus;
 
@@ -178,7 +212,7 @@
 	Usart1ParseDataCallback = UsartParseDataHandler;
 	parameter_init();
 	//deca_sleep(1000);
-	g_com_map[VERSION] = 0x0109;
+	g_com_map[VERSION] = 0x010A;
 #ifdef DEBUG_MODE
 //	g_com_map[DEV_ROLE]=1;
 //		g_com_map[DEV_ID]=1;
@@ -230,7 +264,6 @@
 uint32_t temp;
 extern uint8_t sleep_flag,m_bEUARTTxEn;
 uint16_t waitusart_timer;
-uint8_t bat_percent=0,g_start_send_flag;
 //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
 //{
 //  /* Set transmission flag: trasfer complete*/
@@ -274,7 +307,7 @@
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
   MX_LPTIM1_Init();
- // MX_USART1_UART_Init();
+  MX_USART1_UART_Init();
   MX_SPI1_Init();
   MX_ADC_Init();
   MX_DMA_Init();
@@ -288,6 +321,7 @@
 	dwt_entersleep();
 	waitusart_timer=1;
 	DW_DISABLE;
+
 //	HAL_Delay(2000);
 //	mcu_sleep();
 	//LED0_BLINK;		
@@ -313,17 +347,17 @@
 //		}else{
 //		HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET);
 //		}
-		LED_TR_BLINK;
+//		LED_TR_BLINK;
 		
 			bat_percent=Get_Battary();
 		if(bat_percent>15)
-		{//	LED0_ON;
+		{	LED0_ON;
 			Tag_App();
-		//	LED0_OFF;
+			LED0_OFF;
 		}else{
-			//LED_LR_ON;
+			LED_LR_ON;
 			Tag_App();
-		//	LED_LR_OFF;		
+			LED_LR_OFF;		
 		}
 		//LED0_BLINK;		
 		IdleTask();	
@@ -725,7 +759,7 @@
 	nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
 	if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
 	{
-	//	mcu_sleep();
+		mcu_sleep();
 	}
 }
 /* USER CODE END 4 */

--
Gitblit v1.9.3