Fix camera, AW9120 back LED strip, full-height dmenu, and preinstall Bantam & gitconfig
- Camera (geminux-camera):
- Auto-configure Media Controller subdevs (hi556 + 1a040000.seninf at 1296x972
SRGGB10_1X10 -> /dev/video0 MBRA), unpack 10-bit packed MTISP Bayer frames,
and run pedestal subtraction, bilinear demosaic, Gray-World AWB, gamma 2.2
LUT, and closed-loop V4L2 AE/AGC with 90-degree rotation and --oneshot JPEG
capture.
- AW9120 cover LED daemon (geminux-leds):
- Drive the back cover multicolor RGB strip (rgb:indicator-1..5, plus
rgb:indicator-6 via led/off) using sysfs multi_intensity + brightness
instead of matching monochrome red/blue names on the inside keyboard
indicator-7 Caps Lock LEDs, and filter netlink uevents to
SUBSYSTEM=power_supply.
- Launcher & dmenu:
- Make dmenu span the full screen height in vertical mode and auto-fill
available item rows in geminux-launcher.
- Preinstalled packages & skel config:
- Package and preinstall Bantam (geminux-bantam @geminux APK) with readline.
- Preinstall sanitized default .gitconfig in /etc/skel (and /root) without
user identity fields.
This commit is contained in:
1 parent
8843558f3b
commit
2706b9a901
36 files changed
+6621
-153
No files matched your search
@@ -49,8 +49,8 @@ geminux-modem-ctl: geminux-modem-ctl.c
|
||||
geminux-bt-obex: geminux-bt-obex.c
|
||||
$(CC) $(CFLAGS) $(GIO_CFLAGS) -o $@ $< $(GIO_LIBS)
|
||||
|
||||
geminux-leds: geminux-leds.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
geminux-leds: geminux-leds.c geminux-leds-core.h
|
||||
$(CC) $(CFLAGS) -o $@ geminux-leds.c
|
||||
|
||||
geminux-power-audit: geminux-power-audit.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#ifndef GEMINUX_LEDS_CORE_H
|
||||
#define GEMINUX_LEDS_CORE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline int geminux_led_clamp_u8(int v) {
|
||||
if (v < 0) return 0;
|
||||
if (v > 255) return 255;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline bool geminux_led_is_cover_rgb(const char *name) {
|
||||
if (!name) return false;
|
||||
return strncmp(name, "rgb:indicator-", 14) == 0 &&
|
||||
name[14] >= '1' && name[14] <= '6' && name[15] == '\0';
|
||||
}
|
||||
|
||||
static inline bool geminux_led_is_back_strip(const char *name) {
|
||||
if (!name) return false;
|
||||
return strncmp(name, "rgb:indicator-", 14) == 0 &&
|
||||
name[14] >= '1' && name[14] <= '5' && name[15] == '\0';
|
||||
}
|
||||
|
||||
static inline int geminux_led_format_mc(const char *multi_index,
|
||||
int r, int g, int b,
|
||||
char *intensity_out,
|
||||
size_t intensity_sz,
|
||||
int *brightness_out) {
|
||||
r = geminux_led_clamp_u8(r);
|
||||
g = geminux_led_clamp_u8(g);
|
||||
b = geminux_led_clamp_u8(b);
|
||||
|
||||
if (brightness_out) {
|
||||
*brightness_out = (r == 0 && g == 0 && b == 0) ? 0 : 255;
|
||||
}
|
||||
if (!intensity_out || intensity_sz == 0) return -1;
|
||||
|
||||
int vals[3] = {r, g, b};
|
||||
if (multi_index) {
|
||||
int parsed[3] = {0, 0, 0};
|
||||
int count = 0;
|
||||
const char *p = multi_index;
|
||||
while (*p != '\0') {
|
||||
while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') p++;
|
||||
if (*p == '\0') break;
|
||||
const char *start = p;
|
||||
while (*p != '\0' && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') p++;
|
||||
size_t tok_len = (size_t)(p - start);
|
||||
if (count < 3) {
|
||||
if (tok_len == 3 && memcmp(start, "red", 3) == 0) parsed[count] = r;
|
||||
else if (tok_len == 5 && memcmp(start, "green", 5) == 0) parsed[count] = g;
|
||||
else if (tok_len == 4 && memcmp(start, "blue", 4) == 0) parsed[count] = b;
|
||||
else parsed[count] = 0;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (count == 3) {
|
||||
vals[0] = parsed[0];
|
||||
vals[1] = parsed[1];
|
||||
vals[2] = parsed[2];
|
||||
}
|
||||
}
|
||||
|
||||
int n = snprintf(intensity_out, intensity_sz, "%d %d %d\n", vals[0], vals[1], vals[2]);
|
||||
if (n < 0 || (size_t)n >= intensity_sz) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool geminux_uevent_is_power_supply(const char *buf, size_t len) {
|
||||
if (!buf || len == 0) return false;
|
||||
static const char target[] = "SUBSYSTEM=power_supply";
|
||||
const size_t tlen = sizeof(target) - 1;
|
||||
size_t i = 0;
|
||||
while (i < len) {
|
||||
while (i < len && (buf[i] == '\0' || buf[i] == '\n' || buf[i] == '\r')) i++;
|
||||
if (i >= len) break;
|
||||
size_t start = i;
|
||||
while (i < len && buf[i] != '\0' && buf[i] != '\n' && buf[i] != '\r') i++;
|
||||
size_t tok_len = i - start;
|
||||
if (tok_len == tlen && memcmp(buf + start, target, tlen) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <linux/netlink.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -17,65 +18,143 @@
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "geminux-leds-core.h"
|
||||
|
||||
#define LEDS_SOCK "/run/geminux/leds.sock"
|
||||
|
||||
static void write_led(const char *channel, int val) {
|
||||
static int write_sysfs_str(const char *path, const char *s) {
|
||||
int fd = open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
size_t len = strlen(s);
|
||||
size_t off = 0;
|
||||
int rc = 0;
|
||||
while (off < len) {
|
||||
ssize_t w = write(fd, s + off, len - off);
|
||||
if (w < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
off += (size_t)w;
|
||||
}
|
||||
close(fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int read_sysfs_line(const char *path, char *out, size_t out_sz) {
|
||||
if (!out || out_sz == 0) return -1;
|
||||
out[0] = '\0';
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
ssize_t n = -1;
|
||||
do {
|
||||
n = read(fd, out, out_sz - 1);
|
||||
} while (n < 0 && errno == EINTR);
|
||||
close(fd);
|
||||
if (n <= 0) return -1;
|
||||
out[n] = '\0';
|
||||
while (n > 0 && (out[n - 1] == '\n' || out[n - 1] == '\r')) {
|
||||
out[--n] = '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_mc_led_dir(const char *dir_path, int r, int g, int b) {
|
||||
r = geminux_led_clamp_u8(r);
|
||||
g = geminux_led_clamp_u8(g);
|
||||
b = geminux_led_clamp_u8(b);
|
||||
|
||||
char p[512];
|
||||
if (r == 0 && g == 0 && b == 0) {
|
||||
snprintf(p, sizeof(p), "%s/brightness", dir_path);
|
||||
write_sysfs_str(p, "0\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char idx_buf[64];
|
||||
snprintf(p, sizeof(p), "%s/multi_index", dir_path);
|
||||
if (read_sysfs_line(p, idx_buf, sizeof(idx_buf)) != 0) {
|
||||
snprintf(idx_buf, sizeof(idx_buf), "red green blue");
|
||||
}
|
||||
|
||||
char intensity_buf[32];
|
||||
int bri = 0;
|
||||
if (geminux_led_format_mc(idx_buf, r, g, b, intensity_buf,
|
||||
sizeof(intensity_buf), &bri) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(p, sizeof(p), "%s/multi_intensity", dir_path);
|
||||
write_sysfs_str(p, intensity_buf);
|
||||
|
||||
char bri_buf[16];
|
||||
snprintf(bri_buf, sizeof(bri_buf), "%d\n", bri);
|
||||
snprintf(p, sizeof(p), "%s/brightness", dir_path);
|
||||
write_sysfs_str(p, bri_buf);
|
||||
}
|
||||
|
||||
static void apply_strip_rgb(int r, int g, int b, bool include_end_led) {
|
||||
DIR *d = opendir("/sys/class/leds");
|
||||
if (!d) return;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
if (strstr(de->d_name, channel)) {
|
||||
char p[320];
|
||||
snprintf(p, sizeof(p), "/sys/class/leds/%s/brightness", de->d_name);
|
||||
int fd = open(p, O_WRONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
dprintf(fd, "%d\n", val);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
bool match = include_end_led ? geminux_led_is_cover_rgb(de->d_name)
|
||||
: geminux_led_is_back_strip(de->d_name);
|
||||
if (!match) continue;
|
||||
char dir_path[320];
|
||||
snprintf(dir_path, sizeof(dir_path), "/sys/class/leds/%s", de->d_name);
|
||||
write_mc_led_dir(dir_path, r, g, b);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void apply_rgb(int r, int g, int b) {
|
||||
write_led("red", r);
|
||||
write_led("green", g);
|
||||
write_led("blue", b);
|
||||
static void write_single_cover_led(int idx, int r, int g, int b) {
|
||||
if (idx < 1 || idx > 6) return;
|
||||
char dir_path[64];
|
||||
snprintf(dir_path, sizeof(dir_path), "/sys/class/leds/rgb:indicator-%d", idx);
|
||||
write_mc_led_dir(dir_path, r, g, b);
|
||||
}
|
||||
|
||||
static void sync_charging_led(void) {
|
||||
static int read_charging_state(void) {
|
||||
DIR *d = opendir("/sys/class/power_supply");
|
||||
if (!d) return;
|
||||
if (!d) return 0;
|
||||
int state = 0;
|
||||
struct dirent *de;
|
||||
while ((de = readdir(d)) != NULL) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char p[320], typ[32] = {0}, st[32] = {0};
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/type", de->d_name);
|
||||
FILE *ft = fopen(p, "r");
|
||||
if (!ft) continue;
|
||||
if (fgets(typ, sizeof(typ), ft)) {
|
||||
size_t ln = strlen(typ);
|
||||
while (ln > 0 && typ[ln - 1] == '\n') typ[--ln] = '\0';
|
||||
}
|
||||
fclose(ft);
|
||||
if (strcmp(typ, "Battery") != 0) continue;
|
||||
if (read_sysfs_line(p, typ, sizeof(typ)) != 0) continue;
|
||||
if (strcmp(typ, "Battery") != 0 && strcmp(typ, "USB") != 0) continue;
|
||||
|
||||
snprintf(p, sizeof(p), "/sys/class/power_supply/%s/status", de->d_name);
|
||||
FILE *fs = fopen(p, "r");
|
||||
if (fs) {
|
||||
if (fgets(st, sizeof(st), fs)) {
|
||||
size_t ln = strlen(st);
|
||||
while (ln > 0 && st[ln - 1] == '\n') st[--ln] = '\0';
|
||||
}
|
||||
fclose(fs);
|
||||
if (read_sysfs_line(p, st, sizeof(st)) != 0) continue;
|
||||
if (strcmp(st, "Charging") == 0) {
|
||||
state = 1;
|
||||
break;
|
||||
} else if (strcmp(st, "Full") == 0) {
|
||||
state = 2;
|
||||
}
|
||||
if (strcmp(st, "Charging") == 0) apply_rgb(32, 16, 0);
|
||||
else if (strcmp(st, "Full") == 0) apply_rgb(0, 32, 0);
|
||||
else apply_rgb(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
closedir(d);
|
||||
return state;
|
||||
}
|
||||
|
||||
static void sync_charging_led(int *last_state, bool force) {
|
||||
int st = read_charging_state();
|
||||
if (!force && *last_state == st) return;
|
||||
*last_state = st;
|
||||
if (st == 1) apply_strip_rgb(32, 16, 0, false);
|
||||
else if (st == 2) apply_strip_rgb(0, 32, 0, false);
|
||||
else apply_strip_rgb(0, 0, 0, true);
|
||||
}
|
||||
|
||||
static void disarm_timer(int tmr_fd) {
|
||||
if (tmr_fd < 0) return;
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
timerfd_settime(tmr_fd, 0, &its, NULL);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -103,9 +182,14 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int uev_fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
|
||||
int uev_fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
|
||||
NETLINK_KOBJECT_UEVENT);
|
||||
if (uev_fd >= 0) {
|
||||
struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_pid = (uint32_t)getpid(), .nl_groups = 1 };
|
||||
struct sockaddr_nl nl = {
|
||||
.nl_family = AF_NETLINK,
|
||||
.nl_pid = (uint32_t)getpid(),
|
||||
.nl_groups = 1,
|
||||
};
|
||||
bind(uev_fd, (struct sockaddr *)&nl, sizeof(nl));
|
||||
}
|
||||
|
||||
@@ -120,7 +204,8 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
sync_charging_led();
|
||||
int last_chg_state = -1;
|
||||
sync_charging_led(&last_chg_state, true);
|
||||
|
||||
struct epoll_event events[8];
|
||||
bool running = true;
|
||||
@@ -140,19 +225,34 @@ int main(void) {
|
||||
char cmd[128] = {0};
|
||||
ssize_t r = read(cfd, cmd, sizeof(cmd) - 1);
|
||||
if (r > 0) {
|
||||
while (r > 0 && (cmd[r - 1] == '\n' || cmd[r - 1] == '\r')) cmd[--r] = '\0';
|
||||
int rr = 0, gg = 0, bb = 0, ms = 0;
|
||||
while (r > 0 && (cmd[r - 1] == '\n' || cmd[r - 1] == '\r')) {
|
||||
cmd[--r] = '\0';
|
||||
}
|
||||
int idx = 0, rr = 0, gg = 0, bb = 0, ms = 0;
|
||||
if (strcmp(cmd, "off") == 0) {
|
||||
apply_rgb(0, 0, 0);
|
||||
disarm_timer(tmr_fd);
|
||||
apply_strip_rgb(0, 0, 0, true);
|
||||
} else if (strcmp(cmd, "auto") == 0) {
|
||||
disarm_timer(tmr_fd);
|
||||
sync_charging_led(&last_chg_state, true);
|
||||
} else if (sscanf(cmd, "rgb %d %d %d", &rr, &gg, &bb) == 3) {
|
||||
apply_rgb(rr, gg, bb);
|
||||
disarm_timer(tmr_fd);
|
||||
apply_strip_rgb(rr, gg, bb, false);
|
||||
} else if (sscanf(cmd, "led %d %d %d %d", &idx, &rr, &gg, &bb) == 4) {
|
||||
if (idx >= 1 && idx <= 6) {
|
||||
write_single_cover_led(idx, rr, gg, bb);
|
||||
}
|
||||
} else if (sscanf(cmd, "pulse %d %d %d %d", &rr, &gg, &bb, &ms) == 4) {
|
||||
apply_rgb(rr, gg, bb);
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
its.it_value.tv_sec = ms / 1000;
|
||||
its.it_value.tv_nsec = (ms % 1000) * 1000000L;
|
||||
timerfd_settime(tmr_fd, 0, &its, NULL);
|
||||
apply_strip_rgb(rr, gg, bb, false);
|
||||
if (ms > 0 && tmr_fd >= 0) {
|
||||
struct itimerspec its;
|
||||
memset(&its, 0, sizeof(its));
|
||||
its.it_value.tv_sec = ms / 1000;
|
||||
its.it_value.tv_nsec = (ms % 1000) * 1000000L;
|
||||
timerfd_settime(tmr_fd, 0, &its, NULL);
|
||||
} else {
|
||||
disarm_timer(tmr_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
dprintf(cfd, "OK\n");
|
||||
@@ -161,11 +261,19 @@ int main(void) {
|
||||
} else if (fd == tmr_fd) {
|
||||
uint64_t exp = 0;
|
||||
while (read(tmr_fd, &exp, sizeof(exp)) > 0) {}
|
||||
sync_charging_led();
|
||||
sync_charging_led(&last_chg_state, true);
|
||||
} else if (fd == uev_fd) {
|
||||
char ubuf[1024];
|
||||
while (recv(uev_fd, ubuf, sizeof(ubuf), 0) > 0) {}
|
||||
sync_charging_led();
|
||||
bool ps_event = false;
|
||||
ssize_t ulen;
|
||||
while ((ulen = recv(uev_fd, ubuf, sizeof(ubuf), 0)) > 0) {
|
||||
if (geminux_uevent_is_power_supply(ubuf, (size_t)ulen)) {
|
||||
ps_event = true;
|
||||
}
|
||||
}
|
||||
if (ps_event) {
|
||||
sync_charging_led(&last_chg_state, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user