Hopefully did not break other things... Find that the PS4 requires you to ask to connect versus some/most other devices will do the request... Also found issue without printing, where adding a delay(1) in a couple of places appears to help when Serial1 printing is not onmain
| BTHIDInput *next = NULL; | BTHIDInput *next = NULL; | ||||
| friend class BluetoothController; | friend class BluetoothController; | ||||
| protected: | protected: | ||||
| strbuf_t *btstrbuf; | |||||
| uint8_t needs_connect_to_device = false; | |||||
| Device_t *btdevice = NULL; | Device_t *btdevice = NULL; | ||||
| }; | }; | ||||
| // BUGBUG version to allow some of the controlled objects to call? | // BUGBUG version to allow some of the controlled objects to call? | ||||
| void sendL2CapCommand(uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00) { | void sendL2CapCommand(uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00) { | ||||
| //sendL2CapCommand(device_connection_handle_, data, nbytes, control_scid_ & 0xff, control_scid_ >> 8); | |||||
| USBHDBGSerial.printf("sendL2CapCommand: %x %d %x %x : control: %x\n", (uint32_t)data, nbytes, channelLow, channelHigh, control_scid_); | |||||
| sendL2CapCommand (device_connection_handle_, data, nbytes, channelLow, channelHigh); | sendL2CapCommand (device_connection_handle_, data, nbytes, channelLow, channelHigh); | ||||
| } | |||||
| } | |||||
| protected: | protected: | ||||
| virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len); | virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len); |
| #define print USBHost::print_ | #define print USBHost::print_ | ||||
| #define println USBHost::println_//#define DEBUG_BT | #define println USBHost::println_//#define DEBUG_BT | ||||
| //#define DEBUG_BT | //#define DEBUG_BT | ||||
| #define DEBUG_BT_VERBOSE | |||||
| //#define DEBUG_BT_VERBOSE | |||||
| #ifndef DEBUG_BT | #ifndef DEBUG_BT | ||||
| #undef DEBUG_BT_VERBOSE | #undef DEBUG_BT_VERBOSE | ||||
| if (do_pair_device_) { | if (do_pair_device_) { | ||||
| sendHCIAuthenticationRequested(); | sendHCIAuthenticationRequested(); | ||||
| pending_control_ = PC_AUTHENTICATION_REQUESTED; | pending_control_ = PC_AUTHENTICATION_REQUESTED; | ||||
| } else if (device_driver_ && device_driver_->needs_connect_to_device) { | |||||
| DBGPrintf(" Needs connect to device(PS4?)\n"); | |||||
| // The PS4 requires a connection request to it. | |||||
| delay(1); | |||||
| sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, control_dcid_, HID_CTRL_PSM); | |||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| switch (pending_control_tx_) { | switch (pending_control_tx_) { | ||||
| case STATE_TX_SEND_CONNECT_INT: | case STATE_TX_SEND_CONNECT_INT: | ||||
| delay(1); | |||||
| connection_rxid_++; | connection_rxid_++; | ||||
| sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, interrupt_dcid_, HID_INTR_PSM); | sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, interrupt_dcid_, HID_INTR_PSM); | ||||
| pending_control_tx_ = 0; | pending_control_tx_ = 0; | ||||
| // Set HID Boot mode | // Set HID Boot mode | ||||
| setHIDProtocol(HID_BOOT_PROTOCOL); // | setHIDProtocol(HID_BOOT_PROTOCOL); // | ||||
| //setHIDProtocol(HID_RPT_PROTOCOL); //HID_RPT_PROTOCOL | //setHIDProtocol(HID_RPT_PROTOCOL); //HID_RPT_PROTOCOL | ||||
| if (do_pair_device_) | |||||
| if (do_pair_device_) { | |||||
| pending_control_tx_ = STATE_TX_SEND_CONNECT_INT; | pending_control_tx_ = STATE_TX_SEND_CONNECT_INT; | ||||
| else | |||||
| } else if (device_driver_ && device_driver_->needs_connect_to_device) { | |||||
| DBGPrintf(" Needs connect to device INT(PS4?)\n"); | |||||
| // The PS4 requires a connection request to it. | |||||
| pending_control_tx_ = STATE_TX_SEND_CONNECT_INT; | |||||
| } else { | |||||
| pending_control_ = 0; | pending_control_ = 0; | ||||
| } | |||||
| } else if (scid == interrupt_dcid_) { | } else if (scid == interrupt_dcid_) { | ||||
| // Enable SCan to page mode | // Enable SCan to page mode | ||||
| sendHCIWriteScanEnable(2); | sendHCIWriteScanEnable(2); |
| // 9, 10 flash ON, OFF times in 100ths of sedond? 2.5 seconds = 255 | // 9, 10 flash ON, OFF times in 100ths of sedond? 2.5 seconds = 255 | ||||
| USBHDBGSerial.printf("Joystick update Rumble/LEDs\n"); | USBHDBGSerial.printf("Joystick update Rumble/LEDs\n"); | ||||
| btdriver_->sendL2CapCommand(packet, sizeof(packet), 0x42, 0x00); | |||||
| btdriver_->sendL2CapCommand(packet, sizeof(packet), 0x41, 0x00); | |||||
| return true; | return true; | ||||
| } | } | ||||
| axis[i] = data[i]; | axis[i] = data[i]; | ||||
| } | } | ||||
| mask <<= 1; // shift down the mask. | mask <<= 1; // shift down the mask. | ||||
| //USBHDBGSerial.printf("%02x ", axisPS4[i]); | |||||
| //USBHDBGSerial.printf("%02x ", axis[i]); | |||||
| } | } | ||||
| //USBHDBGSerial.printf("\n"); | //USBHDBGSerial.printf("\n"); | ||||
| joystickEvent = true; | joystickEvent = true; | ||||
| if (strncmp((const char *)remoteName, "Wireless Controller", 19) == 0) { | if (strncmp((const char *)remoteName, "Wireless Controller", 19) == 0) { | ||||
| USBHDBGSerial.printf(" JoystickController::remoteNameComplete %s - set to PS4\n", remoteName); | USBHDBGSerial.printf(" JoystickController::remoteNameComplete %s - set to PS4\n", remoteName); | ||||
| needs_connect_to_device = true; // We need to force this. | |||||
| joystickType = PS4; | joystickType = PS4; | ||||
| } | } | ||||
| btdevice = nullptr; // remember this way | btdevice = nullptr; // remember this way | ||||
| btdriver_ = nullptr; | btdriver_ = nullptr; | ||||
| connected_ = false; | connected_ = false; | ||||
| needs_connect_to_device = false; | |||||
| } | } | ||||