-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.c
67 lines (51 loc) · 1.29 KB
/
driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <pthread.h>
#include <stdbool.h>
#include "audio.h"
#include "general.h"
#include "timer.h"
volatile bool allow_input = false;
void *input_thread(void *arg);
int main(int argc, char **argv) {
// used to capture user input prior to timer going off
pthread_t input_thread_id;
pthread_create(&input_thread_id, NULL, input_thread, NULL);
if (argc == 1 || argc > 3) {
FAULT:
display_help();
return 1;
}
int check = check_arguments(argc, argv);
if (check > 0) return 1; // strtonum error
if (check < 0) { // formatting error
goto FAULT;
}
char *alarm = "/usr/local/share/timer/sound/alarm.mp3"; // install
// char *alarm = "sound/alarm.mp3"; // debugging
AUDIO *a = audio_init(alarm);
if (!a) return 1;
int t = timer(argv);
if (t) return 1;
play_alarm(a);
pthread_join(input_thread_id, NULL);
audio_clean(a);
free(a);
return 0;
}
void *input_thread(void *arg) {
(void) arg; // to avoid unused variable warning lol
int c;
while (!allow_input) {
c = getchar();
if (c == '\n' || c == EOF) {
allow_input = true;
break;
}
}
return NULL;
}
/*
TODO:
# dnf install mpg123-devel
# dnf install libao-devel
*/