From 01124fd1d994f3ccd9db27ccd5fbbe65af4d04e0 Mon Sep 17 00:00:00 2001 From: John Janus Date: Fri, 6 Oct 2017 11:03:25 +0200 Subject: [PATCH] implement unprelling in code --- simple_try.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/simple_try.c b/simple_try.c index 528b643..fdfaa6b 100644 --- a/simple_try.c +++ b/simple_try.c @@ -19,6 +19,8 @@ #define INTROBTN 13 #define HORNBTN 11 +#define UNPRELL 200 + volatile bool running = true; static volatile bool pwrOn = false; static volatile bool chnl1 = true; @@ -43,8 +45,12 @@ void ctrlCHandler(int signum) { void pwrBtn(void) { if (delaying) return; pthread_mutex_lock(mut); - pwrOn = !pwrOn; - if (pwrOn) intro = false; + int pwrstate = digitalRead(PWRBTN); + delay(UNPRELL); + if (pwrstate==digitalRead(PWRBTN)) { + pwrOn = !pwrOn; + if (pwrOn) intro = false; + } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -52,7 +58,11 @@ void pwrBtn(void) { void chnl1Btn(void) { if (delaying || !pwrOn) return; pthread_mutex_lock(mut); - chnl1 = true; + int chnl1state = digitalRead(CHNL1BTN); + delay(UNPRELL); + if (chnl1state==digitalRead(CHNL1BTN)) { + chnl1 = true; + } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -60,7 +70,11 @@ void chnl1Btn(void) { void chnl2Btn(void) { if (delaying || !pwrOn) return; pthread_mutex_lock(mut); - chnl1 = false; + int chnl2state = digitalRead(CHNL2BTN); + delay(UNPRELL); + if (chnl2state==digitalRead(CHNL2BTN)) { + chnl1 = false; + } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -68,8 +82,12 @@ void chnl2Btn(void) { void introBtn(void) { if (delaying || pwrOn) return; pthread_mutex_lock(mut); - intro = !intro; - horn = false; + int introstate = digitalRead(INTROBTN); + delay(UNPRELL); + if (introstate==digitalRead(INTROBTN)) { + intro = !intro; + horn = false; + } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -77,8 +95,12 @@ void introBtn(void) { void hornBtn(void) { if (delaying || pwrOn) return; pthread_mutex_lock(mut); - horn = !horn; - intro = false; + int hornstate = digitalRead(HORNBTN); + delay(UNPRELL); + if (hornstate==digitalRead(HORNBTN)) { + horn = !horn; + intro = false; + } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } -- 2.47.0