소스 검색

修改好button唤醒不正常问题

corvin 5 년 전
부모
커밋
266d80e629
1개의 변경된 파일7개의 추가작업 그리고 20개의 파일을 삭제
  1. 7 20
      src/button.c

+ 7 - 20
src/button.c

@@ -34,25 +34,18 @@ extern int  duer_recorder_test_start(int channel);
 
 static void button_polling_thread()
 {
-	int old_state=0;
-	int now_state=0;
 	uint32_t  btn_press_time = duer_timestamp();
 	uint32_t  btn_release_time = duer_timestamp();
 	int  channel_id=1;
 
 	 while(1)
 	 {
-			 waitForInterrupt(BUTTON_GPIO, 200);
-                         //DUER_LOGI("button_polling_thread %d\n",digitalRead(BUTTON_GPIO));
-			 if((now_state=digitalRead(BUTTON_GPIO))!=old_state)
+			 waitForInterrupt(BUTTON_GPIO, -1);
+                         DUER_LOGI("button_polling_thread %d\n", digitalRead(BUTTON_GPIO));
+			 delay(100);
+			 if(digitalRead(BUTTON_GPIO)==0)
 			 {
-					 	DUER_LOGI("%d %d\n",now_state,old_state);
-					 	if(now_state==1) //release
-					 	{
-							    btn_release_time  =  duer_timestamp(NULL);
-							    if(btn_release_time>btn_press_time+100)
-							    {
-										if(duer_app_is_test_mode())
+			    if(duer_app_is_test_mode())
 										{
 											    duer_recorder_test_start(channel_id);
 											    duer_dcs_dialog_cancel();
@@ -73,14 +66,6 @@ static void button_polling_thread()
 												duer_media_tone_play("./resources/16.wav");
 												event_record_start();
 										}
-								}
-						}
-						else  //press
-						{
-								btn_press_time = duer_timestamp();
-						}
-
-					 	old_state = now_state;
 
 			}
 	 }
@@ -93,6 +78,8 @@ int button_init(void)
 		    DUER_LOGE("wiringPiSetup fail\n");
 		    return -1;
 		}
+		pinMode(BUTTON_GPIO, INPUT);
+		pullUpDnControl(BUTTON_GPIO, PUD_UP);
 
 		if(pthread_create(&s_button_threadID, NULL, (void *)button_polling_thread, NULL)!=0)
 		{