问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

ubuntu怎么用接收器连接手柄

发布网友 发布时间:2023-04-27 23:27

我来回答

1个回答

热心网友 时间:2023-10-25 05:09

在ubuntu1604/2004环境下实现xbox one无线手柄遥+usb无线适配器控机器人运动。

1. 安装xboxdrv和joystick
sudo apt install xboxdrv
sudo apt install joystick

2. 将usb无线接收器插入,查看设备信息
cat /proc/bus/input/devices
输出如下信息说明系统已经识别到了xbox的接收器

I: Bus=0003 Vendor=045e Proct=0719 Version=0100
N: Name="Xbox 360 Wireless Receiver"
P: Phys=
S: Sysfs=/devices/virtual/input/input28
U: Uniq=
H: Handlers=event28 js3
B: PROP=0
B: EV=b
B: KEY=f 0 0 0 0 0 0 7fdb000000000000 0 0 0 0
B: ABS=1b
登录后复制

3. 编译xow
Xow是一个非官方的Linux版本Xbox one手柄无线适配器驱动,其底层基于libusb进行工作,通过Wifi与游戏手柄进行连接,其使用MT76xx的Wifi chip;
3.1 下载xow源码
git clonet https://github.com/mesalix/xow.git

3.2 安装依赖
audo apt install curl libusb-1.0-0-dev cabextract

3.3 编译
cd xow
make BUILD=RELEASE
sudo make install

3.4 Download the firmware for the wireless dongle:
sudo xow-get-firmware.sh

3.5 运行xow
sudo ./xow
[sudo] password for sar:
2022-05-20 11:18:43 INFO - xow v0.5-36-gd335d60 ©Severin v. W.
2022-05-20 11:18:43 INFO - Waiting for device…
2022-05-20 11:18:43 INFO - Wireless address: 62:45:bd:05:8b:85
2022-05-20 11:18:43 INFO - Dongle initialized
2022-05-20 11:18:49 INFO - Controller ‘1’ connected
2022-05-20 11:18:49 INFO - Device announced, proct id: 02d1
2022-05-20 11:18:49 INFO - Battery level: full
2022-05-20 11:28:10 INFO - Controller ‘1’ disconnected
2022-05-20 11:33:12 INFO - Controller ‘1’ connected
2022-05-20 11:33:12 INFO - Device announced, proct id: 02d1

3.6 编译错误解决:
执行make BUILD=RELEASE报错:找不到uinput_setup、uinput_abs_setup的定义
报错原因:linux内核版本太低,xow不支持UINPUT_VERSION 5以下版本;
解决方法:从高版本的ubuntu中拷贝/usr/include/linux/uinput.h替换当前系统下的/usr/include/linux/uinput.h

xow驱动分析可以参考这篇博客:https://blog.csdn.net/YingbinLi/article/details/123268015
4. xbox手柄测试
先运行./xow,在按下xbox one手柄最前端的带x标识的圆形按键,按下按键后按键灯点亮,开始慢闪,配对成功后,按键灯常亮;
打开了一个linux终端,运行:

