Jelajahi Sumber

init newBranch

Chenyingjia 2 tahun lalu
induk
melakukan
fce5b3ec32
1 mengubah file dengan 70 tambahan dan 16 penghapusan
  1. 70 16
      app/app_chargerpin_conn_detect.c

+ 70 - 16
app/app_chargerpin_conn_detect.c

@@ -170,7 +170,7 @@ static void app_pair_host_process(void)
 						
 						Process_UpdatePeroid(app_pair_host_process,1);
 						Process_SetHoldOn(app_pair_host_process,1);
-
+						
 						host_ram.statu=3;		
 						PAIR_CHARGERPIN_PRINT("INTO CONNECT_NO_CHARGE %d\n", nrf_gpio_pin_read(PIN_CHARGING));		
 					}
@@ -186,23 +186,55 @@ static void app_pair_host_process(void)
 				}
 				break;
 			case 3://上拉让从机发现配对信号
-				if ((TIME_GetTicks() - host_ram.delay_pair_count > ADC_CHECKMS)||(nrf_gpio_pin_read(PIN_CHARGING)))
+				if ((TIME_GetTicks() - host_ram.delay_pair_count > ADC_CHECKMS+ADC_CHECKMS))
 				{
-					PAIR_CHARGERPIN_PRINT(" into_event  %d \n", TIME_GetTicks());
+					PAIR_CHARGERPIN_PRINT(" UP pull over time  %d \n", TIME_GetTicks());
+					log("pull over time\n");
+					nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
+					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_host_process,0);
+					host_ram.statu=1;
+				}
+				else if(nrf_gpio_pin_read(PIN_CHARGING))//读到上拉信号以后,说明client已经连接上
+				{
+					PAIR_CHARGERPIN_PRINT(" nrf_gpio_pin_read(PIN_CHARGING SUCCESS \n", TIME_GetTicks());
 					host_ram.statu=4;
+					host_ram.delay_pair_count=TIME_GetTicks();
 					nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
+				}
+				break;
+			case 4:
+				if(nrf_gpio_pin_read(PIN_CHARGING)==0)
+				{
+					PAIR_CHARGERPIN_PRINT(" into_event  %d \n", TIME_GetTicks());
+					host_ram.statu=5;
 					host_ram.delay_pair_count=TIME_GetTicks();
+					
+					ADC_Disable();
+					ADC_RemovePinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
+					ADC_Initialize();
+					
+					log("into_event-H\n");
 					host_ram.into_event();
+					
+				}
+				else if(TIME_GetTicks() - host_ram.delay_pair_count > 500)
+				{
+					PAIR_CHARGERPIN_PRINT("  wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					host_ram.statu=0;
 					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
-					Process_SetHoldOn(app_pair_host_process,0);
+					Process_SetHoldOn(app_pair_host_process,0);	
+					i=3;					
 				}
 				break;
-			case 4:
+			case 5:
 				if (TIME_GetTicks() - host_ram.delay_pair_count > PAIROVERTIME)
 				{
 					PAIR_CHARGERPIN_PRINT("  over_event %d\n", TIME_GetTicks());
 					host_ram.statu=0;
 					host_ram.over_event();
+					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_host_process,0);	
 					i=3;
 				}
 				break;
@@ -278,11 +310,11 @@ static void app_pair_client_process(void)
 					{
 						PAIR_CHARGERPIN_PRINT("INTO CONNECT_NO_CHARGE %d\n", 1);
 						client_ram.pair_line=CONNECT_NO_CHARGE;	
+
+						ADC_Disable();
+						ADC_RemovePinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL);
+						ADC_Initialize();
 						
-						client_ram.delay_pair_count=TIME_GetTicks();
-						Process_UpdatePeroid(app_pair_client_process,1);
-						Process_SetHoldOn(app_pair_client_process,1);
-						client_ram.statu=2;		
 						nrf_gpio_cfg(
 							PIN_CHARGING,
 							NRF_GPIO_PIN_DIR_OUTPUT,
@@ -291,11 +323,13 @@ static void app_pair_client_process(void)
 							NRF_GPIO_PIN_D0H1,
 							NRF_GPIO_PIN_NOSENSE);
 						nrf_gpio_cfg_watcher(PIN_CHARGING);
-						nrf_gpio_pin_set(PIN_CHARGING);
+						nrf_gpio_pin_set(PIN_CHARGING);//拉高100ms
 						
-						client_ram.into_event();	
-						PAIR_CHARGERPIN_PRINT("  into_event %d\n", TIME_GetTicks());
-						PAIR_CHARGERPIN_PRINT("  wait pair %d\n", nrf_gpio_pin_read(PIN_CHARGING));					
+						client_ram.delay_pair_count=TIME_GetTicks();
+						Process_UpdatePeroid(app_pair_client_process,1);
+						Process_SetHoldOn(app_pair_client_process,1);
+						client_ram.statu=2;							
+										
 					}
 				}
 				else
@@ -308,19 +342,39 @@ static void app_pair_client_process(void)
 				}			
 				break;
 			case 2:
-				if(TIME_GetTicks() - client_ram.delay_pair_count > 100)//等
+				if(TIME_GetTicks() - client_ram.delay_pair_count > 100)//等100ms
 				{
 					nrf_gpio_pin_clear(PIN_CHARGING);
 					client_ram.statu=3;
-					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
-					Process_SetHoldOn(app_pair_client_process,0);
+					client_ram.delay_pair_count=TIME_GetTicks();
 				}
 				break;
 			case 3:
+				if(nrf_gpio_pin_read(PIN_CHARGING)==0)
+				{
+					log("into_event-C\n");
+					client_ram.into_event();	
+					client_ram.delay_pair_count=TIME_GetTicks();
+					PAIR_CHARGERPIN_PRINT("  into_event-C %d\n", TIME_GetTicks());
+					PAIR_CHARGERPIN_PRINT("  wait pair %d\n", nrf_gpio_pin_read(PIN_CHARGING));	
+					client_ram.statu=4;
+				}
+				else if(TIME_GetTicks() - client_ram.delay_pair_count > 100)
+				{
+					PAIR_CHARGERPIN_PRINT("  wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					client_ram.statu=0;
+					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_client_process,0);	
+					i=3;					
+				}
+				break;
+			case 4:
 				if (TIME_GetTicks() - client_ram.delay_pair_count > PAIROVERTIME)
 				{
 					client_ram.statu=0;
 					client_ram.over_event();
+					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_client_process,0);					
 					PAIR_CHARGERPIN_PRINT("  over_event %d\n", TIME_GetTicks());
 					i=3;
 				}