aboutsummaryrefslogtreecommitdiff
path: root/src/light_thread.c
diff options
context:
space:
mode:
authorspv <spv@spv.sh>2025-09-21 00:07:50 -0400
committerspv <spv@spv.sh>2025-09-21 00:08:43 -0400
commit38d25483657e82eb546ecb8566214f830efba461 (patch)
treeb9568debc69bffc2595df42266c5550cdf05f3d2 /src/light_thread.c
parent9ddf37ad959faaca72f1634dc61439cdd3c585f1 (diff)
refactoring ftw (now w/ README updates!)
Diffstat (limited to 'src/light_thread.c')
-rw-r--r--src/light_thread.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/light_thread.c b/src/light_thread.c
new file mode 100644
index 0000000..1d273a0
--- /dev/null
+++ b/src/light_thread.c
@@ -0,0 +1,42 @@
+// XXX signals, includes, open, write instead of fopen, fwrite
+
+#include <stdio.h>
+
+#include <stdint.h>
+#include <sys/time.h>
+
+#include "common.h"
+#include "consts.h"
+#include "config.h"
+#include "backlight.h"
+
+uint64_t time_since_press(void) {
+ struct timeval now;
+
+ uint64_t now_usec;
+ uint64_t press_usec;
+ uint64_t diff;
+
+ gettimeofday(&now, NULL);
+
+ now_usec = now.tv_sec * 1000000L;
+ now_usec += now.tv_usec;
+
+ press_usec = last_press->tv_sec * 1000000L;
+ press_usec += last_press->tv_usec;
+
+ diff = now_usec - press_usec;
+
+ return diff;
+}
+
+int light_thread(void) {
+ while (1) {
+ if (time_since_press() > BACKLIGHT_TIME) backlight_off();
+ else backlight_on();
+
+ usleep(THREAD_WAIT);
+ }
+
+ return 0;
+}