目录[-]


1、查看设备

在项目中需要使用游戏手柄对设备进行一些操作,在此选择了微软xbox手柄,通过在linux下调用设备描述文件来获取游戏手柄的输入数据,使用步骤以及代码描述如下。

• Microsoft X-Box One S pad 游戏手柄在ubuntu下的驱动程序;

sudo apt-get install joystick

• 在linux系统下,向系统中插入硬件时,操作系统回味每一个设备分配一个event号,在开发游戏手柄驱动时,需要首先找到游戏手柄对应的event以及线程,通过以下指令可以获取;

cat /proc/bus/input/devices

• linux下,查看系统中插入设备对应的所有event以及线程:

ls /dev/input

• 查看端口输出:

cat /dev/input/js0 | hexdump

2、代码描述

#include "fcntl.h"//Unix 下通用头文件,包含文件的open,close函数
#include "stdio.h"//perror
#include "stdlib.h"
#include "linux/joystick.h"
#include "string.h"//memset
#include <unistd.h>  
#include <string.h>  
#include <sys/types.h>  
#include <sys/stat.h>  
#include <errno.h>  
#include <linux/input.h>  
#include <linux/joystick.h>

#include "../include/microbox.h"

//microbox_acti_type-&