From 9e9d47ce80e9dfbc3224e7788bab7d61060a655f Mon Sep 17 00:00:00 2001 From: ray <2954701669@qq.com> Date: Thu, 18 Apr 2024 07:04:09 +0000 Subject: [PATCH] update. --- usb_read_data.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/usb_read_data.cpp b/usb_read_data.cpp index d6432cd..f3fe0e1 100644 --- a/usb_read_data.cpp +++ b/usb_read_data.cpp @@ -60,7 +60,7 @@ int main() } // 打印usb设备信息 // print_devs(devs); - dev_handle = libusb_open_device_with_vid_pid(NULL, 0x2833, 0x0002); + dev_handle = libusb_open_device_with_vid_pid(NULL, 0x0483, 0x5750); if (dev_handle == NULL) { printf("Cannot open device\n"); @@ -94,20 +94,23 @@ int main() while (1) { - r = libusb_bulk_transfer(dev_handle, (0x01 | LIBUSB_ENDPOINT_IN), data, 64, &transferred, 1000); - if (r == 0 && actual == 64) // we read the 64 bytes successfully - printf("Read Successful\n"); - else + r = libusb_interrupt_transfer(dev_handle, (0x01 | LIBUSB_ENDPOINT_IN), data, 64, &transferred, 1000); + if (r == 0 && actual == 127){ + // 解析GeekIMU的磁力计信息 + int16_t mx = *(int16_t *)(data + 3); + int16_t my = *(int16_t *)(data + 5); + int16_t mz = *(int16_t *)(data + 7); + printf("mag:%d,%d,%d\n", mx, my, mz); + }else{ printf("Read Error\n"); - printf("%i,%i\n", r, actual); + } + + //printf("%i,%i\n", r, actual); + + - // 解析GeekIMU的磁力计信息 - int16_t mx = *(int16_t *)(data + 56); - int16_t my = *(int16_t *)(data + 58); - int16_t mz = *(int16_t *)(data + 60); - printf("mag:%d,%d,%d\n", mx, my, mz); // 睡眠延时100ms - usleep(1000 * 100); + usleep(1000 * 10); // 清屏 // printf("%s","\033[1H\033[2J");//clear display } @@ -125,4 +128,4 @@ int main() libusb_exit(NULL); return 0; -} \ No newline at end of file +}