diff --git a/include/inputdev/CDeviceBase.hpp b/include/inputdev/CDeviceBase.hpp index c468e22..fe81c69 100644 --- a/include/inputdev/CDeviceBase.hpp +++ b/include/inputdev/CDeviceBase.hpp @@ -24,7 +24,7 @@ public: virtual ~CDeviceBase(); void closeDevice(); virtual void deviceDisconnected()=0; - virtual void deviceError(const char* error) {fprintf(stderr, "%s\n", error);} + virtual void deviceError(const char* error, ...); /* Low-Level API */ bool sendUSBInterruptTransfer(uint8_t pipe, const uint8_t* data, size_t length); diff --git a/include/inputdev/CDualshockPad.hpp b/include/inputdev/CDualshockPad.hpp index 5a4b629..e4d4107 100644 --- a/include/inputdev/CDualshockPad.hpp +++ b/include/inputdev/CDualshockPad.hpp @@ -30,7 +30,9 @@ union SDualshockOutReport { uint8_t reportId; SDualshockRumble rumble; - uint8_t padding[4]; + uint8_t gyro1; + uint8_t gyro2; + uint8_t padding[2]; uint8_t leds; SDualshockLED led[4]; SDualshockLED reserved; @@ -40,16 +42,16 @@ union SDualshockOutReport enum EDualshockControllerButtons { - DS3_SELECT = 1<<0, - DS3_L3 = 1<<1, - DS3_R3 = 1<<2, - DS3_START = 1<<3, - DS3_UP = 1<<4, - DS3_RIGHT = 1<<5, - DS3_DOWN = 1<<6, - DS3_LEFT = 1<<7, - DS3_L2 = 1<<8, - DS3_R2 = 1<<9, + DS3_SELECT = 1<< 0, + DS3_L3 = 1<< 1, + DS3_R3 = 1<< 2, + DS3_START = 1<< 3, + DS3_UP = 1<< 4, + DS3_RIGHT = 1<< 5, + DS3_DOWN = 1<< 6, + DS3_LEFT = 1<< 7, + DS3_L2 = 1<< 8, + DS3_R2 = 1<< 9, DS3_L1 = 1<<10, DS3_R1 = 1<<11, DS3_TRIANGLE = 1<<12, @@ -102,6 +104,7 @@ struct SDualshockControllerState uint8_t m_reserved5[9]; uint16_t m_accelerometer[3]; uint16_t m_gyrometerZ; + // INTERNAL, set by libBoo, do not modify directly! float accPitch; float accYaw; float gyroZ; @@ -112,7 +115,7 @@ struct IDualshockControllerCallback { CDualshockController* ctrl = nullptr; virtual void controllerDisconnected() {} - virtual void controllerUpdate(const SDualshockControllerState& state) {} + virtual void controllerUpdate(const SDualshockControllerState&) {} }; class CDualshockController final : public CDeviceBase diff --git a/src/inputdev/CDeviceBase.cpp b/src/inputdev/CDeviceBase.cpp index 41c5394..c182bb3 100644 --- a/src/inputdev/CDeviceBase.cpp +++ b/src/inputdev/CDeviceBase.cpp @@ -1,6 +1,7 @@ #include "inputdev/CDeviceBase.hpp" #include "inputdev/CDeviceToken.hpp" #include "IHIDDevice.hpp" +#include namespace boo { @@ -33,6 +34,14 @@ void CDeviceBase::closeDevice() m_token->_deviceClose(); } +void CDeviceBase::deviceError(const char* error, ...) +{ + va_list vl; + va_start(vl, error); + vfprintf(stderr, error, vl); + va_end(vl); +} + bool CDeviceBase::sendUSBInterruptTransfer(uint8_t pipe, const uint8_t* data, size_t length) { if (m_hidDev) diff --git a/src/inputdev/CDualshockPad.cpp b/src/inputdev/CDualshockPad.cpp index 1ccbebf..8664c8f 100644 --- a/src/inputdev/CDualshockPad.cpp +++ b/src/inputdev/CDualshockPad.cpp @@ -29,8 +29,7 @@ void hexdump(void *ptr, int buflen) { namespace boo { static const uint8_t defaultReport[35] = { - 0x01, - 0xff, 0x00, 0xff, 0x00, + 0x01, 0xff, 0x00, 0xff, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0xff, 0x27, 0x10, 0x00, 0x32, 0xff, 0x27, 0x10, 0x00, 0x32, @@ -62,7 +61,11 @@ void CDualshockController::deviceDisconnected() void CDualshockController::initialCycle() { uint8_t setupCommand[4] = {0x42, 0x0c, 0x00, 0x00}; //Tells controller to start sending changes on in pipe - sendHIDReport(setupCommand, sizeof(setupCommand), 0x03F4); + if (!sendHIDReport(setupCommand, sizeof(setupCommand), 0x03F4)) + { + deviceError("Unable to send complete packet! Request size %x\n", sizeof(setupCommand)); + return; + } uint8_t btAddr[8]; receiveReport(btAddr, sizeof(btAddr), 0x03F5); for (int i = 0; i < 6; i++) @@ -113,9 +116,9 @@ void CDualshockController::transferCycle() } else { - if (state.m_reserved5[8] == 0xC0) + if (state.m_reserved5[8] & 0x80) m_rumbleRequest &= ~DS3_MOTOR_RIGHT; - if (state.m_reserved5[7] == 0x01) + if (state.m_reserved5[7] & 0x01) m_rumbleRequest &= ~DS3_MOTOR_LEFT; m_rumbleState = m_rumbleRequest; const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V); diff --git a/src/inputdev/CHIDListenerUdev.cpp b/src/inputdev/CHIDListenerUdev.cpp index 5a01ef1..5db05f5 100644 --- a/src/inputdev/CHIDListenerUdev.cpp +++ b/src/inputdev/CHIDListenerUdev.cpp @@ -47,7 +47,7 @@ class CHIDListenerUdev final : public IHIDListener int vid = 0, pid = 0; udev_list_entry* attrs = udev_device_get_properties_list_entry(device); -#if 0 +#if 1 udev_list_entry* att = NULL; udev_list_entry_foreach(att, attrs) { diff --git a/test/main.cpp b/test/main.cpp index ce3f7e3..b172a16 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -73,6 +73,7 @@ class CDualshockControllerCallback : public IDualshockControllerCallback /* else ctrl->stopRumble(DS3_MOTOR_RIGHT | DS3_MOTOR_LEFT);*/ + printf("CONTROLLER UPDATE %d %d\n", state.m_leftStick[0], state.m_leftStick[1]); printf(" %d %d\n", state.m_rightStick[0], state.m_rightStick[1]); printf(" %f %f %f\n", state.accPitch, state.accYaw, state.gyroZ);