日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

linux测试手柄,Linux Joystick 介绍

發布時間:2024/9/27 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux测试手柄,Linux Joystick 介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Linux手柄使用

Linux手柄驅動, 一般為joydev, 可使用modprobe -a joydev加載驅動模塊。

手柄連接后的原始設備文件為/dev/hidraw*, 這個和具體手柄廠商的驅動相關。需要針對特定手柄進行操作優化可能需要使用這個設備。

通常情況下joydev手柄驅動提供一個通用的手柄接口供使用。joydev驅動創建的設備文件一般為/dev/input/js*。joydev驅動提供兩種不同操作: 搖桿axes和按鍵button。

一般使用joydev提供的通用驅動。使用joydev一些手柄會將十字方向鍵當作搖桿類型,而不是button類型,比如我的手柄北通蝙蝠D2(BTP-BD2F),因此在一些游戲模擬器軟件中不能識別十字按鍵。

實用工具

在Linux中提供幾個實用工具:

jscal: 按鍵校準和按鍵重映射工具

jscal-restore

jscal-store

jstest: 讀取按鍵狀態,測試按鍵是否正確

jscal 按鍵映射示例:

An example output of -q looks like this ./jscal -q /dev/input/js0:

-u

n_of_buttons,btnmap1,btnmap2,

...> --set-mappings Sets axis and button mappings to the

specified valuesjscal -u

10,0,1,2,5,6,16,17,40,41,42,13,288,289,290,291,292,293,294,295,296,297,298,299,300

/dev/input/js0

The joystick has 10 axes and 13 buttons. If now one is to switch axes 2jscal -u

10,0,1,5,2,6,16,17,40,41,42,13,288,289,290,291,292,293,294,295,296,297,298,299,300

/dev/input/js0

changing 2,5 to 5,2 on the line.

Remapping buttons is done the same way.

jstest示例:

jstest /dev/input/js0

手柄編程#include

#include

#include

typedef unsigned int __u32;

typedef short __s16;

typedef unsigned char __u8;

struct js_event {

__u32 time; /* event timestamp in milliseconds */

__s16 value; /* value */

__u8 type; /* event type */

__u8 number; /* axis/button number */

};

#define JS_EVENT_BUTTON 0x01 /* button pressed/released */

#define JS_EVENT_AXIS 0x02 /* joystick moved */

#define JS_EVENT_INIT 0x80 /* initial state of device */

int main() {

int fd = open("/dev/input/js0", O_RDONLY);

struct js_event e;

while(1) {

read(fd, &e, sizeof(e));

int type = JS_EVENT_BUTTON | JS_EVENT_INIT;

switch(e.type) {

case JS_EVENT_AXIS:

printf("axis number: %d, value: %d, time: %d\n", e.number, e.value, e.time);

break;

case JS_EVENT_BUTTON:

printf("btn: number: %d, value: %d, time: %d\n", e.number, e.value, e.time);

break;

}

}

close(fd);

return 0;

}

參考:

總結

以上是生活随笔為你收集整理的linux测试手柄,Linux Joystick 介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。