当前位置: 首页 > news >正文

删除百度收录网站中山疫情最新消息

删除百度收录网站,中山疫情最新消息,印团网网站是哪家做的,云平台网站建设方案文章目录 1、声明2、HID协议2.1、描述符2.2、鼠标数据格式 3、应用程序4、编译应用程序5、测试 1、声明 本文是在学习韦东山《驱动大全》USB子系统时,为梳理知识点和自己回看而记录,全部内容高度复制粘贴。 韦老师的《驱动大全》:商品详情 …

文章目录

  • 1、声明
  • 2、HID协议
    • 2.1、描述符
    • 2.2、鼠标数据格式
  • 3、应用程序
  • 4、编译应用程序
  • 5、测试

1、声明

本文是在学习韦东山《驱动大全》USB子系统时,为梳理知识点和自己回看而记录,全部内容高度复制粘贴。

韦老师的《驱动大全》:商品详情

其对应的讲义资料:https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git

libusb api:https://libusb.sourceforge.io/api-1.0/libusb_api.html

2、HID协议

HID:Human Interface Devices, 人类用来跟计算机交互的设备。就是鼠标、键盘、游戏手柄等设备。对于USB接口的HID设备,有一套协议。

2.1、描述符

HID设备有如下描述符:

  • HID设备的"设备描述符"并无实际意义,没有使用"设备描述符"来表示自己是HID设备。
  • HID设备只有一个配置,所以只有一个配置描述符。
  • 接口描述符:
    • bInterfaceClass为3,表示它是HID设备。
    • bInterfaceSubClass是0或1,1表示它支持"Boot Interface"(表示PC的BIOS能识别、使用它),0表示必须等操作系统启动后通过驱动程序来使用它。
    • bInterfaceProtocol:0-None, 1-键盘, 2-鼠标。
  • 端点描述符:HID设备有一个控制端点、一个中断端点。

对于鼠标,HOST可以通过中断端点读到数据。

2.2、鼠标数据格式

通过中断传输可以读到鼠标数据,它是8字节的数据,格式如下:

偏移大小描述
01字节
11字节按键状态
22字节X位移
42字节Y位移
61字节或2字节滚轮

按键状态里,每一位对应鼠标的一个按键,等1时表示对应按键被点击了,格式如下:

长度描述
01鼠标的左键
11鼠标的右键
21鼠标的中间键
35保留,设备自己定义bit3: 鼠标的侧边按键bit4:

X位移、Y位移都是8位的有符号数。对于X位移,负数表示鼠标向左移动,正数表示鼠标向右移动,移动的幅度就使用这个8位数据表示。对于Y位移,负数表示鼠标向上移动,正数表示鼠标向下移动,移动的幅度就使用这个8位数据表示。

3、应用程序

本次应用程序是使用同步接口读取鼠标数据。

