USB-HID/UsbHidDevEx/main.cpp

35 lines
737 B
C++
Raw Normal View History

2024-04-21 14:05:38 +08:00
#include "hiddev.h"
#include <iostream>
#include <csignal>
bool running = true;
void signalHandler(int signal) {
running = false;
}
int main() {
signal(SIGINT, signalHandler);
HIDDev device;
if (!device.openDevice(0x2833, 0x0002)) {
std::cerr << "Unable to open device initially.\n";
}
while (running) {
unsigned char data[64];
int len = device.read(data, sizeof(data));
if (len > 0) {
std::cout << "Data read: ";
for (int i = 0; i < 5; i++) {
std::cout << std::hex << static_cast<int>(data[i]) << " ";
}
std::cout << std::dec << "\n";
}
}
device.closeDevice();
return 0;
}