diff options
| -rw-r--r-- | src/backlight.c | 2 | ||||
| -rw-r--r-- | src/config.h | 2 | ||||
| -rw-r--r-- | src/keypress_thread.c | 6 | ||||
| -rw-r--r-- | src/light_thread.c | 17 | ||||
| -rw-r--r-- | src/main.c | 12 |
5 files changed, 17 insertions, 22 deletions
diff --git a/src/backlight.c b/src/backlight.c index 0824f0b..5ff2555 100644 --- a/src/backlight.c +++ b/src/backlight.c @@ -17,8 +17,6 @@ void write_to_backlight(int brightness) { void backlight_on(void) { write_to_backlight(MAX_BRIGHTNESS); - - usleep(BACKLIGHT_TIME); } void backlight_off(void) { diff --git a/src/config.h b/src/config.h index c1bb692..ece1e36 100644 --- a/src/config.h +++ b/src/config.h @@ -8,7 +8,7 @@ #define THREAD_WAIT (100 MS) /* how long to keep the light on */ -#define BACKLIGHT_TIME (10 SEC) +#define BACKLIGHT_TIME (5 SEC) /* path to keypad evdev */ #define KEYBOARD_FILE "/dev/input/event1" diff --git a/src/keypress_thread.c b/src/keypress_thread.c index a174968..1b102d4 100644 --- a/src/keypress_thread.c +++ b/src/keypress_thread.c @@ -15,12 +15,12 @@ void on_press(void) { // XXX signal light thread } -int keypress_thread(pid_t _light_pid) { +void keypress_thread(pid_t _light_pid) { light_pid = _light_pid; FILE* fp = fopen(KEYBOARD_FILE, "r"); fseek(fp, 0, SEEK_END); - + void* discard = malloc(KEYPRESS_SIZE); while (1) { @@ -34,5 +34,5 @@ int keypress_thread(pid_t _light_pid) { // XXX handle SIGINT or whatever - return 0; + __builtin_unreachable(); } diff --git a/src/light_thread.c b/src/light_thread.c index 20b7bb9..287932b 100644 --- a/src/light_thread.c +++ b/src/light_thread.c @@ -1,4 +1,4 @@ -// XXX signals, includes, open, write instead of fopen, fwrite +// XXX sigwait instead of signal handler... #include <stdio.h> @@ -34,20 +34,15 @@ void handler(int _) { backlight_off(); } else { backlight_on(); + usleep(BACKLIGHT_TIME); - handler(_); + raise(SIGCONT); } } -int light_thread(pid_t _keypress_pid) { - keypress_pid = _keypress_pid; - +void light_thread() { signal(SIGCONT, handler); - while (1) { - pause(); -// usleep(THREAD_WAIT); - } - - return 0; + for (;;) pause(); + __builtin_unreachable(); } @@ -8,8 +8,8 @@ #include "consts.h" #include "config.h" -extern int light_thread(pid_t _keypress_pid); -extern int keypress_thread(pid_t _light_pid); +extern void light_thread(void); +extern void keypress_thread(pid_t _light_pid); struct timeval* last_press; @@ -34,8 +34,10 @@ int main(int argc, const char* argv[]) { setup(); pid_t keypress_pid = getpid(); - pid_t pid = fork(); + pid_t light_pid = fork(); - if (pid == 0) return light_thread(keypress_pid); - else return keypress_thread(/*light_*/pid); + if (light_pid == 0) light_thread(); + else keypress_thread(light_pid); + + return -1; } |
