From f0df357449d23a0e1c856cbb0b49b4b6764a2f28 Mon Sep 17 00:00:00 2001 From: whowechina Date: Sun, 16 Mar 2025 17:51:27 +0800 Subject: [PATCH] Edge-triggered HID report --- firmware/src/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/firmware/src/main.c b/firmware/src/main.c index 878d8ff..19ebc3c 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -93,7 +93,7 @@ static void core1_loop() struct __attribute__((packed)) { uint8_t buttons; uint8_t joy[6]; -} hid_report = {0}; +} hid_report, old_hid_report; static void hid_update() { @@ -107,7 +107,10 @@ static void hid_update() hid_report.joy[i] = spin_units(i); } if (tud_hid_ready()) { - tud_hid_n_report(0, REPORT_ID_JOYSTICK, &hid_report, sizeof(hid_report)); + if ((memcmp(&hid_report, &old_hid_report, sizeof(hid_report)) != 0) && + tud_hid_report(REPORT_ID_JOYSTICK, &hid_report, sizeof(hid_report))) { + old_hid_report = hid_report; + } } }