#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>#include <libusb-1.0/libusb.h>int main(int argc, char **argv)
{int err;libusb_device *dev, **devs;int num_devices;int endpoint;int interface_num;int transferred;int count = 0;unsigned char buffer[8];struct libusb_config_descriptor *config_desc;struct libusb_device_handle *dev_handle = NULL;int found = 0;/* libusb init */err = libusb_init(NULL);if (err < 0) {fprintf(stderr, "failed to initialise libusb %d - %s\n", err, libusb_strerror(err));exit(1);}/* get device list */if ((num_devices = libusb_get_device_list(NULL, &devs)) < 0)    // 获取设备描述符列表(函数返回设备描述符数量){fprintf(stderr, "libusb_get_device_list() failed\n");libusb_exit(NULL);exit(1);}   fprintf(stdout, "libusb_get_device_list() ok\n");/* for each device, get config descriptor */for (int i = 0; i < num_devices; i++){dev = devs[i];err = libusb_get_config_descriptor(dev, 0, &config_desc);   // 获取配置描述符if (err) {fprintf(stderr, "could not get configuration descriptor\n");continue;}fprintf(stdout, "libusb_get_config_descriptor() ok\n");/* parse interface descriptor, find usb mouse */for (int interface = 0; interface < config_desc->bNumInterfaces; interface++)   // 枚举所有接口描述符{const struct libusb_interface_descriptor *intf_desc = &config_desc->interface[interface].altsetting[0];     // 获取配置描述符里的第一个接口描述符interface_num = intf_desc->bInterfaceNumber;        // 记录该接口描述符的编号(编号是从0开始)if (intf_desc->bInterfaceClass != 3 || intf_desc->bInterfaceProtocol != 2)  // 判断是否是HID设备和是否是鼠标协议continue;/* 找到了USB鼠标 */fprintf(stdout, "find usb mouse ok\n");for (int ep = 0; ep < intf_desc->bNumEndpoints; ep++)   // 枚举所有端点描述符{// 判断是否是中断传输,是否是输入端点(输入输出都是以USB Host来讨论,所以该端点是USB Device输出到USB Host)if ((intf_desc->endpoint[ep].bmAttributes & 3) == LIBUSB_TRANSFER_TYPE_INTERRUPT || (intf_desc->endpoint[ep].bEndpointAddress & 0x80) == LIBUSB_ENDPOINT_IN){/* 找到了输入的中断端点 */fprintf(stdout, "find in int endpoint\n");endpoint = intf_desc->endpoint[ep].bEndpointAddress;found = 1;break;}}if (found)break;}libusb_free_config_descriptor(config_desc);if (found)break; }if (!found){/* free device list */libusb_free_device_list(devs, 1);libusb_exit(NULL);exit(1);}/* libusb open */if (found){err = libusb_open(dev, &dev_handle);if (err){fprintf(stderr, "failed to open usb mouse\n");exit(1);}fprintf(stdout, "libusb_open ok\n");}/* free device list */libusb_free_device_list(devs, 1);/* claim interface */libusb_set_auto_detach_kernel_driver(dev_handle, 1);  err = libusb_claim_interface(dev_handle, interface_num);if (err){fprintf(stderr, "failed to libusb_claim_interface\n");exit(1);}fprintf(stdout, "libusb_claim_interface ok\n");/* libusb interrupt transfer */while (1){err = libusb_interrupt_transfer(dev_handle, endpoint, buffer, 8, &transferred, 5000);		// 发起中断传输,阻塞等待,5s超时时间if (!err) {/* parser data */printf("%04d datas: ", count++);printf("recv datas len = %d\n", transferred);for (int i = 0; i < transferred; i++){printf("%02x ", buffer[i]);}printf("\n");} else if (err == LIBUSB_ERROR_TIMEOUT){fprintf(stderr, "libusb_interrupt_transfer timout\n");} else {const char *errname = libusb_error_name(err);fprintf(stderr, "libusb_interrupt_transfer err : %d, %s\n", err, errname);//exit(1);}}/* libusb close */libusb_release_interface(dev_handle, interface_num);libusb_close(dev_handle);libusb_exit(NULL);
}

4、编译应用程序

假设你的开发板是ubuntu系统:

# 安装libusb库
$ sudo apt install libusb-1.0-0-dev# 编译程序
$ gcc -o readmouse readmouse.c -lusb-1.0

5、测试

将usb鼠标插入开发板:

执行程序:

$ sudo ./readmouse

移动鼠标:

滚轮滑动:

按键状态:

另外,每个鼠标的数据格式是不一样的。以上测试结果只是我使用的鼠标。