sudo jstest /dev/input/js4
Driver version is 2.1.0.
Joystick (Xbox One Wireless Controller) has 8 axes (X, Y, Z, Rx, Ry, Rz, Hat0X, Hat0Y)
and 11 buttons (BtnA, BtnB, BtnX, BtnY, BtnTL, BtnTR, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes: 0: 0 1: 0 2:-32767 3: 0 4: 0 5:-32767 6: 0 7: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off
登录后复制
注意:在/dev/input下可能会生成js0, js1, js2, js3, js4 5个文件,可以分别使用jstest 测试一下,运行sudo jstest /dev/input/js4 后,操作手柄操作杆查看数据是否有变化。

5. xbox手柄操作数据接收与解析
joystick_xbox.h

#include <linux/input.h>
#include <linux/joystick.h>
#include <string>

class JoystickXBox
{
public:
JoystickXBox(const std::string &dev_name);
~JoystickXBox();
bool Open();
void Close();
bool Read(struct js_event &js);
unsigned char GetAxes()
{
return axes_;
}
unsigned char GetButtons()
{
return buttons_;
}
int GetFd()
{
return fd_;
}
void PrintData();
void ProcessData(const struct js_event &js);

private:
bool debug_ = false;
int fd_ = -1;
std::string dev_name_ = "";
int version_ = 0x000800;
char name_[512] = "Unkown";
unsigned char axes_ = 2;
unsigned char buttons_ = 2;
int *axis_ = nullptr;
char *button_ = nullptr;
};
登录后复制

joystick_xbox.cpp

#include <errno.h>
#include <fcntl.h>
#include <memory>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "joystick_xbox.h"

JoystickXBox::JoystickXBox(const std::string &dev_name) : fd_(-1),dev_name_(dev_name)
{
}

JoystickXBox::~JoystickXBox()
{
if (axis_)
{
delete axis_;
axis_ = nullptr;
}

if (button_)
{
delete button_;
button_ = nullptr;
}
}

bool JoystickXBox::Open()
{
int fd = -1;
if (dev_name_.length() == 0)
{
return false;
}
// O_NONBLOCK open
fd = open(dev_name_.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
fd_ = -1;
printf("JoystickXBox open %s error, %d(%s)\n", dev_name_.c_str(), errno, strerror(errno));
return false;
}

ioctl(fd, JSIOCGVERSION, &version_);
ioctl(fd, JSIOCGAXES, &axes_);
ioctl(fd, JSIOCGBUTTONS, &buttons_);
ioctl(fd, JSIOCGNAME(512), name_);
printf("JoystickXBox Driver version is %d.%d.%d.\n", version_ >> 16, (version_ >> 8) & 0xff, version_ & 0xff);
printf("JoystickXBox (%s) has %d axes and %d buttons\n", name_, axes_, buttons_);
fd_ = fd;
axis_ = (int *)calloc(axes_, sizeof(int));
button_ = (char *)calloc(buttons_, sizeof(char));

return true;
}

void JoystickXBox::Close()
{
if (fd_ > 0)
{
close(fd_);
fd_ = -1;
}
}

bool JoystickXBox::Read(struct js_event &js)
{
int len = -1;
if (fd_ < 0)
{
return false;
}

memset(&js, 0, sizeof(js));
len = read(fd_, &js, sizeof(struct js_event));
if (len != sizeof(struct js_event))
{
printf("JoystickXBox: error reading, %d(%s)\n", errno, strerror(errno));
return false;
}

return true;
}

void JoystickXBox::ProcessData(const struct js_event &js)
{
JoystickFrame frame;
int joystick_angular_value = 0;
int joystick_linear_value = 0;
int button_angular_value = 0;
int button_linear_value = 0;

switch (js.type & ~JS_EVENT_INIT)
{
case JS_EVENT_BUTTON:
button_[js.number] = js.value;
break;
case JS_EVENT_AXIS:
axis_[js.number] = js.value;
break;
}
if (debug_)
{
PrintData();
}
}

void JoystickXBox::PrintData()
{
if (axes_ && axis_)
{
printf("Axes: ");
for (int i = 0; i < axes_; i++)
{
printf("%2d:%6d ", i, axis_[i]);
}
}
if (buttons_ && button_)
{
printf("Buttons: ");
for (int i = 0; i < buttons_; i++)
{
printf("%2d:%s ", i, button_[i] ? "on " : "off");
}
}
printf("\n");
fflush(stdout);
}

int main()
{
bool ret = false;
int err_cnt = 0;
fd_set rfds;
timeval timeout;
struct js_event js;
int fd = -1;
std::string dev_name = "/dev/input/js4";
std::unique_ptr<JoystickXBox> joystick_xbox = std::make_unique<JoystickXBox>(dev_name);

ret = joystick_xbox->Open();
if (!ret)
{
return -1;
}
fd = joystick_xbox->GetFd();

while (1)
{
usleep(100);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
int ret = select(fd + 1, &rfds, NULL, NULL, &timeout);
if (ret > 0 && FD_ISSET(fd, &rfds))
{
ret = joystick_xbox->Read(js);
if (ret)
{
joystick_xbox->ProcessData(js);
}
}
}

joystick_xbox->Close();

return 0;
}

登录后复制

ubuntu
linux


点赞文章给优秀博主打call~

热心网友 时间:2023-10-25 05:09

在ubuntu1604/2004环境下实现xbox one无线手柄遥+usb无线适配器控机器人运动。

1. 安装xboxdrv和joystick
sudo apt install xboxdrv
sudo apt install joystick

2. 将usb无线接收器插入,查看设备信息
cat /proc/bus/input/devices
输出如下信息说明系统已经识别到了xbox的接收器

I: Bus=0003 Vendor=045e Proct=0719 Version=0100
N: Name="Xbox 360 Wireless Receiver"
P: Phys=
S: Sysfs=/devices/virtual/input/input28
U: Uniq=
H: Handlers=event28 js3
B: PROP=0
B: EV=b
B: KEY=f 0 0 0 0 0 0 7fdb000000000000 0 0 0 0
B: ABS=1b
登录后复制

3. 编译xow
Xow是一个非官方的Linux版本Xbox one手柄无线适配器驱动,其底层基于libusb进行工作,通过Wifi与游戏手柄进行连接,其使用MT76xx的Wifi chip;
3.1 下载xow源码
git clonet https://github.com/mesalix/xow.git

3.2 安装依赖
audo apt install curl libusb-1.0-0-dev cabextract

3.3 编译
cd xow
make BUILD=RELEASE
sudo make install

3.4 Download the firmware for the wireless dongle:
sudo xow-get-firmware.sh

3.5 运行xow
sudo ./xow
[sudo] password for sar:
2022-05-20 11:18:43 INFO - xow v0.5-36-gd335d60 ©Severin v. W.
2022-05-20 11:18:43 INFO - Waiting for device…
2022-05-20 11:18:43 INFO - Wireless address: 62:45:bd:05:8b:85
2022-05-20 11:18:43 INFO - Dongle initialized
2022-05-20 11:18:49 INFO - Controller ‘1’ connected
2022-05-20 11:18:49 INFO - Device announced, proct id: 02d1
2022-05-20 11:18:49 INFO - Battery level: full
2022-05-20 11:28:10 INFO - Controller ‘1’ disconnected
2022-05-20 11:33:12 INFO - Controller ‘1’ connected
2022-05-20 11:33:12 INFO - Device announced, proct id: 02d1

3.6 编译错误解决:
执行make BUILD=RELEASE报错:找不到uinput_setup、uinput_abs_setup的定义
报错原因:linux内核版本太低,xow不支持UINPUT_VERSION 5以下版本;
解决方法:从高版本的ubuntu中拷贝/usr/include/linux/uinput.h替换当前系统下的/usr/include/linux/uinput.h

xow驱动分析可以参考这篇博客:https://blog.csdn.net/YingbinLi/article/details/123268015
4. xbox手柄测试
先运行./xow,在按下xbox one手柄最前端的带x标识的圆形按键,按下按键后按键灯点亮,开始慢闪,配对成功后,按键灯常亮;
打开了一个linux终端,运行:

sudo jstest /dev/input/js4
Driver version is 2.1.0.
Joystick (Xbox One Wireless Controller) has 8 axes (X, Y, Z, Rx, Ry, Rz, Hat0X, Hat0Y)
and 11 buttons (BtnA, BtnB, BtnX, BtnY, BtnTL, BtnTR, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR).
Testing ... (interrupt to exit)
Axes: 0: 0 1: 0 2:-32767 3: 0 4: 0 5:-32767 6: 0 7: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off
登录后复制
注意:在/dev/input下可能会生成js0, js1, js2, js3, js4 5个文件,可以分别使用jstest 测试一下,运行sudo jstest /dev/input/js4 后,操作手柄操作杆查看数据是否有变化。

5. xbox手柄操作数据接收与解析
joystick_xbox.h

#include <linux/input.h>
#include <linux/joystick.h>
#include <string>

class JoystickXBox
{
public:
JoystickXBox(const std::string &dev_name);
~JoystickXBox();
bool Open();
void Close();
bool Read(struct js_event &js);
unsigned char GetAxes()
{
return axes_;
}
unsigned char GetButtons()
{
return buttons_;
}
int GetFd()
{
return fd_;
}
void PrintData();
void ProcessData(const struct js_event &js);

private:
bool debug_ = false;
int fd_ = -1;
std::string dev_name_ = "";
int version_ = 0x000800;
char name_[512] = "Unkown";
unsigned char axes_ = 2;
unsigned char buttons_ = 2;
int *axis_ = nullptr;
char *button_ = nullptr;
};
登录后复制

joystick_xbox.cpp

#include <errno.h>
#include <fcntl.h>
#include <memory>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "joystick_xbox.h"

JoystickXBox::JoystickXBox(const std::string &dev_name) : fd_(-1),dev_name_(dev_name)
{
}

JoystickXBox::~JoystickXBox()
{
if (axis_)
{
delete axis_;
axis_ = nullptr;
}

if (button_)
{
delete button_;
button_ = nullptr;
}
}

bool JoystickXBox::Open()
{
int fd = -1;
if (dev_name_.length() == 0)
{
return false;
}
// O_NONBLOCK open
fd = open(dev_name_.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
fd_ = -1;
printf("JoystickXBox open %s error, %d(%s)\n", dev_name_.c_str(), errno, strerror(errno));
return false;
}

ioctl(fd, JSIOCGVERSION, &version_);
ioctl(fd, JSIOCGAXES, &axes_);
ioctl(fd, JSIOCGBUTTONS, &buttons_);
ioctl(fd, JSIOCGNAME(512), name_);
printf("JoystickXBox Driver version is %d.%d.%d.\n", version_ >> 16, (version_ >> 8) & 0xff, version_ & 0xff);
printf("JoystickXBox (%s) has %d axes and %d buttons\n", name_, axes_, buttons_);
fd_ = fd;
axis_ = (int *)calloc(axes_, sizeof(int));
button_ = (char *)calloc(buttons_, sizeof(char));

return true;
}

void JoystickXBox::Close()
{
if (fd_ > 0)
{
close(fd_);
fd_ = -1;
}
}

bool JoystickXBox::Read(struct js_event &js)
{
int len = -1;
if (fd_ < 0)
{
return false;
}

memset(&js, 0, sizeof(js));
len = read(fd_, &js, sizeof(struct js_event));
if (len != sizeof(struct js_event))
{
printf("JoystickXBox: error reading, %d(%s)\n", errno, strerror(errno));
return false;
}

return true;
}

void JoystickXBox::ProcessData(const struct js_event &js)
{
JoystickFrame frame;
int joystick_angular_value = 0;
int joystick_linear_value = 0;
int button_angular_value = 0;
int button_linear_value = 0;

switch (js.type & ~JS_EVENT_INIT)
{
case JS_EVENT_BUTTON:
button_[js.number] = js.value;
break;
case JS_EVENT_AXIS:
axis_[js.number] = js.value;
break;
}
if (debug_)
{
PrintData();
}
}

void JoystickXBox::PrintData()
{
if (axes_ && axis_)
{
printf("Axes: ");
for (int i = 0; i < axes_; i++)
{
printf("%2d:%6d ", i, axis_[i]);
}
}
if (buttons_ && button_)
{
printf("Buttons: ");
for (int i = 0; i < buttons_; i++)
{
printf("%2d:%s ", i, button_[i] ? "on " : "off");
}
}
printf("\n");
fflush(stdout);
}

int main()
{
bool ret = false;
int err_cnt = 0;
fd_set rfds;
timeval timeout;
struct js_event js;
int fd = -1;
std::string dev_name = "/dev/input/js4";
std::unique_ptr<JoystickXBox> joystick_xbox = std::make_unique<JoystickXBox>(dev_name);

ret = joystick_xbox->Open();
if (!ret)
{
return -1;
}
fd = joystick_xbox->GetFd();

while (1)
{
usleep(100);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
int ret = select(fd + 1, &rfds, NULL, NULL, &timeout);
if (ret > 0 && FD_ISSET(fd, &rfds))
{
ret = joystick_xbox->Read(js);
if (ret)
{
joystick_xbox->ProcessData(js);
}
}
}

joystick_xbox->Close();

return 0;
}

登录后复制

ubuntu
linux


点赞文章给优秀博主打call~
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
为什么来大姨妈胸会胀 少儿学什么舞蹈 青年学什么舞蹈好 成年人学什么舞蹈 福州企业最低工资标准 2013年厦门的底薪是多少 生产要素的需求有哪些性质 生产要素的需求有何特点? 什么是生产要素需求 微观经济学要素需求什么是条件要素需求?它和要素需求有什么不同?_百度... 错误解决2 fatal error: openssl/opensslv.h 用q 币怎么买115网盘的会员充值 请问115怎么不能开通会员 得了股癣怎么治疗 用什么药 得了1个月了 也没下去 体股癣怎么治 oppor9和opporeno9pro外形一样吗 为什么微信解除了银行卡还能看到卡号 阳早,寒春是犹太人吗? 阳早与寒春 请问手癣的最好治疗方法是什么、偏方也行 一对老外阳早,寒春的故事 阳早寒春的精神 人家说我的脸长的很标致,是什么意思? 掉发严重是什么原因呢 掉头发严重是什么原因呢? Steam游戏如何退款 110可不可以查电话? 110可以查电话吗?不知道的不要,乱讲 打110可以查湖南的号码吗 注册未满15天的注销需要多久? msdn我告诉你里的windows系统怎么辨认旗舰版专业版企业版 请问股藓 用什么药膏有效 台式机想加2G内存条,不知道加什么类型的内存和电脑兼容,下面是机子的资料 三脔的引证解释三脔的引证解释是什么 建筑设计和建筑规划之间的关系? 建筑规划与设计关系与协调? 城市规划与城市设计有什么区别 如何进行职业规划与设计 安排建筑设计与城市规划的关系? 新娘新郎伴娘伴郎的胸花都是用什么花材制作的怎么制作的急 胸花的制作方法 新娘鲜花胸花怎么做 2023年资产评估师报名时间 注册资产评估师(CPV)简介 2020年资产评估师考试时间安排 资产评估师什么时候考试 2021年四川资产评估师考试时间及方式:9月19日-20日 回流比控制器如何保持回流罐液位 当回流比rrmin时精馏塔是否还能进行操作如何确定精馏塔的操作回流比 请问新版一百元人民币编号后四位分别是0000和9999有收藏价值么?