#include <wiringPi.h>
#include <stdio.h>
+#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <unistd.h>
+#include <pthread.h>
#define PWRLED 8
#define CHNL1LED 9
static volatile bool running = true;
static volatile bool pwrOn = false;
static volatile bool chnl1 = true;
+pthread_cond_t* wakeup;
-void ctrlCHandler(int dummy) {
+void ctrlCHandler(int signum) {
running = false;
+ pthread_cond_signal(wakeup);
return;
}
void pwrBtn(void) {
pwrOn = !pwrOn;
+ pthread_cond_signal(wakeup);
}
void chnl1Btn(void) {
chnl1 = true;
+ pthread_cond_signal(wakeup);
}
void chnl2Btn(void) {
chnl1 = false;
+ pthread_cond_signal(wakeup);
}
int main(void) {
pinMode(PWRLED, OUTPUT);
pinMode(CHNL1LED, OUTPUT);
pinMode(CHNL2LED, OUTPUT);
+ pthread_mutex_t* 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 (!pwrOn) {
digitalWrite(PWRLED, HIGH);
digitalWrite(CHNL1LED, HIGH);
digitalWrite(CHNL2LED, HIGH);
- sleep(0.3);
+ //sleep(0.3);
continue;
}
digitalWrite(PWRLED, LOW);
digitalWrite(CHNL2LED, LOW);
digitalWrite(CHNL1LED, HIGH);
}
+ pthread_mutex_unlock(mut)
//delay(200);
- sleep(0.3);
+ //sleep(0.3);
}
printf("ShuttingDown\n");