]> Johnzone git - FakeRadio.git/commitdiff
added horn
authorJohn Janus <mail@johnzone.org>
Fri, 22 Sep 2017 13:23:38 +0000 (15:23 +0200)
committerJohn Janus <mail@johnzone.org>
Fri, 22 Sep 2017 13:23:38 +0000 (15:23 +0200)
nebelhorn.mp3 [new file with mode: 0644]
simple_try.c

diff --git a/nebelhorn.mp3 b/nebelhorn.mp3
new file mode 100644 (file)
index 0000000..05bd908
Binary files /dev/null and b/nebelhorn.mp3 differ
index 01b021b900820ef80b9debe403aabf292f4e2cd1..82ceafb0eb9e21aad379418bba596ca221dcc1a1 100644 (file)
 #define CHNL1BTN 2
 #define CHNL2BTN 3
 #define INTROBTN 13
+#define HORNBTN 11
 
 static volatile bool running = true;
 static volatile bool pwrOn = false;
 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 pthread_cond_t* wakeup;
@@ -71,6 +73,14 @@ void introBtn(void) {
     pthread_cond_signal(wakeup);
 }
 
+void hornBtn(void) {
+    if (delaying || pwrOn) return;
+    pthread_mutex_lock(mut);
+    horn = !horn;
+    pthread_mutex_unlock(mut);
+    pthread_cond_signal(wakeup);
+}
+
 int main(void) {
     printf("Initializing...\n");
     if (wiringPiSetup() == -1) {
@@ -84,14 +94,17 @@ int main(void) {
     pinMode(CHNL1BTN, INPUT);
     pinMode(CHNL2BTN, INPUT);
     pinMode(INTROBTN, INPUT);
+    pinMode(HORNBTN, INPUT);
     pullUpDnControl(PWRBTN, PUD_UP);
     pullUpDnControl(CHNL1BTN, PUD_UP);
     pullUpDnControl(CHNL2BTN, PUD_UP);
     pullUpDnControl(INTROBTN, PUD_UP);
+    pullUpDnControl(HORNBTN, PUD_UP);
     if (wiringPiISR(PWRBTN, INT_EDGE_RISING, pwrBtn)) printf("failed to initialize pwrBtn\n");
     if (wiringPiISR(CHNL1BTN, INT_EDGE_RISING, chnl1Btn)) printf("failed to initialize chnl1Btn\n");
     if (wiringPiISR(CHNL2BTN, INT_EDGE_RISING, chnl2Btn)) printf("failed to initialize chnl2Btn\n");
     if (wiringPiISR(INTROBTN, INT_EDGE_RISING, introBtn)) printf("failed to initialize introBtn\n");
+    if (wiringPiISR(HORNBTN, INT_EDGE_RISING, hornBtn)) printf("failed to initialize hornBtn\n");
     
     printf("Set LED pins to output\n");
     pinMode(PWRLED, OUTPUT);
@@ -122,6 +135,11 @@ int main(void) {
             if (intro) {
                 playThread = startPlayThread("intro.mp3", true);
                 digitalWrite(INTROLED, LOW);
+                horn = false;
+            } else if (horn) {
+                playThread = startPlayThread("nebelhorn.mp3", true);
+                intro = false;
+                digitalWrite(INTROLED, HIGH);
             } else {
                 digitalWrite(INTROLED, HIGH);
             }
@@ -144,6 +162,7 @@ int main(void) {
     }
     
     printf("ShuttingDown\n");
+    pthread_cancel(playThread);
     pthread_cond_destroy(wakeup);
     pthread_mutex_destroy(mut);
     free(wakeup);