Use real gamepad USB ids for UHID
Create the UHID device using the same values as the physical gamepad: - vendorId - productId - productVersion
This commit is contained in:
parent
afbaf59abb
commit
ac334496a1
@ -163,8 +163,11 @@ sc_control_msg_serialize(const struct sc_control_msg *msg, uint8_t *buf) {
|
|||||||
return 2;
|
return 2;
|
||||||
case SC_CONTROL_MSG_TYPE_UHID_CREATE:
|
case SC_CONTROL_MSG_TYPE_UHID_CREATE:
|
||||||
sc_write16be(&buf[1], msg->uhid_create.id);
|
sc_write16be(&buf[1], msg->uhid_create.id);
|
||||||
|
sc_write16be(&buf[3], msg->uhid_create.vendor_id);
|
||||||
|
sc_write16be(&buf[5], msg->uhid_create.product_id);
|
||||||
|
sc_write16be(&buf[7], msg->uhid_create.product_version);
|
||||||
|
|
||||||
size_t index = 3;
|
size_t index = 9;
|
||||||
index += write_string_tiny(&buf[index], msg->uhid_create.name, 127);
|
index += write_string_tiny(&buf[index], msg->uhid_create.name, 127);
|
||||||
|
|
||||||
sc_write16be(&buf[index], msg->uhid_create.report_desc_size);
|
sc_write16be(&buf[index], msg->uhid_create.report_desc_size);
|
||||||
@ -284,9 +287,14 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
|
|||||||
// Quote only if name is not null
|
// Quote only if name is not null
|
||||||
const char *name = msg->uhid_create.name;
|
const char *name = msg->uhid_create.name;
|
||||||
const char *quote = name ? "\"" : "";
|
const char *quote = name ? "\"" : "";
|
||||||
LOG_CMSG("UHID create [%" PRIu16 "] name=%s%s%s "
|
LOG_CMSG("UHID create [%" PRIu16 "] %04" PRIx16 ":%04" PRIx16
|
||||||
"report_desc_size=%" PRIu16, msg->uhid_create.id,
|
" (%" PRIu16 ") name=%s%s%s report_desc_size=%" PRIu16,
|
||||||
quote, name, quote, msg->uhid_create.report_desc_size);
|
msg->uhid_create.id,
|
||||||
|
msg->uhid_create.vendor_id,
|
||||||
|
msg->uhid_create.product_id,
|
||||||
|
msg->uhid_create.product_version,
|
||||||
|
quote, name, quote,
|
||||||
|
msg->uhid_create.report_desc_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SC_CONTROL_MSG_TYPE_UHID_INPUT: {
|
case SC_CONTROL_MSG_TYPE_UHID_INPUT: {
|
||||||
|
@ -98,6 +98,9 @@ struct sc_control_msg {
|
|||||||
} set_screen_power_mode;
|
} set_screen_power_mode;
|
||||||
struct {
|
struct {
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
uint16_t vendor_id;
|
||||||
|
uint16_t product_id;
|
||||||
|
uint16_t product_version;
|
||||||
const char *name; // pointer to static data
|
const char *name; // pointer to static data
|
||||||
uint16_t report_desc_size;
|
uint16_t report_desc_size;
|
||||||
const uint8_t *report_desc; // pointer to static data
|
const uint8_t *report_desc; // pointer to static data
|
||||||
|
@ -15,6 +15,9 @@ struct sc_hid_input {
|
|||||||
|
|
||||||
struct sc_hid_open {
|
struct sc_hid_open {
|
||||||
uint16_t hid_id;
|
uint16_t hid_id;
|
||||||
|
uint16_t vendor_id;
|
||||||
|
uint16_t product_id;
|
||||||
|
uint16_t product_version;
|
||||||
const char *name; // pointer to static memory
|
const char *name; // pointer to static memory
|
||||||
const uint8_t *report_desc; // pointer to static memory
|
const uint8_t *report_desc; // pointer to static memory
|
||||||
size_t report_desc_size;
|
size_t report_desc_size;
|
||||||
|
@ -233,7 +233,10 @@ sc_hid_gamepad_slot_get_id(size_t slot_idx) {
|
|||||||
bool
|
bool
|
||||||
sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,
|
sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,
|
||||||
struct sc_hid_open *hid_open,
|
struct sc_hid_open *hid_open,
|
||||||
uint32_t gamepad_id) {
|
uint32_t gamepad_id,
|
||||||
|
uint16_t vendor_id,
|
||||||
|
uint16_t product_id,
|
||||||
|
uint16_t product_version) {
|
||||||
assert(gamepad_id != SC_GAMEPAD_ID_INVALID);
|
assert(gamepad_id != SC_GAMEPAD_ID_INVALID);
|
||||||
ssize_t slot_idx = sc_hid_gamepad_slot_find(hid, SC_GAMEPAD_ID_INVALID);
|
ssize_t slot_idx = sc_hid_gamepad_slot_find(hid, SC_GAMEPAD_ID_INVALID);
|
||||||
if (slot_idx == -1) {
|
if (slot_idx == -1) {
|
||||||
@ -250,6 +253,9 @@ sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,
|
|||||||
|
|
||||||
uint16_t hid_id = sc_hid_gamepad_slot_get_id(slot_idx);
|
uint16_t hid_id = sc_hid_gamepad_slot_get_id(slot_idx);
|
||||||
hid_open->hid_id = hid_id;
|
hid_open->hid_id = hid_id;
|
||||||
|
hid_open->vendor_id = vendor_id;
|
||||||
|
hid_open->product_id = product_id;
|
||||||
|
hid_open->product_version = product_version;
|
||||||
hid_open->name = name;
|
hid_open->name = name;
|
||||||
hid_open->report_desc = SC_HID_GAMEPAD_REPORT_DESC;
|
hid_open->report_desc = SC_HID_GAMEPAD_REPORT_DESC;
|
||||||
hid_open->report_desc_size = sizeof(SC_HID_GAMEPAD_REPORT_DESC);
|
hid_open->report_desc_size = sizeof(SC_HID_GAMEPAD_REPORT_DESC);
|
||||||
|
@ -33,7 +33,10 @@ sc_hid_gamepad_init(struct sc_hid_gamepad *hid);
|
|||||||
bool
|
bool
|
||||||
sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,
|
sc_hid_gamepad_generate_open(struct sc_hid_gamepad *hid,
|
||||||
struct sc_hid_open *hid_open,
|
struct sc_hid_open *hid_open,
|
||||||
uint32_t gamepad_id);
|
uint32_t gamepad_id,
|
||||||
|
uint16_t vendor_id,
|
||||||
|
uint16_t product_id,
|
||||||
|
uint16_t product_version);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_hid_gamepad_generate_close(struct sc_hid_gamepad *hid,
|
sc_hid_gamepad_generate_close(struct sc_hid_gamepad *hid,
|
||||||
|
@ -335,6 +335,9 @@ sc_hid_keyboard_generate_input_from_mods(struct sc_hid_input *hid_input,
|
|||||||
|
|
||||||
void sc_hid_keyboard_generate_open(struct sc_hid_open *hid_open) {
|
void sc_hid_keyboard_generate_open(struct sc_hid_open *hid_open) {
|
||||||
hid_open->hid_id = SC_HID_ID_KEYBOARD;
|
hid_open->hid_id = SC_HID_ID_KEYBOARD;
|
||||||
|
hid_open->vendor_id = 0;
|
||||||
|
hid_open->product_id = 0;
|
||||||
|
hid_open->product_version = 0;
|
||||||
hid_open->name = NULL; // No name specified after "scrcpy"
|
hid_open->name = NULL; // No name specified after "scrcpy"
|
||||||
hid_open->report_desc = SC_HID_KEYBOARD_REPORT_DESC;
|
hid_open->report_desc = SC_HID_KEYBOARD_REPORT_DESC;
|
||||||
hid_open->report_desc_size = sizeof(SC_HID_KEYBOARD_REPORT_DESC);
|
hid_open->report_desc_size = sizeof(SC_HID_KEYBOARD_REPORT_DESC);
|
||||||
|
@ -190,6 +190,9 @@ sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
|
|||||||
|
|
||||||
void sc_hid_mouse_generate_open(struct sc_hid_open *hid_open) {
|
void sc_hid_mouse_generate_open(struct sc_hid_open *hid_open) {
|
||||||
hid_open->hid_id = SC_HID_ID_MOUSE;
|
hid_open->hid_id = SC_HID_ID_MOUSE;
|
||||||
|
hid_open->vendor_id = 0;
|
||||||
|
hid_open->product_id = 0;
|
||||||
|
hid_open->product_version = 0;
|
||||||
hid_open->name = NULL; // No name specified after "scrcpy"
|
hid_open->name = NULL; // No name specified after "scrcpy"
|
||||||
hid_open->report_desc = SC_HID_MOUSE_REPORT_DESC;
|
hid_open->report_desc = SC_HID_MOUSE_REPORT_DESC;
|
||||||
hid_open->report_desc_size = sizeof(SC_HID_MOUSE_REPORT_DESC);
|
hid_open->report_desc_size = sizeof(SC_HID_MOUSE_REPORT_DESC);
|
||||||
|
@ -425,6 +425,9 @@ enum sc_gamepad_device_event_type {
|
|||||||
struct sc_gamepad_device_event {
|
struct sc_gamepad_device_event {
|
||||||
enum sc_gamepad_device_event_type type;
|
enum sc_gamepad_device_event_type type;
|
||||||
uint32_t gamepad_id;
|
uint32_t gamepad_id;
|
||||||
|
uint16_t vendor_id;
|
||||||
|
uint16_t product_id;
|
||||||
|
uint16_t product_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sc_gamepad_button_event {
|
struct sc_gamepad_button_event {
|
||||||
|
@ -895,6 +895,10 @@ sc_input_manager_process_mouse_wheel(struct sc_input_manager *im,
|
|||||||
static void
|
static void
|
||||||
sc_input_manager_process_gamepad_device(struct sc_input_manager *im,
|
sc_input_manager_process_gamepad_device(struct sc_input_manager *im,
|
||||||
const SDL_ControllerDeviceEvent *event) {
|
const SDL_ControllerDeviceEvent *event) {
|
||||||
|
uint16_t vendor_id = 0;
|
||||||
|
uint16_t product_id = 0;
|
||||||
|
uint16_t product_version = 0;
|
||||||
|
|
||||||
SDL_JoystickID id;
|
SDL_JoystickID id;
|
||||||
if (event->type == SDL_CONTROLLERDEVICEADDED) {
|
if (event->type == SDL_CONTROLLERDEVICEADDED) {
|
||||||
SDL_GameController *gc = SDL_GameControllerOpen(event->which);
|
SDL_GameController *gc = SDL_GameControllerOpen(event->which);
|
||||||
@ -903,6 +907,10 @@ sc_input_manager_process_gamepad_device(struct sc_input_manager *im,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vendor_id = SDL_GameControllerGetVendor(gc);
|
||||||
|
product_id = SDL_GameControllerGetProduct(gc);
|
||||||
|
product_version = SDL_GameControllerGetProductVersion(gc);
|
||||||
|
|
||||||
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gc);
|
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gc);
|
||||||
if (!joystick) {
|
if (!joystick) {
|
||||||
LOGW("Could not get controller joystick");
|
LOGW("Could not get controller joystick");
|
||||||
@ -928,6 +936,9 @@ sc_input_manager_process_gamepad_device(struct sc_input_manager *im,
|
|||||||
struct sc_gamepad_device_event evt = {
|
struct sc_gamepad_device_event evt = {
|
||||||
.type = sc_gamepad_device_event_type_from_sdl_type(event->type),
|
.type = sc_gamepad_device_event_type_from_sdl_type(event->type),
|
||||||
.gamepad_id = id,
|
.gamepad_id = id,
|
||||||
|
.vendor_id = vendor_id,
|
||||||
|
.product_id = product_id,
|
||||||
|
.product_version = product_version,
|
||||||
};
|
};
|
||||||
im->gp->ops->process_gamepad_device(im->gp, &evt);
|
im->gp->ops->process_gamepad_device(im->gp, &evt);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,9 @@ sc_gamepad_uhid_send_open(struct sc_gamepad_uhid *gamepad,
|
|||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
||||||
msg.uhid_create.id = hid_open->hid_id;
|
msg.uhid_create.id = hid_open->hid_id;
|
||||||
|
msg.uhid_create.vendor_id = hid_open->vendor_id;
|
||||||
|
msg.uhid_create.product_id = hid_open->product_id;
|
||||||
|
msg.uhid_create.product_version = hid_open->product_version;
|
||||||
msg.uhid_create.name = hid_open->name;
|
msg.uhid_create.name = hid_open->name;
|
||||||
msg.uhid_create.report_desc = hid_open->report_desc;
|
msg.uhid_create.report_desc = hid_open->report_desc;
|
||||||
msg.uhid_create.report_desc_size = hid_open->report_desc_size;
|
msg.uhid_create.report_desc_size = hid_open->report_desc_size;
|
||||||
@ -59,7 +62,10 @@ sc_gamepad_processor_process_gamepad_device(struct sc_gamepad_processor *gp,
|
|||||||
if (event->type == SC_GAMEPAD_DEVICE_ADDED) {
|
if (event->type == SC_GAMEPAD_DEVICE_ADDED) {
|
||||||
struct sc_hid_open hid_open;
|
struct sc_hid_open hid_open;
|
||||||
if (!sc_hid_gamepad_generate_open(&gamepad->hid, &hid_open,
|
if (!sc_hid_gamepad_generate_open(&gamepad->hid, &hid_open,
|
||||||
event->gamepad_id)) {
|
event->gamepad_id,
|
||||||
|
event->vendor_id,
|
||||||
|
event->product_id,
|
||||||
|
event->product_version)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +141,9 @@ sc_keyboard_uhid_init(struct sc_keyboard_uhid *kb,
|
|||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
||||||
msg.uhid_create.id = SC_HID_ID_KEYBOARD;
|
msg.uhid_create.id = SC_HID_ID_KEYBOARD;
|
||||||
|
msg.uhid_create.vendor_id = hid_open.vendor_id;
|
||||||
|
msg.uhid_create.product_id = hid_open.product_id;
|
||||||
|
msg.uhid_create.product_version = hid_open.product_version;
|
||||||
msg.uhid_create.name = hid_open.name;
|
msg.uhid_create.name = hid_open.name;
|
||||||
msg.uhid_create.report_desc = hid_open.report_desc;
|
msg.uhid_create.report_desc = hid_open.report_desc;
|
||||||
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
|
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
|
||||||
|
@ -81,6 +81,9 @@ sc_mouse_uhid_init(struct sc_mouse_uhid *mouse,
|
|||||||
struct sc_control_msg msg;
|
struct sc_control_msg msg;
|
||||||
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
msg.type = SC_CONTROL_MSG_TYPE_UHID_CREATE;
|
||||||
msg.uhid_create.id = SC_HID_ID_MOUSE;
|
msg.uhid_create.id = SC_HID_ID_MOUSE;
|
||||||
|
msg.uhid_create.vendor_id = hid_open.vendor_id;
|
||||||
|
msg.uhid_create.product_id = hid_open.product_id;
|
||||||
|
msg.uhid_create.product_version = hid_open.product_version;
|
||||||
msg.uhid_create.name = hid_open.name;
|
msg.uhid_create.name = hid_open.name;
|
||||||
msg.uhid_create.report_desc = hid_open.report_desc;
|
msg.uhid_create.report_desc = hid_open.report_desc;
|
||||||
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
|
msg.uhid_create.report_desc_size = hid_open.report_desc_size;
|
||||||
|
@ -14,7 +14,10 @@ sc_gamepad_processor_process_gamepad_device(struct sc_gamepad_processor *gp,
|
|||||||
if (event->type == SC_GAMEPAD_DEVICE_ADDED) {
|
if (event->type == SC_GAMEPAD_DEVICE_ADDED) {
|
||||||
struct sc_hid_open hid_open;
|
struct sc_hid_open hid_open;
|
||||||
if (!sc_hid_gamepad_generate_open(&gamepad->hid, &hid_open,
|
if (!sc_hid_gamepad_generate_open(&gamepad->hid, &hid_open,
|
||||||
event->gamepad_id)) {
|
event->gamepad_id,
|
||||||
|
event->vendor_id,
|
||||||
|
event->product_id,
|
||||||
|
event->product_version)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +329,9 @@ static void test_serialize_uhid_create(void) {
|
|||||||
.type = SC_CONTROL_MSG_TYPE_UHID_CREATE,
|
.type = SC_CONTROL_MSG_TYPE_UHID_CREATE,
|
||||||
.uhid_create = {
|
.uhid_create = {
|
||||||
.id = 42,
|
.id = 42,
|
||||||
|
.vendor_id = 1234,
|
||||||
|
.product_id = 5678,
|
||||||
|
.product_version = 30,
|
||||||
.name = "ABC",
|
.name = "ABC",
|
||||||
.report_desc_size = sizeof(report_desc),
|
.report_desc_size = sizeof(report_desc),
|
||||||
.report_desc = report_desc,
|
.report_desc = report_desc,
|
||||||
@ -337,11 +340,14 @@ static void test_serialize_uhid_create(void) {
|
|||||||
|
|
||||||
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 20);
|
assert(size == 26);
|
||||||
|
|
||||||
const uint8_t expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_UHID_CREATE,
|
SC_CONTROL_MSG_TYPE_UHID_CREATE,
|
||||||
0, 42, // id
|
0, 42, // id
|
||||||
|
1234 >> 8, 1234 & 0xff, // vendor id
|
||||||
|
5678 >> 8, 5678 & 0xff, // product id
|
||||||
|
0, 30, // product version
|
||||||
3, // name size
|
3, // name size
|
||||||
65, 66, 67, // "ABC"
|
65, 66, 67, // "ABC"
|
||||||
0, 11, // report desc size
|
0, 11, // report desc size
|
||||||
|
@ -48,6 +48,9 @@ public final class ControlMessage {
|
|||||||
private long sequence;
|
private long sequence;
|
||||||
private int id;
|
private int id;
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
private int vendorId;
|
||||||
|
private int productId;
|
||||||
|
private int productVersion;
|
||||||
|
|
||||||
private ControlMessage() {
|
private ControlMessage() {
|
||||||
}
|
}
|
||||||
@ -131,12 +134,15 @@ public final class ControlMessage {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createUhidCreate(int id, String name, byte[] reportDesc) {
|
public static ControlMessage createUhidCreate(int id, String name, byte[] reportDesc, int vendorId, int productId, int productVersion) {
|
||||||
ControlMessage msg = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
msg.type = TYPE_UHID_CREATE;
|
msg.type = TYPE_UHID_CREATE;
|
||||||
msg.id = id;
|
msg.id = id;
|
||||||
msg.text = name;
|
msg.text = name;
|
||||||
msg.data = reportDesc;
|
msg.data = reportDesc;
|
||||||
|
msg.vendorId = vendorId;
|
||||||
|
msg.productId = productId;
|
||||||
|
msg.productVersion = productVersion;
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,4 +232,16 @@ public final class ControlMessage {
|
|||||||
public byte[] getData() {
|
public byte[] getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getVendorId() {
|
||||||
|
return vendorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProductId() {
|
||||||
|
return productId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProductVersion() {
|
||||||
|
return productVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,9 +139,12 @@ public class ControlMessageReader {
|
|||||||
|
|
||||||
private ControlMessage parseUhidCreate() throws IOException {
|
private ControlMessage parseUhidCreate() throws IOException {
|
||||||
int id = dis.readUnsignedShort();
|
int id = dis.readUnsignedShort();
|
||||||
|
int vendorId = dis.readUnsignedShort();
|
||||||
|
int productId = dis.readUnsignedShort();
|
||||||
|
int productVersion = dis.readUnsignedShort();
|
||||||
String name = parseString(1);
|
String name = parseString(1);
|
||||||
byte[] data = parseByteArray(2);
|
byte[] data = parseByteArray(2);
|
||||||
return ControlMessage.createUhidCreate(id, name, data);
|
return ControlMessage.createUhidCreate(id, name, data, vendorId, productId, productVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControlMessage parseUhidInput() throws IOException {
|
private ControlMessage parseUhidInput() throws IOException {
|
||||||
|
@ -210,7 +210,7 @@ public class Controller implements AsyncProcessor {
|
|||||||
device.rotateDevice();
|
device.rotateDevice();
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_UHID_CREATE:
|
case ControlMessage.TYPE_UHID_CREATE:
|
||||||
getUhidManager().open(msg.getId(), msg.getText(), msg.getData());
|
getUhidManager().open(msg.getId(), msg.getText(), msg.getData(), msg.getVendorId(), msg.getProductId(), msg.getProductVersion());
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_UHID_INPUT:
|
case ControlMessage.TYPE_UHID_INPUT:
|
||||||
getUhidManager().writeInput(msg.getId(), msg.getData());
|
getUhidManager().writeInput(msg.getId(), msg.getData());
|
||||||
|
@ -47,7 +47,7 @@ public final class UhidManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(int id, String name, byte[] reportDesc) throws IOException {
|
public void open(int id, String name, byte[] reportDesc, int vendorId, int productId, int productVersion) throws IOException {
|
||||||
try {
|
try {
|
||||||
FileDescriptor fd = Os.open("/dev/uhid", OsConstants.O_RDWR, 0);
|
FileDescriptor fd = Os.open("/dev/uhid", OsConstants.O_RDWR, 0);
|
||||||
try {
|
try {
|
||||||
@ -57,7 +57,7 @@ public final class UhidManager {
|
|||||||
close(old);
|
close(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] req = buildUhidCreate2Req(name, reportDesc);
|
byte[] req = buildUhidCreate2Req(name, reportDesc, vendorId, productId, productVersion);
|
||||||
Os.write(fd, req, 0, req.length);
|
Os.write(fd, req, 0, req.length);
|
||||||
|
|
||||||
registerUhidListener(id, fd);
|
registerUhidListener(id, fd);
|
||||||
@ -147,7 +147,7 @@ public final class UhidManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] buildUhidCreate2Req(String name, byte[] reportDesc) {
|
private static byte[] buildUhidCreate2Req(String name, byte[] reportDesc, int vendorId, int productId, int productVersion) {
|
||||||
/*
|
/*
|
||||||
* struct uhid_event {
|
* struct uhid_event {
|
||||||
* uint32_t type;
|
* uint32_t type;
|
||||||
@ -182,9 +182,9 @@ public final class UhidManager {
|
|||||||
|
|
||||||
buf.putShort((short) reportDesc.length);
|
buf.putShort((short) reportDesc.length);
|
||||||
buf.putShort(BUS_VIRTUAL);
|
buf.putShort(BUS_VIRTUAL);
|
||||||
buf.putInt(0); // vendor id
|
buf.putInt(vendorId); // vendor id
|
||||||
buf.putInt(0); // product id
|
buf.putInt(productId); // product id
|
||||||
buf.putInt(0); // version
|
buf.putInt(productVersion); // version
|
||||||
buf.putInt(0); // country;
|
buf.putInt(0); // country;
|
||||||
buf.put(reportDesc);
|
buf.put(reportDesc);
|
||||||
return buf.array();
|
return buf.array();
|
||||||
|
@ -324,6 +324,9 @@ public class ControlMessageReaderTest {
|
|||||||
DataOutputStream dos = new DataOutputStream(bos);
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
dos.writeByte(ControlMessage.TYPE_UHID_CREATE);
|
dos.writeByte(ControlMessage.TYPE_UHID_CREATE);
|
||||||
dos.writeShort(42); // id
|
dos.writeShort(42); // id
|
||||||
|
dos.writeShort(1234); // vendor id
|
||||||
|
dos.writeShort(5678); // product id
|
||||||
|
dos.writeShort(30); // product version
|
||||||
dos.writeByte(3); // name size
|
dos.writeByte(3); // name size
|
||||||
dos.write("ABC".getBytes(StandardCharsets.US_ASCII));
|
dos.write("ABC".getBytes(StandardCharsets.US_ASCII));
|
||||||
byte[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
byte[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||||
@ -337,6 +340,9 @@ public class ControlMessageReaderTest {
|
|||||||
ControlMessage event = reader.read();
|
ControlMessage event = reader.read();
|
||||||
Assert.assertEquals(ControlMessage.TYPE_UHID_CREATE, event.getType());
|
Assert.assertEquals(ControlMessage.TYPE_UHID_CREATE, event.getType());
|
||||||
Assert.assertEquals(42, event.getId());
|
Assert.assertEquals(42, event.getId());
|
||||||
|
Assert.assertEquals(1234, event.getVendorId());
|
||||||
|
Assert.assertEquals(5678, event.getProductId());
|
||||||
|
Assert.assertEquals(30, event.getProductVersion());
|
||||||
Assert.assertEquals("ABC", event.getText());
|
Assert.assertEquals("ABC", event.getText());
|
||||||
Assert.assertArrayEquals(data, event.getData());
|
Assert.assertArrayEquals(data, event.getData());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user