From 1855759f51bd8a7ef7f21152b03f47f7de443d03 Mon Sep 17 00:00:00 2001 From: John Janus Date: Fri, 6 Oct 2017 23:40:02 +0200 Subject: [PATCH] use bool to flag actual change --- simple_try.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/simple_try.c b/simple_try.c index 32f4298..026ee4a 100644 --- a/simple_try.c +++ b/simple_try.c @@ -27,7 +27,7 @@ static volatile bool chnl1 = true; static volatile bool intro = false; static volatile bool horn = false; static volatile bool delaying = false; -//static volatile bool sthchanged = false; +static volatile bool sthchanged = false; static pthread_cond_t* wakeup; static pthread_mutex_t* mut; static pthread_t playThread; @@ -50,6 +50,7 @@ void pwrBtn(void) { if (pwrstate==digitalRead(PWRBTN)) { pwrOn = !pwrOn; if (pwrOn) intro = false; + sthchanged = true; } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); @@ -62,6 +63,7 @@ void chnl1Btn(void) { delay(UNPRELL); if (chnl1state==digitalRead(CHNL1BTN)) { chnl1 = true; + sthchanged = true; } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); @@ -74,6 +76,7 @@ void chnl2Btn(void) { delay(UNPRELL); if (chnl2state==digitalRead(CHNL2BTN)) { chnl1 = false; + sthchanged = true; } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); @@ -87,6 +90,7 @@ void introBtn(void) { if (introstate==digitalRead(INTROBTN)) { intro = !intro; horn = false; + sthchanged = true; } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); @@ -100,6 +104,7 @@ void hornBtn(void) { if (hornstate==digitalRead(HORNBTN)) { horn = !horn; intro = false; + sthchanged = true; } pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); @@ -146,6 +151,11 @@ int main(void) { while (running) { pthread_mutex_lock(mut); pthread_cond_wait(wakeup, mut); + if (!sthchanged) { + pthread_mutex_unlock(mut); + continue; + } + sthchanged = false; delaying = true; if (playThread) { pthread_cancel(playThread); -- 2.47.0