* More DS3 work

This commit is contained in:
Phillip Stephens 2015-05-21 17:35:46 -07:00
parent 2234d7f143
commit 4d644327cd
6 changed files with 35 additions and 19 deletions

View File

@ -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);

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "inputdev/CDeviceBase.hpp"
#include "inputdev/CDeviceToken.hpp"
#include "IHIDDevice.hpp"
#include <cstdarg>
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)

View File

@ -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);

View File

@ -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)
{

View File

@ -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);