66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
|
// to make it work for times bigger than 60 minutes this has to be extended
|
||
|
|
||
|
#include "play_raw_audio.h"
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <time.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
// debug pulse audio problems
|
||
|
#define PA_DEBUG 0
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
int countdown_min_total;
|
||
|
char *HOME = getenv("HOME");
|
||
|
char *audio_file = "";
|
||
|
if (HOME != NULL) {
|
||
|
audio_file = strcat(HOME, "/music/alarm-clock-elapsed.wav");
|
||
|
} else {
|
||
|
printf ("Can't find environment variable HOME!\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
if (argc > 1) {
|
||
|
countdown_min_total = atoi(argv[1]);
|
||
|
} else {
|
||
|
if (PA_DEBUG) {
|
||
|
countdown_min_total = 0;
|
||
|
} else {
|
||
|
puts ("Define your countdown length in minutes!");
|
||
|
scanf ("%d", &countdown_min_total);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int countdown_sec_total = countdown_min_total * 60;
|
||
|
|
||
|
int countdown_sec;
|
||
|
int countdown_min;
|
||
|
|
||
|
write(1, "\033c", 3);
|
||
|
|
||
|
while (countdown_sec_total > 0) {
|
||
|
if (countdown_sec_total >= 60) {
|
||
|
countdown_sec = countdown_sec_total % 60;
|
||
|
countdown_min = (countdown_sec_total - countdown_sec) / 60;
|
||
|
} else {
|
||
|
countdown_sec = countdown_sec_total;
|
||
|
countdown_min = 0;
|
||
|
}
|
||
|
|
||
|
write(1, "\033c", 3);
|
||
|
|
||
|
printf ("%02d:%02d", countdown_min, countdown_sec);
|
||
|
fflush(stdout);
|
||
|
printf ("\r");
|
||
|
|
||
|
sleep(1);
|
||
|
countdown_sec_total--;
|
||
|
}
|
||
|
|
||
|
printf ("THE TIME IS UP!\n");
|
||
|
play_raw_audio(audio_file);
|
||
|
|
||
|
return 0;
|
||
|
}
|