浏览代码

铝壳方案代码完善, 包括播放语音,自标定机械热噪声暂时不用, 检测速度变化降为 2km/h 等

guoqiang 1 年之前
父节点
当前提交
2a15b7e641
共有 10 个文件被更改,包括 4313 次插入3095 次删除
  1. 46 6
      Device/gpio.c
  2. 36 6
      Device/gpio.h
  3. 74 56
      Project/BVACS.uvguix.孙凯
  4. 2589 1710
      Project/JLinkLog.txt
  5. 1502 1265
      Project/Listings/BVACS_20240130.map
  6. 3 3
      User/cfg.c
  7. 5 3
      User/main_task.c
  8. 42 32
      User/process.c
  9. 5 4
      User/process.h
  10. 11 10
      User/protocol.c

+ 46 - 6
Device/gpio.c

@@ -65,22 +65,38 @@ void GPIO_LedInit(void)
 {
     /*初始化引脚功能,有部分引脚上电默认为非GPIO,必须选择其功能为GPIO才能作为GPIO使用*/
 	  GPIO_DRV_SetMuxModeSel(LED1_PORT, LED1_PIN, PORT_MUX_AS_GPIO); /*功能复用选择*/
-    GPIO_DRV_SetMuxModeSel(LED2_PORT, LED2_PIN, PORT_MUX_AS_GPIO);
+    //GPIO_DRV_SetMuxModeSel(LED2_PORT, LED2_PIN, PORT_MUX_AS_GPIO);
     GPIO_DRV_SetMuxModeSel(LED3_PORT, LED3_PIN, PORT_MUX_AS_GPIO); /*功能复用选择*/
     GPIO_DRV_SetMuxModeSel(LED4_PORT, LED4_PIN, PORT_MUX_AS_GPIO);
 	
 	
+		GPIO_DRV_SetMuxModeSel(K0_PORT, K0_PIN, PORT_MUX_AS_GPIO);
+		GPIO_DRV_SetMuxModeSel(K1_PORT, K1_PIN, PORT_MUX_AS_GPIO);
+		GPIO_DRV_SetMuxModeSel(K2_PORT, K2_PIN, PORT_MUX_AS_GPIO);
+		GPIO_DRV_SetMuxModeSel(K3_PORT, K3_PIN, PORT_MUX_AS_GPIO);
+
+	
 	  GPIO_DRV_SetPinDirection(LED1_GPIO, LED1_PIN, 1); /*设置GPIO为输出*/
-    GPIO_DRV_SetPinDirection(LED2_GPIO, LED2_PIN, 1);
+    //GPIO_DRV_SetPinDirection(LED2_GPIO, LED2_PIN, 1);
     GPIO_DRV_SetPinDirection(LED3_GPIO, LED3_PIN, 1); /*设置GPIO为输出*/
     GPIO_DRV_SetPinDirection(LED4_GPIO, LED4_PIN, 1);
+	
+		GPIO_DRV_SetPinDirection(K0_GPIO, K0_PIN, 1);
+		GPIO_DRV_SetPinDirection(K1_GPIO, K1_PIN, 1);
+		GPIO_DRV_SetPinDirection(K2_GPIO, K2_PIN, 1);
+		GPIO_DRV_SetPinDirection(K3_GPIO, K3_PIN, 1);
 
 
     /*上电默认LED关闭*/
 		LED1_OFF;
-		LED2_OFF;
+		//LED2_OFF;
 		LED3_OFF;
 		LED4_OFF;
+		
+		K0_OFF;
+		K1_OFF;
+		K2_OFF;
+		K3_OFF;
 
 }
 
@@ -114,10 +130,34 @@ void GPIO_Init(void)
 {
     GPIO_LedInit();
     GPIO_KeyInit();
-    //PORT_SetPinIntSel(KEY4_PORT, KEY4_PIN, PORT_INT_FALLING_EDGE);
+}
+
+
+void Trigger_VoiceOn(uint8_t voice_id)
+{
+	if(voice_id > 3){
+		return ;
+	}
+	
+	if(VOICE_ID_0 == voice_id){
+		K0_ON;
+	}else if(VOICE_ID_1 == voice_id){
+		K1_ON;
+	}else if(VOICE_ID_2 == voice_id){
+		K2_ON;
+	}else if(VOICE_ID_3 == voice_id){
+		K3_ON;
+	}
+	
+	
+}
 
