-
Hi, I'm trying to process output reports sent by the host to the device (esp32s3). You can find my current code below. For some reason I can't get One way I've been sending reports to the device is using the hidapitester.exe tool: Does anyone know what I'm doing wrong? #include "USB.h"
#include "USBHID.h"
USBHID HID;
static const uint8_t report_descriptor[] = {
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
0x09, 0x01, // Usage (0x01)
0xA1, 0x01, // Collection (Application)
0x85, 0x02, // Report ID (2)
0x09, 0x02, // Usage (0x02)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x85, 0x01, // Report ID (1)
0x09, 0x03, // Usage (0x03)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
// 36 bytes
};
uint8_t press_count = 0;
bool report_toggle = false;
class CustomHIDDevice : public USBHIDDevice {
public:
CustomHIDDevice(void) {
static bool initialized = false;
if (!initialized) {
initialized = true;
HID.addDevice(this, sizeof(report_descriptor));
}
}
void begin(void) {
HID.begin();
}
uint16_t _onGetDescriptor(uint8_t *buffer) {
memcpy(buffer, report_descriptor, sizeof(report_descriptor));
return sizeof(report_descriptor);
}
void _onOutput(uint8_t report_id, const uint8_t *buffer, uint16_t len){
report_toggle = !report_toggle;
}
bool send(uint8_t *value) {
return HID.SendReport(2, value, 1);
}
};
CustomHIDDevice Device;
const int buttonPin = 0;
int previousButtonState = HIGH;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
Device.begin();
USB.begin();
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (HID.ready() && buttonState != previousButtonState) {
previousButtonState = buttonState;
press_count++;
Device.send(&press_count);
delay(100);
}
digitalWrite(LED_BUILTIN, report_toggle);
}
|
Beta Was this translation helpful? Give feedback.
Answered by
me-no-dev
Oct 24, 2024
Replies: 1 comment 2 replies
-
This has recently been fixed. What version are you on? |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ikkentim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has recently been fixed. What version are you on?