#include "usb.h"
libusb_device_handle *handle;
uint8_t endpoint_in=0;
uint8_t endpoint_out=0;
uint8_t data_buf[32]={0};
int usb_Init(void)
{
int endpoint_num, number_interfaces, altesetting = -1;
int i;
int res;
libusb_device *dev;
struct libusb_config_descriptor *conf_desc;
const struct libusb_endpoint_descriptor *endpoint;
//data inial
data_buf[0] = 0xaa;
data_buf[31] = 0xed;
//lib init
libusb_init(NULL);
//打开设备
handle = libusb_open_device_with_vid_pid(NULL, 0x0525, 0xa4a0);
if(handle == NULL)
{
return draw_ERROR;
}
//获取端口
dev = libusb_get_device(handle);
libusb_get_config_descriptor(dev, 0, &conf_desc);
number_interfaces = conf_desc->bNumInterfaces;
if(number_interfaces > 0)
{
altesetting = conf_desc->interface[0].num_altsetting;
if(altesetting > 0)
{
endpoint_num = conf_desc->interface[0].altsetting[0].bNumEndpoints;
if(endpoint_num > 0)
{
for(i = 0; i < endpoint_num; i++)
{
endpoint = &conf_desc->interface[0].altsetting[0].endpoint[i];
if ((endpoint->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) & \
(LIBUSB_TRANSFER_TYPE_BULK | LIBUSB_TRANSFER_TYPE_INTERRUPT))
{
if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN)
{
if (!endpoint_in)
endpoint_in = endpoint->bEndpointAddress;
}
else
{
if (!endpoint_out)
endpoint_out = endpoint->bEndpointAddress;
}
}
}
}
}
}
//释放配置描述符
libusb_free_config_descriptor(conf_desc);
//卸载驱动内核
libusb_set_auto_detach_kernel_driver(handle, 1);
//为指定的设备申请接口
res=libusb_claim_interface(handle, 0);
if(res < 0)
return draw_ERROR;
return draw_OK;
}
int usb_Close(void)
{
libusb_exit(NULL);
return draw_OK;
}
//function-1
int draw_ClearScreen(unsigned int Color)
{
int res;
int size=0;
data_buf[1] = 0x01;
data_buf[2] = 0x01;
data_buf[3] = (Color>>24)&0xff;
data_buf[4] = (Color>>16)&0xff;
data_buf[5] = (Color>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//function-2
int draw_Point(short x, short y, unsigned int Color)
{
int res;
int size=0;
data_buf[1] = 0x02;
data_buf[2] = 0x03;
data_buf[3] = (x>>8)&0xff;
data_buf[4] = x&0xff;
data_buf[5] = 0x11;
data_buf[6] = (y>>8)&0xff;
data_buf[7] = y&0xff;
data_buf[8] = 0x11;
data_buf[9] = (Color>>24)&0xff;
data_buf[10] = (Color>>16)&0xff;
data_buf[11] = (Color>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//-3
int draw_Line(short x1, short y1, short x2, short y2, unsigned int Color)
{
int res;
int size=0;
data_buf[1] = 0x03;
data_buf[2] = 0x05;
data_buf[3] = (x1>>8)&0xff;
data_buf[4] = x1&0xff;
data_buf[5] = 0x11;
data_buf[6] = (y1>>8)&0xff;
data_buf[7] = y1&0xff;
data_buf[8] = 0x11;
data_buf[9] = (x2>>8)&0xff;
data_buf[10] = x2&0xff;
data_buf[11] = 0x11;
data_buf[12] = (y2>>8)&0xff;
data_buf[13] = y2&0xff;
data_buf[14] = 0x11;
data_buf[15] = (Color>>24)&0xff;
data_buf[16] = (Color>>16)&0xff;
data_buf[17] = (Color>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//-4
int draw_Ellipse(char flag, short x, short y, short w, short h, unsigned int Color, unsigned int FillColor)
{
int res;
int size=0;
data_buf[1] = 0x04;
data_buf[2] = 0x07;
data_buf[3] = flag;
data_buf[4] = 0x11;
data_buf[5] = (x>>8)&0xff;
data_buf[6] = x&0xff;
data_buf[7] = 0x11;
data_buf[8] = (y>>8)&0xff;
data_buf[9] = y&0xff;
data_buf[10] = 0x11;
data_buf[11] = (w>>8)&0xff;
data_buf[12] = w&0xff;
data_buf[13] = 0x11;
data_buf[14] = (h>>8)&0xff;
data_buf[15] = h&0xff;
data_buf[16] = 0x11;
data_buf[17] = (Color>>24)&0xff;
data_buf[18] = (Color>>16)&0xff;
data_buf[19] = (Color>>8)&0xff;
data_buf[20] = 0x11;
data_buf[21] = (FillColor>>24)&0xff;
data_buf[22] = (FillColor>>16)&0xff;
data_buf[23] = (FillColor>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//-5
int draw_Rectangle(char flag, short x, short y, short w, short h, unsigned int Color, unsigned int FillColor)
{
int res;
int size=0;
data_buf[1] = 0x05;
data_buf[2] = 0x07;
data_buf[3] = flag;
data_buf[4] = 0x11;
data_buf[5] = (x>>8)&0xff;
data_buf[6] = x&0xff;
data_buf[7] = 0x11;
data_buf[8] = (y>>8)&0xff;
data_buf[9] = y&0xff;
data_buf[10] = 0x11;
data_buf[11] = (w>>8)&0xff;
data_buf[12] = w&0xff;
data_buf[13] = 0x11;
data_buf[14] = (h>>8)&0xff;
data_buf[15] = h&0xff;
data_buf[16] = 0x11;
data_buf[17] = (Color>>24)&0xff;
data_buf[18] = (Color>>16)&0xff;
data_buf[19] = (Color>>8)&0xff;
data_buf[20] = 0x11;
data_buf[21] = (FillColor>>24)&0xff;
data_buf[22] = (FillColor>>16)&0xff;
data_buf[23] = (FillColor>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//-6
int draw_Sector(char flag, short x, short y, short w, short h, float sr, float er, unsigned int Color, unsigned int FillColor)
{
int res;
int size=0;
int *data_temp;
data_buf[1] = 0x06;
data_buf[2] = 0x09;
data_buf[3] = flag;
data_buf[4] = 0x11;
data_buf[5] = (x>>8)&0xff;
data_buf[6] = x&0xff;
data_buf[7] = 0x11;
data_buf[8] = (y>>8)&0xff;
data_buf[9] = y&0xff;
data_buf[10] = 0x11;
data_buf[11] = (w>>8)&0xff;
data_buf[12] = w&0xff;
data_buf[13] = 0x11;
data_buf[14] = (h>>8)&0xff;
data_buf[15] = h&0xff;
data_buf[16] = 0x11;
data_temp = (int *)&sr;
data_buf[17] = (*data_temp>>24)&0xff;
data_buf[18] = (*data_temp>>16)&0xff;
data_buf[19] = (*data_temp>>8)&0xff;
data_buf[20] = *data_temp&0xff;
data_temp = (int *)&er;
data_buf[21] = (*data_temp>>24)&0xff;
data_buf[22] = (*data_temp>>16)&0xff;
data_buf[23] = (*data_temp>>8)&0xff;
data_buf[24] = *data_temp&0xff;
data_buf[25] = (Color>>24)&0xff;
data_buf[26] = (Color>>16)&0xff;
data_buf[27] = (Color>>8)&0xff;
data_buf[28] = (FillColor>>24)&0xff;
data_buf[29] = (FillColor>>16)&0xff;
data_buf[30] = (FillColor>>8)&0xff;
res = libusb_interrupt_transfer(handle, endpoint_out, data_buf, 32, &size, 10);
if (res >= 0)
return draw_OK;
else
return draw_ERROR;
}
//-7
int draw_Polygon(char flag, unsigned int Color, unsigned int FillColor, short PointNum, short* Point)
{
int res;
int size=0;
int i = 0;
int send_point = 0;
data_buf[1] = 0x07;
data_buf[2] = 0x05;
data_buf[3] = flag;
data_buf[4] = 0x11;
data_buf[5] = (Color
没有合适的资源?快使用搜索试试~ 我知道了~
QT图形视图框架(QGraphicsView)绘图并调用libusb通讯
共25个文件
o:6个
h:5个
cpp:4个
5星 · 超过95%的资源 需积分: 12 86 下载量 45 浏览量
2022-11-15
15:23:08
上传
评论 1
收藏 1.16MB RAR 举报
温馨提示
介绍 通过Qt的图形视图框架进行2D绘图并调用libusb进行通讯 软件架构 软件主要由两部分组成: 1、libusb的调用和使用; 2、qt图形视图框架的基本使用。 安装教程 使用QT打开工程文件; 修改.pro文件中的库路径; 设置kits,编译运行。 使用说明 主要介绍了libusb的设备打开,端口打开,以及中断方式传输数据; 主要介绍了Qt的视图框架QGraphicsView、QGraphicsScene和QGraphicsItems的基本使用; 利用QT的视图框架进行了基本图形的绘制,比如画点、画线、画矩形等。
资源推荐
资源详情
资源评论
收起资源包目录
qt_draw_usb.rar (25个子文件)
usb.c 16KB
libusb.h 74KB
Makefile.Debug 44KB
libusb-1.0.a 207KB
.qmake.stash 1015B
Makefile.Release 44KB
ui_mainwindow.h 12KB
main.cpp 183B
mainwindow.ui 10KB
debug
moc_usb_device.o 362KB
moc_mainwindow.cpp 10KB
moc_mainwindow.o 391KB
page_table.exe 1.84MB
moc_predefs.h 14KB
mainwindow.o 828KB
usb.o 38KB
main.o 574KB
usb_device.o 345KB
moc_usb_device.cpp 5KB
mainwindow.cpp 20KB
mainwindow.h 2KB
Makefile 28KB
usb.h 7KB
page_table.pro 1KB
page_table.pro.user 24KB
release
共 25 条
- 1
资源评论
- SeaNico2023-07-25这个文件的编写风格简洁明了,给出的例子也很实用,让我能够快速入门并成功应用到我的项目中。
- 赵小杏儿2023-07-25这个文件提供了一个对于使用QT图形视图框架绘图以及调用libusb通讯的很好的指南。
- 独角兽邹教授2023-07-25通过这个文件,我学会了如何在QT图形视图框架中进行绘图,并成功实现了与libusb的通讯。
- ai2023-07-25通过阅读这个文件,我不仅了解了QT图形视图框架的绘图功能,还学到了一些有关libusb通讯的知识,对我提升项目的效率有很大帮助。
- 华亿2023-07-25这个文件详细地介绍了如何使用QT图形视图框架进行绘图,并给出了一些关于libusb通讯的实用技巧。
fanxinliuchen
- 粉丝: 6
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功