⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tty.h

📁 足球机器人自动程序
💻 H
字号:
#ifndef TTY_H#define TTY_H#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <termios.h>#include <unistd.h>inline int ttys_init(int id) {		if (id < 0 || id > 9) {		fprintf(stderr, "ttys id should be 0 to 9\n");		exit(-1);	}	char dev[12];	sprintf(dev, "/dev/ttyS%d", id);	int fd;        if ((fd = open(dev, O_RDWR | O_NOCTTY)) < 0) {		perror(dev);		return -1;	}        	struct termios tio;        memset(&tio, 0, sizeof(tio));        tio.c_cflag = B19200 | CS8 | CLOCAL | CREAD | PARENB;	tio.c_iflag = INPCK;        tio.c_cc[VMIN] = 1;                 if (tcsetattr(fd, TCSANOW, &tio) < 0) {		perror("tcsetattr");		return -1;	}	return fd;}inline void tty_set(struct termios *tio) {	struct termios t;	tcgetattr(0, &t);	*tio = t;	t.c_lflag = ISIG;	t.c_cc[VMIN] = 1;	t.c_cc[VTIME] = 0;	tcflush(0, TCIFLUSH);	tcsetattr(0, TCSANOW, &t);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -