diff options
| author | Aaditya Dhruv <[email protected]> | 2025-11-27 00:40:38 -0600 |
|---|---|---|
| committer | Aaditya Dhruv <[email protected]> | 2025-11-27 00:40:38 -0600 |
| commit | 06d6d8ddf8e76992383e925410b2adc55406e83b (patch) | |
| tree | 20d532d731d0d31f4ca4cff29eebb0106da2058e | |
| parent | fdff8f979b0ebdf00442befbc0c9706fa62040a3 (diff) | |
Add IR detection parsing
| -rw-r--r-- | starbit.c | 75 | ||||
| -rw-r--r-- | startbit.h | 2 |
2 files changed, 71 insertions, 6 deletions
@@ -1,3 +1,4 @@ +#include "linux/delay.h" #include "linux/input-event-codes.h" #include "linux/input.h" #include "linux/kern_levels.h" @@ -10,6 +11,8 @@ #include <linux/hid.h> #include "startbit.h" +#define IR_SLEEP 80 + struct wiimouse_dev { struct hid_device* hdev; struct input_dev* in_dev; @@ -22,6 +25,57 @@ static const struct hid_device_id wiimouse_ids[] = { }; +static int wiimote_ir_init(struct hid_device* hdev) { + + int ret = 0; + __u8 enable_ir1[2] = { HID_REPORT_ID_WIIMOTE_IR1_ENABLE, HID_REPORT_DATA_WIIMOTE_IR1_ENABLE }; + if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir1, 2)) < 0) { + printk(KERN_DEBUG "enable ir 1"); + return ret; + } + msleep(IR_SLEEP); + __u8 enable_ir2[2] = { HID_REPORT_ID_WIIMOTE_IR2_ENABLE, HID_REPORT_DATA_WIIMOTE_IR2_ENABLE }; + if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir2, 2)) < 0) { + printk(KERN_DEBUG "enable ir 2"); + return ret; + } + msleep(IR_SLEEP); + + __u8 eeprom_set_data[22] = { 0x16, 0x04, 0xb0, 0x00, 0x30, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + __u8 sensitive_1[22] = { 0x16, 0x04, 0xb0, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + __u8 sensitive_2[22] = { 0x16, 0x04, 0xb0, 0x00, 0x1a, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + __u8 mode[22] = { 0x16, 0x04, 0xb0, 0x00, 0x33, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + if ((ret = hid_hw_output_report(hdev, (__u8*)eeprom_set_data, 22)) < 0) { + printk(KERN_DEBUG "eeprom 1"); + return ret; + } + msleep(IR_SLEEP); + if ((ret = hid_hw_output_report(hdev, (__u8*)sensitive_1, 22)) < 0) { + printk(KERN_DEBUG "sensitive 1"); + return ret; + } + msleep(IR_SLEEP); + if ((ret = hid_hw_output_report(hdev, (__u8*)sensitive_2, 22)) < 0) { + printk(KERN_DEBUG "sensitive 2"); + return ret; + } + msleep(IR_SLEEP); + if ((ret = hid_hw_output_report(hdev, (__u8*)mode, 22)) < 0) { + printk(KERN_DEBUG "mode"); + return ret; + } + msleep(IR_SLEEP); + if ((ret = hid_hw_output_report(hdev, (__u8*)eeprom_set_data, 22)) < 0) { + printk(KERN_DEBUG "eeprom 2"); + return ret; + } + msleep(IR_SLEEP); + + ret = 0; + + return ret; +} + /* * wiimote_init @@ -36,11 +90,8 @@ static int wiimote_init(struct hid_device* hdev) { if ((ret = hid_hw_output_report(hdev, (__u8*)rumble, 2)) < 0) return ret; __u8 led_p1[2] = { HID_REPORT_ID_WIIMOTE_LED_ENABLE, HID_REPORT_DATA_WIIMOTE_LED_ENABLE_P1 }; if ((ret = hid_hw_output_report(hdev, (__u8*)led_p1, 2)) < 0) return ret; - - __u8 enable_ir1[2] = { HID_REPORT_ID_WIIMOTE_IR1_ENABLE, HID_REPORT_DATA_WIIMOTE_IR1_ENABLE }; - if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir1, 2)) < 0) return ret; - __u8 enable_ir2[2] = { HID_REPORT_ID_WIIMOTE_IR2_ENABLE, HID_REPORT_DATA_WIIMOTE_IR2_ENABLE }; - if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir2, 2)) < 0) return ret; + __u8 report_mode[3] = { 0x12, 0x00, 0x33 }; + if ((ret = hid_hw_output_report(hdev, (__u8*)report_mode, 3)) < 0) return ret; return ret; } @@ -60,6 +111,10 @@ static int wiimote_event(struct hid_device* hdev, struct hid_report* report, u8 input_report_key(in_dev, BTN_LEFT, 0); input_sync(in_dev); } + if (data[2] & 0x80) { + printk(KERN_DEBUG "HOME button was pressed, recalibrating IR\n"); + wiimote_ir_init(hdev); + } return 0; } @@ -95,6 +150,8 @@ static int wiimouse_probe(struct hid_device *hdev, const struct hid_device_id *i if (ret) return ret; wiimote_init(hdev); + printk(KERN_DEBUG "starting ir init"); + if ((ret = wiimote_ir_init(hdev)) != 0) return ret; hid_set_drvdata(hdev, wdev); /* Init done, device ready to use */ printk(KERN_DEBUG "Hello I'm a wiimouse!"); @@ -111,6 +168,13 @@ static void wiimote_report(struct hid_device *hdev, struct hid_report *report) { printk(KERN_DEBUG "Report ID: %02x\n", report->id); } +static int wiimote_mapping(struct hid_device *hdev, + struct hid_input *hidinput, struct hid_field *field, + struct hid_usage *usage, unsigned long **bit, int *max) { + //printk(KERN_DEBUG "ID: %s", hidinput->name); + return 0; +} + static struct hid_driver wiimouse_driver = { .name = "wiimouse-mouse", .id_table = wiimouse_ids, @@ -118,6 +182,7 @@ static struct hid_driver wiimouse_driver = { .raw_event = wiimote_event, .report = wiimote_report, .remove = wiimote_remove, + .input_mapping = wiimote_mapping }; module_hid_driver(wiimouse_driver); @@ -7,7 +7,7 @@ #define NINTENDO_WIIMOTE_PRODUCT_ID 0x0306 #define HID_REPORT_ID_WIIMOTE_RUMBLE_ENABLE 0x10 -#define HID_REPORT_DATA_WIIMOTE_RUMBLE_ENABLE 0x10 +#define HID_REPORT_DATA_WIIMOTE_RUMBLE_ENABLE 0x01 #define HID_REPORT_ID_WIIMOTE_LED_ENABLE 0x11 #define HID_REPORT_DATA_WIIMOTE_LED_ENABLE_P1 0x10 |
