diff options
| author | Aaditya Dhruv <[email protected]> | 2025-11-23 18:51:46 -0600 |
|---|---|---|
| committer | Aaditya Dhruv <[email protected]> | 2025-11-23 18:51:46 -0600 |
| commit | fdff8f979b0ebdf00442befbc0c9706fa62040a3 (patch) | |
| tree | a4c2b8884220670b203fd6a0557fdbb2631556cc | |
| parent | f2e71b9fa6796022b85480ab9e57835ba9b64eda (diff) | |
Add input_dev support for basic BTN_LEFT clicking
| -rw-r--r-- | starbit.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -1,3 +1,4 @@ +#include "linux/input-event-codes.h" #include "linux/input.h" #include "linux/kern_levels.h" #include "linux/printk.h" @@ -48,9 +49,16 @@ static int wiimote_init(struct hid_device* hdev) { static int wiimote_event(struct hid_device* hdev, struct hid_report* report, u8 *data, int size) { printk(KERN_DEBUG "Report ID: %02x | Buttons: %02x %02x %02x\n", report->id, data[0], data[1], data[2]); + struct wiimouse_dev* wdev = hid_get_drvdata(hdev); + if (data[2] & 0x08) { printk(KERN_DEBUG "A button was pressed\n"); + struct input_dev* in_dev = wdev->in_dev; + input_report_key(in_dev, BTN_LEFT, 1); + input_sync(in_dev); + input_report_key(in_dev, BTN_LEFT, 0); + input_sync(in_dev); } return 0; } @@ -66,8 +74,19 @@ static int wiimouse_probe(struct hid_device *hdev, const struct hid_device_id *i if(in_dev == NULL) { return -1; } - - + wdev->in_dev = in_dev; + + in_dev->name = "Wiimouse"; + in_dev->id.vendor = NINTENDO_WIIMOTE_VENDOR_ID; + in_dev->id.product = NINTENDO_WIIMOTE_PRODUCT_ID; + in_dev->id.version = 0x0000; + set_bit(EV_KEY, in_dev->evbit); + set_bit(BTN_LEFT, in_dev->keybit); + ret = input_register_device(in_dev); + if (ret) { + input_free_device(in_dev); + return ret; + } printk(KERN_DEBUG "wiimouse-mouse: Starting parse"); /* Init hid device, setup input subsystem etc. */ ret = hid_parse(hdev); @@ -76,11 +95,17 @@ static int wiimouse_probe(struct hid_device *hdev, const struct hid_device_id *i if (ret) return ret; wiimote_init(hdev); + hid_set_drvdata(hdev, wdev); /* Init done, device ready to use */ printk(KERN_DEBUG "Hello I'm a wiimouse!"); return 0; } +static void wiimote_remove(struct hid_device* hdev) { + struct wiimouse_dev* wdev = hid_get_drvdata(hdev); + input_unregister_device(wdev->in_dev); +} + static void wiimote_report(struct hid_device *hdev, struct hid_report *report) { printk(KERN_DEBUG "Report ID: %02x\n", report->id); @@ -92,6 +117,7 @@ static struct hid_driver wiimouse_driver = { .probe = wiimouse_probe, .raw_event = wiimote_event, .report = wiimote_report, + .remove = wiimote_remove, }; module_hid_driver(wiimouse_driver); |
