buffer_size = mpg123_outblock(mh);
buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));
- if (mpg123_open(mh, file) != MPG123_OK) return;
- if (mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK) return;
+ if (mpg123_open(mh, file) != MPG123_OK) return NULL;
+ if (mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK) return NULL;
format.bits = mpg123_encsize(encoding) * BITS;
format.rate = rate;
}
-int main (int argc, char** argv)
+/*int main (int argc, char** argv)
{
pthread_t thread = startPlayThread("platt01.mp3");
void* status;
pthread_join(thread, status);
//playFunc("platt01.mp3");
-}
+}*/
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
+#include "mp3player.h"
#define PWRLED 8
#define CHNL1LED 9
static volatile bool pwrOn = false;
static volatile bool chnl1 = true;
//static volatile bool sthchanged = false;
-pthread_cond_t* wakeup;
-pthread_mutex_t* mut;
+static pthread_cond_t* wakeup;
+static pthread_mutex_t* mut;
+static pthread_t playThread;
+
+
void ctrlCHandler(int signum) {
pthread_mutex_lock(mut);
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");
+
printf("Set LED pins to output\n");
-
pinMode(PWRLED, OUTPUT);
pinMode(CHNL1LED, OUTPUT);
pinMode(CHNL2LED, OUTPUT);
+
+ printf("initialize mutex and condition variable");
mut = malloc (sizeof(pthread_mutex_t));
pthread_mutex_init(mut, NULL);
wakeup = malloc(sizeof(pthread_cond_t));
pthread_cond_init(wakeup, NULL);
+
printf("Start Main Loop\n");
while (running) {
pthread_mutex_lock(mut);
pthread_cond_wait(wakeup, mut);
+ if (playThread) {
+ printf("playing");
+ pthread_cancel(playThread);
+ }
+
if (!pwrOn) {
digitalWrite(PWRLED, HIGH);
digitalWrite(CHNL1LED, HIGH);
if (chnl1) {
digitalWrite(CHNL1LED, LOW);
digitalWrite(CHNL2LED, HIGH);
+ playThread = startPlayThread("platt01.mp3");
} else {
digitalWrite(CHNL2LED, LOW);
digitalWrite(CHNL1LED, HIGH);
+ playThread = startPlayThread("dansk01.mp3");
}
}
pthread_mutex_unlock(mut);