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

📄 joystick.c

📁 在linux下多媒体开发实例linux下多媒体开发
💻 C
字号:
/* * joystick.c * Example program for joystick driver. Returns status of first * joystick. Requires kernel joystick driver. */#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <sys/ioctl.h>#include <fcntl.h>#include <linux/joystick.h>int main(){  int fd, status;  struct JS_DATA_TYPE js;  struct JS_DATA_SAVE_TYPE jsd;  /* open device file */  status = fd = open("/dev/js0", O_RDONLY);  if (status < 0) {    perror("open of /dev/js0 failed");    exit(1);  }  /* display current settings */  status = ioctl(fd, JS_GET_ALL, &jsd);  if (status == -1) {    perror("error from ioctl");    exit(1);  }  printf(	 "timeout: %d  busy: %d  expire time: %ld  time limit: %ld\n"	 "buttons: %d  x: %d  y: %d  x corr: %d  y corr: %d\n"	 "Current joystick settings: (interrupt to exit)\n",	 jsd.JS_TIMEOUT, jsd.BUSY, jsd.JS_EXPIRETIME,	 jsd.JS_TIMELIMIT, jsd.JS_SAVE.buttons,	 jsd.JS_SAVE.x, jsd.JS_SAVE.y,	 jsd.JS_CORR.x, jsd.JS_CORR.y);  while (1) {    status = read(fd, &js, JS_RETURN);    if (status != JS_RETURN) {      perror("error reading /dev/js0");      exit(1);    }    printf("button 0: %s  button 1: %s  X axis: %4d  Y axis: %4d\r",	    (js.buttons & 0x01) ? "on " : "off",	    (js.buttons & 0x02) ? "on " : "off",	    js.x,	    js.y);    fflush(stdout); /* make sure line is output */    usleep(100); /* don't run too fast */  }  exit(0);}

⌨️ 快捷键说明

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