add hid stylus pen device.

this works with android, for bypassing that absmouse does not support android.
note that, to hide cursor on android for every touch signal, find cursor option in android settings menu.

references:
1. https://stackoverflow.com/questions/28536602/hid-digitizer-descriptor-doesnt-perform-well-with-landscape-orientation
2. https://github.com/jonathanedgecombe/absmouse/blob/master/src/AbsMouse.cpp
This commit is contained in:
Jay
2024-12-23 22:03:37 +09:00
parent 7c1afa837a
commit 15b1623aa3
6 changed files with 121 additions and 1 deletions

View File

@@ -197,11 +197,43 @@ static void send_hid_report(uint8_t report_id, uint32_t btn)
}
}
break;
default: break;
}
}
/* use this to send stylus touch signal through USB. */
static void send_stylus_touch(uint16_t x, uint16_t y, bool state)
{
// skip if hid is not ready yet
if ( !tud_hid_ready() ) return;
static bool has_stylus_pen = false;
hid_stylus_report_t report =
{
.attr = 0,
.x = 0,
.y = 0
};
report.x = x;
report.y = y;
if (state)
{
report.attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE;
tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
has_stylus_pen = true;
}else
{
report.attr = 0;
if (has_stylus_pen) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
has_stylus_pen = false;
}
}
// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
// tud_hid_report_complete_cb() is used to send the next report after previous one is complete
void hid_task(void)

View File

@@ -79,6 +79,7 @@ uint8_t const desc_hid_report[] =
{
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )),
TUD_HID_REPORT_DESC_STYLUS_PEN( HID_REPORT_ID(REPORT_ID_STYLUS_PEN )),
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
};

View File

@@ -29,6 +29,7 @@ enum
{
REPORT_ID_KEYBOARD = 1,
REPORT_ID_MOUSE,
REPORT_ID_STYLUS_PEN,
REPORT_ID_CONSUMER_CONTROL,
REPORT_ID_GAMEPAD,
REPORT_ID_COUNT