-    //GPIO_DRV_InstallCallback(KEY4_INSTANCE, KEY4_handler, 0);
-    //NVIC_SetPriority(KEY4_IRQ, 3);
+void Trigger_VoiceOff()
+{
+		K0_OFF;
+		K1_OFF;
+		K2_OFF;
+		K3_OFF;
 }
 
 /* ======================================  Functions define  ======================================== */

+ 36 - 6
Device/gpio.h

@@ -63,9 +63,22 @@ extern "C" {
 #define LED1_PIN       (7)
 
 //433 语音播报输出
-#define LED2_PORT      (PORTC)
-#define LED2_GPIO      (GPIOC)
-#define LED2_PIN       (5)
+#define K0_PORT      (PORTA)
+#define K0_GPIO      (GPIOA)
+#define K0_PIN       (10)
+
+#define K1_PORT      (PORTA)
+#define K1_GPIO      (GPIOA)
+#define K1_PIN       (11)
+
+#define K2_PORT      (PORTA)
+#define K2_GPIO      (GPIOA)
+#define K2_PIN       (12)
+
+#define K3_PORT      (PORTA)
+#define K3_GPIO      (GPIOA)
+#define K3_PIN       (13)
+
 
 //设备运行指示灯
 #define LED3_PORT      (PORTC)
@@ -94,9 +107,18 @@ extern "C" {
 #define LED1_OFF       do{GPIO_DRV_WritePin(LED1_GPIO, LED1_PIN, 0);}while(0)
 #define LED1_TOGGLE    do{GPIO_DRV_TogglePins(LED1_GPIO, (1<<LED1_PIN));}while(0)
 
-#define LED2_ON        do{GPIO_DRV_WritePin(LED2_GPIO , LED2_PIN, 1);}while(0)
-#define LED2_OFF       do{GPIO_DRV_WritePin(LED2_GPIO, LED2_PIN, 0);}while(0)
-#define LED2_TOGGLE    do{GPIO_DRV_TogglePins(LED2_GPIO, (1<<LED2_PIN));}while(0)
+//#define LED2_ON        do{GPIO_DRV_WritePin(LED2_GPIO , LED2_PIN, 1);}while(0)
+//#define LED2_OFF       do{GPIO_DRV_WritePin(LED2_GPIO, LED2_PIN, 0);}while(0)
+//#define LED2_TOGGLE    do{GPIO_DRV_TogglePins(LED2_GPIO, (1<<LED2_PIN));}while(0)
+
+#define K0_ON        do{GPIO_DRV_WritePin(K0_GPIO, K0_PIN, 1);}while(0)
+#define K0_OFF       do{GPIO_DRV_WritePin(K0_GPIO, K0_PIN, 0);}while(0)
+#define K1_ON        do{GPIO_DRV_WritePin(K1_GPIO, K1_PIN, 1);}while(0)
+#define K1_OFF       do{GPIO_DRV_WritePin(K1_GPIO, K1_PIN, 0);}while(0)
+#define K2_ON        do{GPIO_DRV_WritePin(K2_GPIO, K2_PIN, 1);}while(0)
+#define K2_OFF       do{GPIO_DRV_WritePin(K2_GPIO, K2_PIN, 0);}while(0)
+#define K3_ON        do{GPIO_DRV_WritePin(K3_GPIO, K3_PIN, 1);}while(0)
+#define K3_OFF       do{GPIO_DRV_WritePin(K3_GPIO, K3_PIN, 0);}while(0)
 
 #define LED3_ON        do{GPIO_DRV_WritePin(LED3_GPIO , LED3_PIN, 0);}while(0)
 #define LED3_OFF       do{GPIO_DRV_WritePin(LED3_GPIO, LED3_PIN, 1);}while(0)
@@ -117,6 +139,11 @@ extern "C" {
 #define LOW     (0)
 #define HIGH    (1)
 
+#define VOICE_ID_0 (0)
+#define VOICE_ID_1 (1)
+#define VOICE_ID_2 (2)
+#define VOICE_ID_3 (3)
+
 
 /* ===========================================  Typedef  ============================================ */
 
@@ -127,6 +154,9 @@ extern void GPIO_LedInit(void);
 extern void GPIO_KeyInit(void);
 void GPIO_Init(void);
 
+void Trigger_VoiceOn(uint8_t voice_id);
+void Trigger_VoiceOff();
+
 /* ======================================  Functions define  ======================================== */
 
 

文件差异内容过多而无法显示
+ 74 - 56
Project/BVACS.uvguix.孙凯


文件差异内容过多而无法显示
+ 2589 - 1710
Project/JLinkLog.txt


文件差异内容过多而无法显示
+ 1502 - 1265
Project/Listings/BVACS_20240130.map


+ 3 - 3
User/cfg.c

@@ -33,9 +33,9 @@ int Config_Init(void)
 				Factory_reset();
 			
 				//设备内参, 不加入出厂设置
-				config->xaxis_threshold = 0.0;
-				config->yaxis_threshold = 0.0;
-				config->zaxis_threshold = 0.0;
+				config->xaxis_threshold = 0.015;
+				config->yaxis_threshold = 0.015;
+				config->zaxis_threshold = 0.015;
 			
 				//
 				config->IapFlag = Startup_Normal;

+ 5 - 3
User/main_task.c

@@ -68,6 +68,9 @@ void Uart1_RxDataHandle(void)
 										case Cmd_BvStatus:
 											ret_len = Read_BvStatus(txbuf+tx_len, txbuf_size-tx_len);
 											break;
+										case Cmd_GetNoisethreshold:
+											ret_len = Read_NoiseThreshold(txbuf+tx_len, txbuf_size-tx_len);
+											break;
 										default:
 											txbuf[1] |= 0x80;
 											txbuf[tx_len] = INVALID_COMMAND;
@@ -135,10 +138,9 @@ void Uart1_RxDataHandle(void)
 											ret_write = Trigger_SendFiltered(rxbuf+4, rx_len-4-2);
 											break;
 										case Cmd_CalibrateNoise:
+											ret_write = Trigger_CalibrateNoise(rxbuf+4, rx_len-4-2);
 											break;
-										case Cmd_GetNoisethreshold:
-											break;
-										
+
 										case Cmd_IapUpgrade:
 											tx_len += IAP_CmdHandle(rxbuf+tx_len, rx_len-4-2, txbuf+tx_len);
 											if(1 == iap_reboot){

+ 42 - 32
User/process.c

@@ -15,7 +15,8 @@ uint16_t	g_blinkLedTgtTime;	/*RUN LED目
 //uint8_t	  g_bvopen_delay;    
 
 uint8_t	  g_bvopen;  // 0: close , 1: open
-uint8_t   g_trigger_vo;
+uint8_t   g_vo_delay;
+uint8_t   g_voiceid;
 
 #define  DEFAULT_VO_PERIOD     (500) /* 5秒*/
 uint16_t	g_VoiceOutTime;			/*语音播报频率控制时间*/
@@ -99,8 +100,8 @@ void timer_callback(void)
 		}
 		
 	//433  语音输出
-	if(g_trigger_vo > 0){
-		g_trigger_vo--;
+	if(g_vo_delay > 0){
+		g_vo_delay--;
 	
 	}
 	
@@ -122,7 +123,8 @@ void Process_Init(void)
 		//g_alg_run_count		= 0;
 		g_bvopen_delay	= 0;
 		g_bvopen = BV_CLOSE;
-		g_trigger_vo = 0;
+		g_vo_delay = 0;
+		g_voiceid = 0;
 		g_vo_alarm = 0;
 	
 		/* acc data */
@@ -159,38 +161,25 @@ void Process_RunLedPrd(void)
 	if(g_VoiceOutTime >= DEFAULT_VO_PERIOD){
 			g_VoiceOutTime = 0;
 			
-			if((g_vo_alarm == 1) && (g_trigger_vo == 0)){
-				g_trigger_vo = VO_COUNT_DFTT;
+			if((g_vo_alarm == 1) && (g_vo_delay == 0)){
+				g_vo_delay = VO_COUNT_DFTT;
 			}
 		
 	}
 
 	
-	if(g_bvopen == BV_OPEN){
-			LED4_ON;
-	}else{
-			LED4_OFF;
-	}
+	//if(g_bvopen == BV_OPEN){
+	//		LED4_ON;
+	//}else{
+	//		LED4_OFF;
+	//}
 	
 	
 		//433  语音输出
-	if(g_trigger_vo > 0){
-		
-		if(GPIO_DRV_GetPinsOutput(LED2_GPIO)& (1<<LED2_PIN))
-		{
-				
-		}else{
-				LED2_ON;
-		}
-		
-	
+	if(g_vo_delay > 0){
+		Trigger_VoiceOn(g_voiceid);
 	}else{
-		
-		if(GPIO_DRV_GetPinsOutput(LED2_GPIO)&(1<<LED2_PIN))
-		{
-			LED2_OFF;
-		}
-	
+		Trigger_VoiceOff();
 	}
 	
 	
@@ -252,6 +241,9 @@ void autocaculate_mtnoise(axis_info_t* paxis_info)
 		double accz_sd = 0.0;
 	
 		uint16_t i=0;
+		int tmp = 0;
+	
+		LED4_ON;
 
 		detect_info.info[g_samplecount].x = paxis_info->x;
 		detect_info.info[g_samplecount].y = paxis_info->y;
@@ -286,10 +278,20 @@ void autocaculate_mtnoise(axis_info_t* paxis_info)
 			config->xaxis_threshold = 3*fabs(accx_sd);
 			config->yaxis_threshold = 3*fabs(accy_sd);
 			config->zaxis_threshold = 3*fabs(accz_sd);
+			
+			//截取小数点后3位
+			tmp = (config->xaxis_threshold+0.0005)*1000;
+			config->xaxis_threshold = 1.0*tmp/1000;
+			tmp = (config->yaxis_threshold+0.0005)*1000;
+			config->yaxis_threshold = 1.0*tmp/1000;
+			tmp = (config->zaxis_threshold+0.0005)*1000;
+			config->zaxis_threshold = 1.0*tmp/1000;
+			
 			SaveConfig();
 			
 			g_samplecount=0;
 			g_autocalibration=0;
+			LED4_OFF;
 			
 		}
 	
@@ -308,11 +310,14 @@ void alg_PreProcess(void)
 			
 				_bvopen = g_bvopen;
 				if(BV_OPEN == g_bvopen){
+						LED4_ON;
+					
 						if(ALG_None == g_alg_context.state){
 								g_alg_context.state = ALG_Start;
 						}
 						
 				}else{
+						LED4_OFF;
 					  if(ALG_Triggering != g_alg_context.state){
 								g_alg_context.state = ALG_None;
 						}
@@ -388,13 +393,13 @@ void alg_detect(axis_info_t* paxis_info)
 		paxis_info->z  -= g_alg_context.axis_offset.z;
 	
 		//机械滤波
-		if(fabs(paxis_info->x) <= config->xaxis_threshold){
+		if(fabs(paxis_info->x) <= MECHANICAL_NOISE_THRESHOLD){
 				paxis_info->x = 0.0;
 		}
-		if(fabs(paxis_info->y) <= config->yaxis_threshold){
+		if(fabs(paxis_info->y) <= MECHANICAL_NOISE_THRESHOLD){
 				paxis_info->y = 0.0;
 		}
-		if(fabs(paxis_info->z) <= config->zaxis_threshold){
+		if(fabs(paxis_info->z) <= MECHANICAL_NOISE_THRESHOLD){
 				paxis_info->z = 0.0;
 		}
 		
@@ -485,6 +490,7 @@ void alg_detect(axis_info_t* paxis_info)
 			
 				g_VoiceOutTime = DEFAULT_VO_PERIOD-10;
 				g_vo_alarm = 1;
+				g_voiceid = VOICE_ID_0;
 			
 				x_keepcount = 0;
 				y_keepcount = 0;
@@ -531,6 +537,8 @@ void alg_Triggering(void)
 							//sv_close();
 							g_alg_context.state = ALG_Finished;
 							g_vo_alarm = 0;
+							g_vo_delay = VO_COUNT_DFTT;
+							g_voiceid = VOICE_ID_1;
 							return ;
 						}
 						
@@ -609,7 +617,7 @@ void Process_Alg(void)
 				axis_info.y = acc_y*2.9/1000;
 				axis_info.z = acc_z*2.9/1000;
 			
-				alg_filter(&axis_info);
+				
 				uint32_t start =  OSIF_GetMilliseconds();
 
 				//printf("alg:%d ms st: %d \r", start, g_alg_context.state);
@@ -617,7 +625,9 @@ void Process_Alg(void)
 					autocaculate_mtnoise(&axis_info);
 				
 			}else{
-			
+				
+				alg_filter(&axis_info);
+				
 				switch(g_alg_context.state){
 					case ALG_Start:
 						alg_start();

+ 5 - 4
User/process.h

@@ -44,7 +44,8 @@ extern "C" {
 
 /*************<extern>*****************/	
 extern uint8_t	  g_bvopen;  // 0: close , 1: open
-extern uint8_t   	g_trigger_vo;
+extern uint8_t   	g_vo_delay;
+extern uint8_t    g_voiceid;
 
 extern uint8_t g_autocalibration;
 extern uint16_t g_samplecount;
@@ -90,9 +91,9 @@ typedef struct _filter_avg{
 
 #define DETECT_CNT   						(400) // 4s 
 #define KEEP_CNT								(80)
-#define DETECT_THRESHOLD  			(0.8)	//(1.39)  m/s   5Km/h
-#define DETECT_THRESHOLD_DOWN 	(0.2) //(0.4) // m/s2   5Km/h
-#define MECHANICAL_NOISE_THRESHOLD  (0.02) //g 
+#define DETECT_THRESHOLD  			(0.6)	 //m/s   2Km/h
+#define DETECT_THRESHOLD_DOWN 	(0.2) //  5Km/h
+#define MECHANICAL_NOISE_THRESHOLD  (0.015) //g 
 
 typedef struct _detect_info{
 	axis_info_t info[DETECT_CNT];

+ 11 - 10
User/protocol.c

@@ -5,7 +5,7 @@
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 1, 20240130};
+uint32_t Firmware_Version[4] = {1, 0, 1, 20240305};
 #else
 uint32_t Firmware_Version[4] = {1, 1, 5, 20240125};
 #endif
@@ -125,15 +125,15 @@ uint16_t Read_NoiseThreshold(uint8_t *pBuf, uint16_t buf_len)
 	pBuf[2] = ((uint8_t*)(&config->xaxis_threshold))[2];
 	pBuf[3] = ((uint8_t*)(&config->xaxis_threshold))[3];
 	
-	pBuf[5] = ((uint8_t*)(&config->yaxis_threshold))[0];
-	pBuf[6] = ((uint8_t*)(&config->yaxis_threshold))[1];
-	pBuf[7] = ((uint8_t*)(&config->yaxis_threshold))[2];
-	pBuf[8] = ((uint8_t*)(&config->yaxis_threshold))[3];
+	pBuf[4] = ((uint8_t*)(&config->yaxis_threshold))[0];
+	pBuf[5] = ((uint8_t*)(&config->yaxis_threshold))[1];
+	pBuf[6] = ((uint8_t*)(&config->yaxis_threshold))[2];
+	pBuf[7] = ((uint8_t*)(&config->yaxis_threshold))[3];
 	
-	pBuf[9] = ((uint8_t*)(&config->zaxis_threshold))[0];
-	pBuf[10] = ((uint8_t*)(&config->zaxis_threshold))[1];
-	pBuf[11] = ((uint8_t*)(&config->zaxis_threshold))[2];
-	pBuf[12] = ((uint8_t*)(&config->zaxis_threshold))[3];
+	pBuf[8] = ((uint8_t*)(&config->zaxis_threshold))[0];
+	pBuf[9] = ((uint8_t*)(&config->zaxis_threshold))[1];
+	pBuf[10] = ((uint8_t*)(&config->zaxis_threshold))[2];
+	pBuf[11] = ((uint8_t*)(&config->zaxis_threshold))[3];
 	
 	return 12;
 }
@@ -232,7 +232,8 @@ uint8_t Trigger_VoicOutput(uint8_t *pdata, uint8_t len)
 {
 	if(len == 2){
 		
-		g_trigger_vo = VO_COUNT_DFTT;
+		g_vo_delay = VO_COUNT_DFTT;
+		g_voiceid = pdata[1];
 		return RET_OK;
 		
 	}else{