From 0f105c062b5a9c396b6669e1b71ef2eda96149f0 Mon Sep 17 00:00:00 2001 From: Anders Holck Date: Sat, 11 Apr 2026 00:22:13 +0200 Subject: [PATCH] clean up --- tty_c/Makefile | 4 ---- tty_c/tty.c | 58 -------------------------------------------------- 2 files changed, 62 deletions(-) delete mode 100644 tty_c/Makefile delete mode 100644 tty_c/tty.c diff --git a/tty_c/Makefile b/tty_c/Makefile deleted file mode 100644 index ae799ba..0000000 --- a/tty_c/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -tty: tty.c - $(CC) -o $@ $< -clean: - rm -f tty diff --git a/tty_c/tty.c b/tty_c/tty.c deleted file mode 100644 index 4b8816c..0000000 --- a/tty_c/tty.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int main(void) { - int fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY); - if (fd < 0) { perror("open"); return 1; } - - // Configure serial port - struct termios tty; - tcgetattr(fd, &tty); - cfmakeraw(&tty); - cfsetspeed(&tty, B115200); - tty.c_cflag |= CLOCAL | CREAD; - tty.c_cc[VMIN] = 0; - tty.c_cc[VTIME] = 1; - tcsetattr(fd, TCSANOW, &tty); - - // Set stdin to raw mode - struct termios old_stdin, raw_stdin; - tcgetattr(STDIN_FILENO, &old_stdin); - raw_stdin = old_stdin; - cfmakeraw(&raw_stdin); - tcsetattr(STDIN_FILENO, TCSANOW, &raw_stdin); - - write(STDOUT_FILENO, "Holcks minitty - ctrl-d to exit\r\n", 33); - - struct pollfd fds[2] = { - { .fd = STDIN_FILENO, .events = POLLIN }, - { .fd = fd, .events = POLLIN }, - }; - - char buf[256]; - while (1) { - poll(fds, 2, -1); - if (fds[0].revents & POLLIN) { - int n = read(STDIN_FILENO, buf, sizeof(buf)); - if (n > 0) { - for (int i = 0; i < n; i++) - if (buf[i] == 4) goto done; // Ctrl-D - write(fd, buf, n); - } - } - if (fds[1].revents & POLLIN) { - int n = read(fd, buf, sizeof(buf)); - if (n > 0) write(STDOUT_FILENO, buf, n); - } - } - -done: - tcsetattr(STDIN_FILENO, TCSANOW, &old_stdin); - close(fd); - return 0; -}