英伟达 TX2 蓝牙自动连接蓝牙 设备

本文指导读者在Ubuntu系统中安装blueman、修改蓝牙配置,启用蓝牙服务,通过bluetoothctl进行配对操作,并验证蓝牙键盘设备。包括sudo apt-get安装、蓝牙配置、重启系统及蓝牙控制命令的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. sudo apt-get install blueman bluez*

 

2. vi /etc/bluetooth/main.conf

    去掉行[Policy]和AutoEnable前的注释,将AutoEnable 设置为True

#FastConnectable = false

[Policy]
#
# The ReconnectUUIDs defines the set of remote services that should try


# in later on. Defaults to 'false'.
AutoEnable=true
3. sudo vi /lib/udev/rules.d/50-bluetooth-hci-auto-poweron.rules

屏蔽下面行

# Set bluetooth power up
#ACTION=="add", SUBSYSTEM=="bluetooth", KERNEL=="hci[0-9]*", RUN+="/bin/hciconfig %k up"

4. 重启系统
5. 检查蓝牙服务是否开启

#开启蓝牙
sudo rfkill unblock bluetooth


sudo systemctl status bluetooth

sudo systemctl status nvwifibt.service

6.  现在可以查看是否有蓝牙适配器

root@tegra-ubuntu:/home/nvidia# hciconfig 
hci0:   Type: BR/EDR  Bus: UART
        BD Address: 00:04:4B:8D:3B:FF  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING 
        RX bytes:836 acl:0 sco:0 events:58 errors:0
        TX bytes:4531 acl:0 sco:0 commands:58 errors:0

二 蓝牙配对

 

运行bluetoothctl命令
# bluetoothctl
列出可用的蓝牙控制器
[bluetooth]# list
选择使用的蓝牙控制器
[bluetooth]# select 01:23:45:67:89:AB
显示蓝牙控制器的详细信息
bluetooth]# show
打开蓝牙
[bluetooth]# power on
开始扫描
[bluetooth]# scan on
结束扫描
[bluetooth]# scan off
选择蓝牙设备配对
[bluetooth]# pair 34:88:5D:87:C0:A6(你的蓝牙设备)
连接到蓝牙设备
[bluetooth]# connect FF:FF:98:00:FC:B0
信任设备
[bluetooth]# trust FF:FF:98:00:FC:B0

三 配对成功后,生成 在/dev/input/event4 设备输入文件,我连接的是个蓝牙键盘
编写测试用例 检测 蓝牙键盘

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>


int main(){
	int key_fd=-1;
	key_fd = open("/dev/input/event4", O_RDONLY);
    if(key_fd < 0)
    {
        printf("open /dev/input/event4 failded...\n");
    }
	while(1){
		struct input_event t;
        if (read (key_fd, &t, sizeof (t)) == sizeof(t)){
            if (t.type == EV_KEY)
				printf("key code %d value %d\n",t.code,t.value );
        }
	}
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值