]> Johnzone git - FakeRadio.git/commitdiff
fix bug which made switching the radio on again impossible
authorJohn Janus <j.janus@lighthouse-it.de>
Tue, 29 Aug 2017 10:44:31 +0000 (12:44 +0200)
committerJohn Janus <j.janus@lighthouse-it.de>
Tue, 29 Aug 2017 10:44:31 +0000 (12:44 +0200)
simple_try.c

index f3a0e2114607a5a5204558d8cf631bf1ca3cad8e..ef9f037dc949438abbe0ed639412de3265b6dbab 100644 (file)
@@ -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);