Skip to content

Instantly share code, notes, and snippets.

@slavapestov
Created August 9, 2020 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slavapestov/6f894594db02c580b3203ee8be5d66a8 to your computer and use it in GitHub Desktop.
Save slavapestov/6f894594db02c580b3203ee8be5d66a8 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <termios.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/termios.h>
#include <sys/types.h>
int main() {
int fd;
struct termios termios_p;
int status;
speed_t speed;
fd = open("/dev/mouse", O_RDWR);
if (fd < 0) { perror("open"); return 1; }
status = tcgetattr(fd, &termios_p);
if (status < 0) { perror("tcgetattr"); return 1; }
speed = cfgetispeed(&termios_p);
printf("%x\n", speed);
status = cfsetispeed(&termios_p, B4800);
if (status) { perror("cfsetispeed\n"); return 1; }
speed = cfgetospeed(&termios_p);
printf("%x\n", speed);
status = cfsetospeed(&termios_p, B4800);
if (status) { perror("cfsetospeed\n"); return 1; }
status = tcsetattr(fd, TCSANOW, &termios_p);
if (status) { perror("tcsetattr"); return 1; }
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment