pthread_mutex_t* mut;
void ctrlCHandler(int signum) {
+ pthread_mutex_lock(mut);
running = false;
+ pthread_mutex_unlock(mut);
pthread_cond_signal(wakeup);
return;
}
void pwrBtn(void) {
+ pthread_mutex_lock(mut);
pwrOn = !pwrOn;
+ pthread_mutex_unlock(mut);
pthread_cond_signal(wakeup);
}
void chnl1Btn(void) {
+ pthread_mutex_lock(mut);
chnl1 = true;
+ pthread_mutex_unlock(mut);
pthread_cond_signal(wakeup);
}
void chnl2Btn(void) {
+ pthread_mutex_lock(mut);
chnl1 = false;
+ pthread_mutex_unlock(mut);
pthread_cond_signal(wakeup);
}
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);
- continue;
- }
- digitalWrite(PWRLED, LOW);
- if (chnl1) {
- digitalWrite(CHNL1LED, LOW);
- digitalWrite(CHNL2LED, HIGH);
} else {
- digitalWrite(CHNL2LED, LOW);
- digitalWrite(CHNL1LED, HIGH);
+ digitalWrite(PWRLED, LOW);
+ if (chnl1) {
+ digitalWrite(CHNL1LED, LOW);
+ digitalWrite(CHNL2LED, HIGH);
+ } else {
+ digitalWrite(CHNL2LED, LOW);
+ digitalWrite(CHNL1LED, HIGH);
+ }
}
pthread_mutex_unlock(mut);
- //delay(200);
- //sleep(0.3);
-
}
+
printf("ShuttingDown\n");
pthread_cond_destroy(wakeup);
pthread_mutex_destroy(mut);