Bring up SSD2092 display/touch, USB NCM, HiDPI XLibre/DWM, and USB charging
This commit is contained in:
1 parent
034c1f61b1
commit
9db15e30ce
150 files changed
+2356
-446
No files matched your search
@@ -16,9 +16,10 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MODEM_SOCK "/run/geminux/modem.sock"
|
||||
#define STATE_FILE "/run/geminux/modem-state"
|
||||
#define AT_DEV "/dev/ttyC0"
|
||||
#define MODEM_SOCK "/run/geminux/modem.sock"
|
||||
#define MODEM_SOCK_FALLBACK "/tmp/geminux-modem.sock"
|
||||
#define STATE_FILE "/run/geminux/modem-state"
|
||||
#define AT_DEV "/dev/ttyC0"
|
||||
|
||||
typedef struct {
|
||||
int epfd;
|
||||
@@ -29,6 +30,7 @@ typedef struct {
|
||||
bool muted;
|
||||
bool speaker;
|
||||
char active_peer[64];
|
||||
char sock_path[64];
|
||||
} modem_ctx_t;
|
||||
|
||||
static void spawn_bg(const char *const argv[]) {
|
||||
@@ -182,9 +184,31 @@ static void handle_cmd(modem_ctx_t *ctx, int cfd) {
|
||||
}
|
||||
}
|
||||
|
||||
static int bind_modem_socket(modem_ctx_t *ctx) {
|
||||
const char *candidates[2] = { MODEM_SOCK, MODEM_SOCK_FALLBACK };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
unlink(candidates[i]);
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (fd < 0) return -1;
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", candidates[i]);
|
||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0 && listen(fd, 8) == 0) {
|
||||
chmod(candidates[i], 0660);
|
||||
snprintf(ctx->sock_path, sizeof(ctx->sock_path), "%s", candidates[i]);
|
||||
return fd;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
ctx->sock_path[0] = '\0';
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
modem_ctx_t ctx;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.srv_fd = -1;
|
||||
ctx.at_fd = -1;
|
||||
mkdir("/run/geminux", 0755);
|
||||
|
||||
@@ -195,18 +219,7 @@ int main(void) {
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
ctx.sig_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||
|
||||
unlink(MODEM_SOCK);
|
||||
ctx.srv_fd = socket(AF_UNIX, SOCK_STREAM | O_NONBLOCK | O_CLOEXEC, 0);
|
||||
if (ctx.srv_fd >= 0) {
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", MODEM_SOCK);
|
||||
if (bind(ctx.srv_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
|
||||
listen(ctx.srv_fd, 8);
|
||||
chmod(MODEM_SOCK, 0660);
|
||||
}
|
||||
}
|
||||
ctx.srv_fd = bind_modem_socket(&ctx);
|
||||
|
||||
ctx.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
int fixed[2] = {ctx.sig_fd, ctx.srv_fd};
|
||||
@@ -232,15 +245,38 @@ int main(void) {
|
||||
if (fd == ctx.sig_fd) {
|
||||
running = false;
|
||||
} else if (fd == ctx.srv_fd) {
|
||||
if (events[i].events & (EPOLLERR | EPOLLHUP)) {
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.srv_fd, NULL);
|
||||
close(ctx.srv_fd);
|
||||
ctx.srv_fd = -1;
|
||||
continue;
|
||||
}
|
||||
int cfd;
|
||||
while ((cfd = accept4(ctx.srv_fd, NULL, NULL, SOCK_CLOEXEC)) >= 0) {
|
||||
handle_cmd(&ctx, cfd);
|
||||
close(cfd);
|
||||
}
|
||||
if (errno == EINVAL || errno == EBADF || errno == ENOTSOCK || errno == EOPNOTSUPP) {
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.srv_fd, NULL);
|
||||
close(ctx.srv_fd);
|
||||
ctx.srv_fd = -1;
|
||||
}
|
||||
} else if (fd == ctx.at_fd) {
|
||||
if (events[i].events & (EPOLLHUP | EPOLLERR)) {
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.at_fd, NULL);
|
||||
close(ctx.at_fd);
|
||||
ctx.at_fd = -1;
|
||||
write_state(&ctx);
|
||||
continue;
|
||||
}
|
||||
char atbuf[512] = {0};
|
||||
ssize_t r = read(ctx.at_fd, atbuf, sizeof(atbuf) - 1);
|
||||
if (r > 0) {
|
||||
if (r == 0 || (r < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)) {
|
||||
epoll_ctl(ctx.epfd, EPOLL_CTL_DEL, ctx.at_fd, NULL);
|
||||
close(ctx.at_fd);
|
||||
ctx.at_fd = -1;
|
||||
write_state(&ctx);
|
||||
} else if (r > 0) {
|
||||
if (strstr(atbuf, "RING")) {
|
||||
const char *ntf[] = {"notify-send", "Incoming Call", "Voice call on MT6797 LTE", NULL};
|
||||
spawn_bg(ntf);
|
||||
@@ -255,7 +291,7 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
unlink(MODEM_SOCK);
|
||||
if (ctx.sock_path[0]) unlink(ctx.sock_path);
|
||||
close(ctx.epfd);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user