From b774cca90937d43a13a6216555126bf9c73b9cb3 Mon Sep 17 00:00:00 2001 From: John Janus Date: Tue, 29 Aug 2017 12:44:31 +0200 Subject: [PATCH] fix bug which made switching the radio on again impossible --- simple_try.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/simple_try.c b/simple_try.c index f3a0e21..ef9f037 100644 --- a/simple_try.c +++ b/simple_try.c @@ -22,23 +22,31 @@ pthread_cond_t* wakeup; pthread_mutex_t* mut; void ctrlCHandler(int signum) { + pthread_mutex_lock(mut); running = false; + pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); return; } void pwrBtn(void) { + pthread_mutex_lock(mut); pwrOn = !pwrOn; + pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } void chnl1Btn(void) { + pthread_mutex_lock(mut); chnl1 = true; + pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } void chnl2Btn(void) { + pthread_mutex_lock(mut); chnl1 = false; + pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -71,29 +79,25 @@ int main(void) { printf("Start Main Loop\n"); while (running) { pthread_mutex_lock(mut); - pthread_cond_wait(wakeup, mut); if (!pwrOn) { digitalWrite(PWRLED, HIGH); digitalWrite(CHNL1LED, HIGH); digitalWrite(CHNL2LED, HIGH); - //sleep(0.3); - continue; - } - digitalWrite(PWRLED, LOW); - if (chnl1) { - digitalWrite(CHNL1LED, LOW); - digitalWrite(CHNL2LED, HIGH); } else { - digitalWrite(CHNL2LED, LOW); - digitalWrite(CHNL1LED, HIGH); + digitalWrite(PWRLED, LOW); + if (chnl1) { + digitalWrite(CHNL1LED, LOW); + digitalWrite(CHNL2LED, HIGH); + } else { + digitalWrite(CHNL2LED, LOW); + digitalWrite(CHNL1LED, HIGH); + } } pthread_mutex_unlock(mut); - //delay(200); - //sleep(0.3); - } + printf("ShuttingDown\n"); pthread_cond_destroy(wakeup); pthread_mutex_destroy(mut); -- 2.47.0