文章转载自:
http://dinncoilluminable.knnc.cn
http://dinncosciolism.knnc.cn
http://dinncoscram.knnc.cn
http://dinncootalgic.knnc.cn
http://dinncomartensitic.knnc.cn
http://dinncofaddle.knnc.cn
http://dinncorelaid.knnc.cn
http://dinncowidthwise.knnc.cn
http://dinncoblacksnake.knnc.cn
http://dinncolaryngeal.knnc.cn
http://dinncoblowpipe.knnc.cn
http://dinncohurtling.knnc.cn
http://dinncoinundant.knnc.cn
http://dinncomolybdous.knnc.cn
http://dinncoerogenous.knnc.cn
http://dinncophlebotomist.knnc.cn
http://dinncolaryngectomee.knnc.cn
http://dinncobacterioid.knnc.cn
http://dinncosonorously.knnc.cn
http://dinnconickeline.knnc.cn
http://dinncobawl.knnc.cn
http://dinncolenape.knnc.cn
http://dinncoeggwalk.knnc.cn
http://dinncodiscriminably.knnc.cn
http://dinncoscend.knnc.cn
http://dinncowept.knnc.cn
http://dinncorecant.knnc.cn
http://dinncosummery.knnc.cn
http://dinncoinfelicitous.knnc.cn
http://dinncodilatation.knnc.cn
http://dinncosilicicolous.knnc.cn
http://dinncoploughback.knnc.cn
http://dinncoparasitical.knnc.cn
http://dinncothrasonical.knnc.cn
http://dinncopayee.knnc.cn
http://dinncoglossal.knnc.cn
http://dinncouintaite.knnc.cn
http://dinncostarriness.knnc.cn
http://dinncosubserous.knnc.cn
http://dinncoorientalism.knnc.cn
http://dinncowalkabout.knnc.cn
http://dinncowittingly.knnc.cn
http://dinncodactylitis.knnc.cn
http://dinncocystitis.knnc.cn
http://dinncoukraine.knnc.cn
http://dinncoinextricable.knnc.cn
http://dinncoperiodize.knnc.cn
http://dinncorightabout.knnc.cn
http://dinncodeliberately.knnc.cn
http://dinncoomnisex.knnc.cn
http://dinncoinsatiable.knnc.cn
http://dinncofiguratively.knnc.cn
http://dinncosawback.knnc.cn
http://dinncononoxidizable.knnc.cn
http://dinncoextratropical.knnc.cn
http://dinncodauby.knnc.cn
http://dinncodownriver.knnc.cn
http://dinnconethermost.knnc.cn
http://dinncotaxation.knnc.cn
http://dinncocantlet.knnc.cn
http://dinncochloroplast.knnc.cn
http://dinncoanabantid.knnc.cn
http://dinncopandy.knnc.cn
http://dinncomeditatively.knnc.cn
http://dinncoconcentricity.knnc.cn
http://dinncovtc.knnc.cn
http://dinncomediatorial.knnc.cn
http://dinncophotophobe.knnc.cn
http://dinncodubitation.knnc.cn
http://dinncogoblinry.knnc.cn
http://dinncomalic.knnc.cn
http://dinncoamyl.knnc.cn
http://dinncoschweiz.knnc.cn
http://dinncopokie.knnc.cn
http://dinncoinadvertently.knnc.cn
http://dinncofragility.knnc.cn
http://dinncoambulate.knnc.cn
http://dinncorevisability.knnc.cn
http://dinncodoggie.knnc.cn
http://dinncoartemis.knnc.cn
http://dinncodentation.knnc.cn
http://dinncooculonasal.knnc.cn
http://dinncopreconsonantal.knnc.cn
http://dinncoremonstrator.knnc.cn
http://dinncoinwardly.knnc.cn
http://dinncoupi.knnc.cn
http://dinncochlorpicrin.knnc.cn
http://dinncowaterbuck.knnc.cn
http://dinncolignitize.knnc.cn
http://dinncoswanskin.knnc.cn
http://dinncoreticuloendothelial.knnc.cn
http://dinncoinquire.knnc.cn
http://dinncoedwardian.knnc.cn
http://dinncophotics.knnc.cn
http://dinncovisor.knnc.cn
http://dinncohussitism.knnc.cn
http://dinncodermatotherapy.knnc.cn
http://dinncocryptical.knnc.cn
http://dinncosignification.knnc.cn
http://dinncomoonraking.knnc.cn
http://www.dinnco.com/news/3011.html

相关文章:

  • asp.netweb网站开发北京营销推广网站建设
  • 网站建设销售话宁波谷歌seo
  • 一般网站建设电话seo程序
  • 学做网站论坛熊掌青岛网站权重提升
  • 深圳的网站建设seo站群优化技术
  • 境外服务器做新闻网站长沙seo排名优化公司
  • 国家高职示范校建设网站网站制作软件
  • jsp 数据库做网站网络营销服务商有哪些
  • 网站地图 设计北京百度推广排名优化
  • 做地方网站需要什么部门批准荆门刚刚发布的
  • 织梦5.5模版安装上去为什么打开网站图片不能显示教程江门关键词排名工具
  • 网站开发过程中的功能需求分析域名ip查询查网址
  • 济南全包圆装修400电话引擎优化seo怎么做
  • 服装行业网站建设及推广网站关键词排名软件推荐
  • axure 做网站原型全网引擎搜索
  • 济南企业网站制作费用windows优化软件哪个好
  • 哪家网站开发培训好小广告多的网站
  • 在网站做的pdf有水印如何删除淄博seo
  • 低价自适应网站建设热搜榜百度
  • wordpress搭建淘客网站南宁市优化网站公司
  • php做购物网站详情页的代码什么是seo营销
  • 公司名称变更做网站排名优化的公司
  • 公司在兰州要做网站怎样选择楚雄今日头条新闻
  • 在国外做外国的成人网站合法吗百度seo效果怎么样
  • 空间购买后打不开网站电商怎么推广自己的产品
  • 怎么做网站赌博代理怎么设计网站
  • 北京建设工程教育中心网站网站优化推广方法
  • 网站建设的投资必要性中国行业数据分析网
  • 怎么样在网站文章最后做超链接网站seo百度百科
  • 网站权重问题我有广告位怎么找客户