From: John Janus Date: Fri, 22 Sep 2017 13:23:38 +0000 (+0200) Subject: added horn X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=5f39bfa23339fc50db2660e881abe6229fbda8c9;p=FakeRadio.git added horn --- diff --git a/nebelhorn.mp3 b/nebelhorn.mp3 new file mode 100644 index 0000000..05bd908 Binary files /dev/null and b/nebelhorn.mp3 differ diff --git a/simple_try.c b/simple_try.c index 01b021b..82ceafb 100644 --- a/simple_try.c +++ b/simple_try.c @@ -17,11 +17,13 @@ #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);