From ab8042f626cc6ac57de494aacb7aaaceaec10691 Mon Sep 17 00:00:00 2001 From: belek666 Date: Sat, 1 Jun 2019 11:55:46 +0200 Subject: [PATCH] minor changes to pademu --- modules/ds34bt/iop/ds34bt.c | 2 +- modules/ds34usb/iop/ds34usb.c | 23 ++++++++++++++--------- modules/pademu/Makefile | 2 +- modules/pademu/ds34bt.c | 23 ++++++++--------------- modules/pademu/ds34usb.c | 31 +++++++++++++++++-------------- modules/pademu/pademu.c | 4 ++-- src/gui.c | 20 ++++++++++---------- 7 files changed, 53 insertions(+), 52 deletions(-) diff --git a/modules/ds34bt/iop/ds34bt.c b/modules/ds34bt/iop/ds34bt.c index bf2ad8891..f25d470be 100644 --- a/modules/ds34bt/iop/ds34bt.c +++ b/modules/ds34bt/iop/ds34bt.c @@ -1158,7 +1158,7 @@ static void l2cap_event_cb(int resultCode, int bytes, void *arg) } } - UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE, l2cap_event_cb, arg); + UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE + 23, l2cap_event_cb, arg); SignalSema(bt_dev.hid_sema); } diff --git a/modules/ds34usb/iop/ds34usb.c b/modules/ds34usb/iop/ds34usb.c index e2acc5cf0..122fe6645 100644 --- a/modules/ds34usb/iop/ds34usb.c +++ b/modules/ds34usb/iop/ds34usb.c @@ -60,7 +60,7 @@ static u8 link_key[] = //for ds4 authorisation 0xC0, 0x7F, 0x12, 0xAA, 0xD9, 0x66, 0x3C, 0xCE }; -static u8 usb_buf[MAX_BUFFER_SIZE + 20] __attribute((aligned(4))) = {0}; +static u8 usb_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; int usb_probe(int devId); int usb_connect(int devId); @@ -239,7 +239,7 @@ static void usb_config_set(int result, int count, void *arg) DelayThread(10000); led[0] = led_patterns[pad][1]; led[3] = 0; - } else if(ds34pad[pad].type == DS4) { + } else if (ds34pad[pad].type == DS4) { led[0] = rgbled_patterns[pad][1][0]; led[1] = rgbled_patterns[pad][1][1]; led[2] = rgbled_patterns[pad][1][2]; @@ -247,6 +247,7 @@ static void usb_config_set(int result, int count, void *arg) } LEDRumble(led, 0, 0, pad); + DelayThread(20000); ds34pad[pad].status |= DS34USB_STATE_RUNNING; @@ -408,8 +409,7 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) usb_buf[9] = led[0] & 0x7F; //LED Conf - if (led[3]) //means charging, so blink - { + if (led[3]) { //means charging, so blink usb_buf[13] = 0x32; usb_buf[18] = 0x32; usb_buf[23] = 0x32; @@ -428,8 +428,7 @@ static int LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) usb_buf[7] = led[1]; //g usb_buf[8] = led[2]; //b - if (led[3]) //means charging, so blink - { + if (led[3]) { //means charging, so blink usb_buf[9] = 0x80; // Time to flash bright (255 = 2.5 seconds) usb_buf[10] = 0x80; // Time to flash dark (255 = 2.5 seconds) } @@ -502,7 +501,7 @@ void ds34usb_set_rumble(u8 lrum, u8 rrum, int port) { if (port >= MAX_PADS) return; - + Rumble(lrum, rrum, port); } @@ -566,8 +565,11 @@ int ds34usb_get_bdaddr(u8 *data, int port) for (i = 0; i < 6; i++) data[5 - i] = usb_buf[2 + i]; + + ret = 1; } else { DPRINTF("DS34USB: ds3usb_get_bdaddr usb transfer error %d\n", ret); + ret = 0; } } else { ret = UsbControlTransfer(ds34pad[port].controlEndp, REQ_USB_IN, USB_REQ_GET_REPORT, (HID_USB_GET_REPORT_FEATURE << 8) | 0x12, 0, 16, usb_buf, usb_cmd_cb, (void *)port); @@ -577,15 +579,18 @@ int ds34usb_get_bdaddr(u8 *data, int port) for (i = 0; i < 6; i++) data[5 - i] = usb_buf[15 - i]; + + ret = 1; } else { DPRINTF("DS34USB: ds3usb_get_bdaddr usb transfer error %d\n", ret); + ret = 0; } } ds34pad[port].update_rum = 1; SignalSema(ds34pad[port].sema); - return 1; + return ret; } void ds34usb_set_bdaddr(u8 *data, int port) @@ -697,7 +702,7 @@ void *rpc_sf(int cmd, void *data, int size) *(u8 *)data = ds34usb_get_status(*(u8 *)data); break; case DS34USB_GET_BDADDR: - *(u8 *)data = ds34usb_get_bdaddr((u8 *)data + 1, *(u8 *)data); + *(u8 *)data = ds34usb_get_bdaddr((u8 *)(data + 1), *(u8 *)data); break; case DS34USB_SET_BDADDR: ds34usb_set_bdaddr((u8 *)(data + 1), *(u8 *)data); diff --git a/modules/pademu/Makefile b/modules/pademu/Makefile index 386bad36a..fe080dcef 100644 --- a/modules/pademu/Makefile +++ b/modules/pademu/Makefile @@ -10,7 +10,7 @@ endif ifeq ($(USE_BT),1) IOP_BIN = bt_pademu.irx -IOP_CFLAGS += -DBT -DUSE_THREAD +IOP_CFLAGS += -DBT IOP_OBJS_DIR = obj.bt/ IOP_OBJS += ds34bt.o endif diff --git a/modules/pademu/ds34bt.c b/modules/pademu/ds34bt.c index 3713c9194..1a988700d 100644 --- a/modules/pademu/ds34bt.c +++ b/modules/pademu/ds34bt.c @@ -528,8 +528,7 @@ static void HCI_event_task(int result) break; case HCI_EVENT_COMMAND_STATUS: - if (hci_buf[2]) // show status on serial if not OK - { + if (hci_buf[2]) { // show status on serial if not OK DPRINTF("HCI Command Failed: \n"); DPRINTF("\t Status = 0x%02X \n", hci_buf[2]); DPRINTF("\t Command_OpCode(OGF) = 0x%02X \n", ((hci_buf[5] & 0xFC) >> 2)); @@ -539,8 +538,7 @@ static void HCI_event_task(int result) case HCI_EVENT_CONNECT_COMPLETE: DPRINTF("HCI event Connect Complete: \n"); - if (!hci_buf[2]) // check if connected OK - { + if (!hci_buf[2]) { // check if connected OK DPRINTF("\t Connection_Handle 0x%02X \n", hci_buf[3] | ((hci_buf[4] & 0x0F) << 8)); DPRINTF("\t Requested by BD_ADDR: \n\t"); for (i = 0; i < 6; i++) { @@ -645,8 +643,7 @@ static void HCI_event_task(int result) } DPRINTF("\n\t Link = 0x%02X \n", hci_buf[11]); DPRINTF("\t Class = 0x%02X 0x%02X 0x%02X \n", hci_buf[8], hci_buf[9], hci_buf[10]); - for (i = 0; i < MAX_PADS; i++) //find free slot - { + for (i = 0; i < MAX_PADS; i++) { //find free slot if (!pad_status_check(DS34BT_STATE_RUNNING, i) && ds34pad[i].enabled) { if (pad_status_check(DS34BT_STATE_CONNECTED, i)) { if (pad_status_check(DS34BT_STATE_DISCONNECTING, i)) //if we're waiting for hci disconnect event @@ -657,8 +654,7 @@ static void HCI_event_task(int result) break; } } - if (i >= MAX_PADS) //no free slot - { + if (i >= MAX_PADS) { //no free slot hci_reject_connection(hci_buf + 2); break; } @@ -667,8 +663,7 @@ static void HCI_event_task(int result) ds34pad[pad].isfake = 0; if (!disable_fake) { ds34pad[pad].isfake = 1; //fake ds3 - for (i = 0; i < sizeof(GenuineMacAddress) / 3; i++) //check if ds3 is genuine - { + for (i = 0; i < sizeof(GenuineMacAddress) / 3; i++) { //check if ds3 is genuine if (ds34pad[pad].bdaddr[5] == GenuineMacAddress[i][0] && ds34pad[pad].bdaddr[4] == GenuineMacAddress[i][1] && ds34pad[pad].bdaddr[3] == GenuineMacAddress[i][2]) { @@ -1102,7 +1097,7 @@ static void l2cap_event_cb(int resultCode, int bytes, void *arg) } } - UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE, l2cap_event_cb, arg); + UsbBulkTransfer(bt_dev.inEndp, l2cap_buf, MAX_BUFFER_SIZE + 23, l2cap_event_cb, arg); SignalSema(bt_dev.hid_sema); } @@ -1175,8 +1170,7 @@ static int hid_LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) led_buf[11] = led[0] & 0x7F; //LED Conf - if (led[3]) //means charging, so blink - { + if (led[3]) { //means charging, so blink led_buf[15] = 0x32; led_buf[20] = 0x32; led_buf[25] = 0x32; @@ -1199,8 +1193,7 @@ static int hid_LEDRumble(u8 *led, u8 lrum, u8 rrum, int pad) led_buf[10] = led[1]; //g led_buf[11] = led[2]; //b - if (led[3]) //means charging, so blink - { + if (led[3]) { //means charging, so blink led_buf[12] = 0x80; // Time to flash bright (255 = 2.5 seconds) led_buf[13] = 0x80; // Time to flash dark (255 = 2.5 seconds) } diff --git a/modules/pademu/ds34usb.c b/modules/pademu/ds34usb.c index 5f9975c98..42eef4d99 100644 --- a/modules/pademu/ds34usb.c +++ b/modules/pademu/ds34usb.c @@ -53,7 +53,7 @@ static u8 rgbled_patterns[][2][3] = {{0x00, 0x10, 0x10}, {0x00, 0x7F, 0x7F}}, // light cyan/cyan }; -static u8 usb_buf[MAX_BUFFER_SIZE + 20] __attribute((aligned(4))) = {0}; +static u8 usb_buf[MAX_BUFFER_SIZE + 32] __attribute((aligned(4))) = {0}; int usb_probe(int devId); int usb_connect(int devId); @@ -231,7 +231,7 @@ static void usb_config_set(int result, int count, void *arg) DelayThread(10000); led[0] = led_patterns[pad][1]; led[3] = 0; - } else if(ds34pad[pad].type == DS4) { + } else if (ds34pad[pad].type == DS4) { led[0] = rgbled_patterns[pad][1][0]; led[1] = rgbled_patterns[pad][1][1]; led[2] = rgbled_patterns[pad][1][2]; @@ -265,7 +265,10 @@ static void readReport(u8 *data, int pad) struct ds3report *report; report = (struct ds3report *)&data[2]; - + + if (report->RightStickX == 0 && report->RightStickY == 0) // ledrumble cmd causes null report sometime + return; + ds34pad[pad].data[0] = ~report->ButtonStateL; ds34pad[pad].data[1] = ~report->ButtonStateH; @@ -510,16 +513,6 @@ int ds34usb_get_data(u8 *dst, int size, int port) int ret = 0; WaitSema(ds34pad[port].sema); - - if (ds34pad[port].update_rum) { - ret = LEDRumble(ds34pad[port].oldled, ds34pad[port].lrum, ds34pad[port].rrum, port); - if (ret == USB_RC_OK) - TransferWait(ds34pad[port].cmd_sema); - else - DPRINTF("DS34USB: LEDRumble usb transfer error %d\n", ret); - - ds34pad[port].update_rum = 0; - } PollSema(ds34pad[port].sema); @@ -529,7 +522,7 @@ int ds34usb_get_data(u8 *dst, int size, int port) TransferWait(ds34pad[port].sema); if (!usb_resulCode) readReport(usb_buf, port); - + usb_resulCode = 1; } else { DPRINTF("DS34USB: ds34usb_get_data usb transfer error %d\n", ret); @@ -537,6 +530,16 @@ int ds34usb_get_data(u8 *dst, int size, int port) mips_memcpy(dst, ds34pad[port].data, size); ret = ds34pad[port].analog_btn & 1; + + if (ds34pad[port].update_rum) { + ret = LEDRumble(ds34pad[port].oldled, ds34pad[port].lrum, ds34pad[port].rrum, port); + if (ret == USB_RC_OK) + TransferWait(ds34pad[port].cmd_sema); + else + DPRINTF("DS34USB: LEDRumble usb transfer error %d\n", ret); + + ds34pad[port].update_rum = 0; + } SignalSema(ds34pad[port].sema); diff --git a/modules/pademu/pademu.c b/modules/pademu/pademu.c index 5a630fe75..033a894cf 100644 --- a/modules/pademu/pademu.c +++ b/modules/pademu/pademu.c @@ -93,9 +93,9 @@ extern struct irx_export_table _exp_pademu; int _start(int argc, char *argv[]) { - u8 pad_vibration = 0xFF; + u8 pad_vibration = 0x03; - pad_enable = 0xFF; + pad_enable = 0x03; if (argc > 1) { pad_enable = argv[1][0]; diff --git a/src/gui.c b/src/gui.c index de60631da..0471268ca 100644 --- a/src/gui.c +++ b/src/gui.c @@ -758,17 +758,17 @@ static int guiPadEmuUpdater(int modified) diaSetEnabled(diaPadEmuConfig, PADCFG_PADPORT, PadEmuEnable); diaSetEnabled(diaPadEmuConfig, PADCFG_PADEMU_VIB, PadEmuPort & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR, PadEmuMode & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PAIR, (PadEmuMode == 1) & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC_STR, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC_STR, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PAIR_STR, PadEmuMode & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_USBDG_MAC_STR, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PAD_MAC_STR, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PAIR_STR, (PadEmuMode == 1) & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_BTINFO, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, PadEmuMode & PadEmuEnable); - diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND_STR, PadEmuMode & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_BTINFO, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND, (PadEmuMode == 1) & PadEmuEnable); + diaSetVisible(diaPadEmuConfig, PADCFG_PADEMU_WORKAROUND_STR, (PadEmuMode == 1) & PadEmuEnable); if (modified) { if (PadEmuMtap) { @@ -796,7 +796,7 @@ static int guiPadEmuUpdater(int modified) PadEmuSettings |= PadEmuMode | (PadEmuPort << (8 + PadPort)) | (PadEmuVib << (16 + PadPort)) | (PadEmuMtap << 24) | ((PadEmuMtapPort - 1) << 25) | (PadEmuWorkaround << 26); PadEmuSettings &= (~(!PadEmuMode) & ~(!PadEmuPort << (8 + PadPort)) & ~(!PadEmuVib << (16 + PadPort)) & ~(!PadEmuMtap << 24) & ~(!(PadEmuMtapPort - 1) << 25) & ~(!PadEmuWorkaround << 26)); - if (PadEmuMode) { + if (PadEmuMode == 1) { if (ds34bt_get_status(0) & DS34BT_STATE_USB_CONFIGURED) { if (dg_discon) { dgmacset = 0;