@@ -199,8 +199,15 @@ void GamepadSearch() {
199199 } else if (cur_dev->product_id == SONY_DS4_USB || cur_dev->product_id == SONY_DS4_V2_USB || cur_dev->product_id == SONY_DS4_DONGLE) {
200200 CurGamepad.ControllerType = SONY_DUALSHOCK4;
201201 CurGamepad.USBConnection = true ;
202+
203+ // BT detection
204+ unsigned char buf[64 ];
205+ memset (buf, 0 , sizeof (buf));
206+ int bytesRead = hid_read_timeout (CurGamepad.HidHandle , buf, sizeof (buf), 100 );
207+ if (bytesRead > 0 && buf[0 ] == 0x11 )
208+ CurGamepad.USBConnection = false ;
202209
203- } else if (cur_dev->product_id == SONY_DS4_BT) {
210+ } else if (cur_dev->product_id == SONY_DS4_BT) { // ?
204211 CurGamepad.ControllerType = SONY_DUALSHOCK4;
205212 CurGamepad.USBConnection = false ;
206213 }
@@ -253,25 +260,23 @@ void GetBatteryInfo() {
253260 if (CurGamepad.USBConnection )
254261 CurGamepad.BatteryLevel = (buf[30 ] & DS_STATUS_BATTERY_CAPACITY) * 100 / DS4_USB_BATTERY_MAX;
255262 else
256- CurGamepad.BatteryLevel = (buf[31 ] & DS_STATUS_BATTERY_CAPACITY) * 100 / DS_BATTERY_MAX; // offset 1?
263+ CurGamepad.BatteryLevel = (buf[32 ] & DS_STATUS_BATTERY_CAPACITY) * 100 / DS_BATTERY_MAX;
257264 }
258265 if (CurGamepad.BatteryLevel > 100 ) CurGamepad.BatteryLevel = 100 ; // It looks like something is not right, once it gave out 125%
259266 }
260267}
261268
262269void ExternalPedalsDInputSearch () {
263- if (joyGetPosEx (JOYSTICKID1, &AppStatus.ExternalPedalsJoyInfo ) == JOYERR_NOERROR &&
264- joyGetDevCaps (JOYSTICKID1, &AppStatus.ExternalPedalsJoyCaps , sizeof (AppStatus.ExternalPedalsJoyCaps )) == JOYERR_NOERROR &&
265- AppStatus.ExternalPedalsJoyCaps .wNumButtons == 16 ) { // DualSense - 15, DigiJoy - 16
266- AppStatus.ExternalPedalsJoyIndex = JOYSTICKID1;
267- AppStatus.ExternalPedalsDInputConnected = true ;
268- } else if (joyGetPosEx (JOYSTICKID2, &AppStatus.ExternalPedalsJoyInfo ) == JOYERR_NOERROR &&
269- joyGetDevCaps (JOYSTICKID2, &AppStatus.ExternalPedalsJoyCaps , sizeof (AppStatus.ExternalPedalsJoyCaps )) == JOYERR_NOERROR &&
270- AppStatus.ExternalPedalsJoyCaps .wNumButtons == 16 ) {
271- AppStatus.ExternalPedalsJoyIndex = JOYSTICKID2;
272- AppStatus.ExternalPedalsDInputConnected = true ;
273- } else
274- AppStatus.ExternalPedalsDInputConnected = false ;
270+ ExternalPedalsConnected = false ;
271+ for (int JoyID = 0 ; JoyID < 4 ; ++JoyID) { // JOYSTICKID4 - 3
272+ if (joyGetPosEx (JoyID, &AppStatus.ExternalPedalsJoyInfo ) == JOYERR_NOERROR && // JoyID - JOYSTICKID1..4
273+ joyGetDevCaps (JoyID, &AppStatus.ExternalPedalsJoyCaps , sizeof (AppStatus.ExternalPedalsJoyCaps )) == JOYERR_NOERROR &&
274+ AppStatus.ExternalPedalsJoyCaps .wNumButtons == 16 ) { // DualSense - 15, DigiJoy - 16
275+ AppStatus.ExternalPedalsJoyIndex = JoyID;
276+ AppStatus.ExternalPedalsDInputConnected = true ;
277+ break ;
278+ }
279+ }
275280}
276281
277282void ExternalPedalsArduinoRead ()
@@ -520,7 +525,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
520525
521526int main (int argc, char **argv)
522527{
523- SetConsoleTitle (" DSAdvance 0.9.7 " );
528+ SetConsoleTitle (" DSAdvance 0.9.8 " );
524529
525530 WNDCLASS AppWndClass = {};
526531 AppWndClass.lpfnWndProc = WindowProc;
0 commit comments