From: John Janus Date: Sun, 17 Sep 2017 08:51:50 +0000 (+0200) Subject: add intro control X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=2ced2e9adf55d6a30ab964be56396b27489b88d5;p=FakeRadio.git add intro control --- diff --git a/intro.mp3 b/intro.mp3 new file mode 100644 index 0000000..9dddc07 Binary files /dev/null and b/intro.mp3 differ diff --git a/simple_try.c b/simple_try.c index 00c829a..691e3c3 100644 --- a/simple_try.c +++ b/simple_try.c @@ -11,14 +11,17 @@ #define PWRLED 8 #define CHNL1LED 9 #define CHNL2LED 7 +#define INTROLED 12 #define PWRBTN 0 #define CHNL1BTN 2 #define CHNL2BTN 3 +#define INTROBTN 13 static volatile bool running = true; static volatile bool pwrOn = false; static volatile bool chnl1 = true; +static volatile bool intro = false; //static volatile bool sthchanged = false; static pthread_cond_t* wakeup; static pthread_mutex_t* mut; @@ -37,6 +40,7 @@ void ctrlCHandler(int signum) { void pwrBtn(void) { pthread_mutex_lock(mut); pwrOn = !pwrOn; + if (pwrOn) intro = false; pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -55,6 +59,13 @@ void chnl2Btn(void) { pthread_cond_signal(wakeup); } +void introBtn(void) { + pthread_mutex_lock(mut); + intro = !intro; + pthread_mutex_unlock(mut); + pthread_cond_signal(wakeup); +} + int main(void) { printf("Initializing...\n"); if (wiringPiSetup() == -1) { @@ -67,17 +78,21 @@ int main(void) { pinMode(PWRBTN, INPUT); pinMode(CHNL1BTN, INPUT); pinMode(CHNL2BTN, INPUT); + pinMode(INTROBTN, INPUT); pullUpDnControl(PWRBTN, PUD_UP); pullUpDnControl(CHNL1BTN, PUD_UP); pullUpDnControl(CHNL2BTN, PUD_UP); + pullUpDnControl(INTROBTN, 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"); printf("Set LED pins to output\n"); pinMode(PWRLED, OUTPUT); pinMode(CHNL1LED, OUTPUT); pinMode(CHNL2LED, OUTPUT); + pinMode(INTROLED, OUTPUT); printf("initialize mutex and condition variable\n"); mut = malloc (sizeof(pthread_mutex_t)); @@ -99,6 +114,7 @@ int main(void) { digitalWrite(CHNL1LED, HIGH); digitalWrite(CHNL2LED, HIGH); chnl1=true; + if (intro) playThread = startPlayThread("intro.mp3"); } else { digitalWrite(PWRLED, LOW); if (chnl1) { @@ -123,8 +139,10 @@ int main(void) { digitalWrite(PWRLED, HIGH); digitalWrite(CHNL1LED, HIGH); digitalWrite(CHNL2LED, HIGH); + digitalWrite(INTROLED, HIGH); pullUpDnControl(PWRBTN, PUD_DOWN); pullUpDnControl(CHNL1BTN, PUD_DOWN); pullUpDnControl(CHNL2BTN, PUD_DOWN); + pullUpDnControl(INTROBTN, PUD_DOWN); }