diff options
| author | spv <spv@spv.sh> | 2025-09-21 00:59:56 -0400 |
|---|---|---|
| committer | spv <spv@spv.sh> | 2025-09-21 00:59:56 -0400 |
| commit | 02a74cc0b499f6a93c25ea8cd392af977298d60a (patch) | |
| tree | 71b9008bdb6402e10477c9f80fe43950f7c89c72 /src/light_thread.c | |
| parent | 38d25483657e82eb546ecb8566214f830efba461 (diff) | |
use signal ipc instead of sleep loop
Diffstat (limited to 'src/light_thread.c')
| -rw-r--r-- | src/light_thread.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/light_thread.c b/src/light_thread.c index 1d273a0..20b7bb9 100644 --- a/src/light_thread.c +++ b/src/light_thread.c @@ -2,14 +2,13 @@ #include <stdio.h> -#include <stdint.h> -#include <sys/time.h> - #include "common.h" #include "consts.h" #include "config.h" #include "backlight.h" +static pid_t keypress_pid; + uint64_t time_since_press(void) { struct timeval now; @@ -30,12 +29,24 @@ uint64_t time_since_press(void) { return diff; } -int light_thread(void) { - while (1) { - if (time_since_press() > BACKLIGHT_TIME) backlight_off(); - else backlight_on(); +void handler(int _) { + if (time_since_press() > BACKLIGHT_TIME) { + backlight_off(); + } else { + backlight_on(); - usleep(THREAD_WAIT); + handler(_); + } +} + +int light_thread(pid_t _keypress_pid) { + keypress_pid = _keypress_pid; + + signal(SIGCONT, handler); + + while (1) { + pause(); +// usleep(THREAD_WAIT); } return 0; |
