23 PS3USB::PS3USB(
USB *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) :
38 my_bdaddr[5] = btadr5;
39 my_bdaddr[4] = btadr4;
40 my_bdaddr[3] = btadr3;
41 my_bdaddr[2] = btadr2;
42 my_bdaddr[1] = btadr1;
43 my_bdaddr[0] = btadr0;
46 uint8_t
PS3USB::Init(uint8_t parent, uint8_t port,
bool lowspeed) {
102 PID = udd->idProduct;
105 goto FailUnknownDevice;
122 #ifdef DEBUG_USB_HOST
124 D_PrintHex<uint8_t > (rcode, 0x80);
130 D_PrintHex<uint8_t > (
bAddress, 0x80);
146 goto FailSetDevTblEntry;
169 goto FailSetDevTblEntry;
175 goto FailSetConfDescr;
179 #ifdef DEBUG_USB_HOST
180 Notify(
PSTR(
"\r\nDualshock 3 Controller Connected"), 0x80);
184 #ifdef DEBUG_USB_HOST
185 Notify(
PSTR(
"\r\nNavigation Controller Connected"), 0x80);
195 for(uint8_t i = 6; i < 10; i++)
198 #ifdef DEBUG_USB_HOST
199 Notify(
PSTR(
"\r\nMotion Controller Connected"), 0x80);
204 if(my_bdaddr[0] != 0x00 || my_bdaddr[1] != 0x00 || my_bdaddr[2] != 0x00 || my_bdaddr[3] != 0x00 || my_bdaddr[4] != 0x00 || my_bdaddr[5] != 0x00) {
210 #ifdef DEBUG_USB_HOST
211 Notify(
PSTR(
"\r\nBluetooth Address was set to: "), 0x80);
212 for(int8_t i = 5; i > 0; i--) {
213 D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
216 D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
228 #ifdef DEBUG_USB_HOST
234 #ifdef DEBUG_USB_HOST
240 #ifdef DEBUG_USB_HOST
246 #ifdef DEBUG_USB_HOST
252 #ifdef DEBUG_USB_HOST
253 Notify(
PSTR(
"\r\nPS3 Init Failed, error code: "), 0x80);
278 if(millis() - timer > 100) {
285 if(millis() - timer > 4000) {
293 void PS3USB::readReport() {
294 ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
299 if(ButtonState != OldButtonState) {
300 ButtonClickState = ButtonState & ~OldButtonState;
301 OldButtonState = ButtonState;
305 void PS3USB::printReport() {
308 D_PrintHex<uint8_t > (readBuf[i], 0x80);
321 bool click = (ButtonClickState & button);
322 ButtonClickState &= ~button;
331 return (uint8_t)(readBuf[((uint8_t)a + 6)]);
335 return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
345 const double zeroG = 511.5;
354 return (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
356 return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
362 return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
366 char statusOutput[100];
399 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
401 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
408 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
417 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
421 if((mode & 0x30) > 0x00) {
422 uint8_t power[2] = {0xff, 0x00};
431 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
432 writeBuf[1] = rightDuration;
433 writeBuf[2] = rightPower;
434 writeBuf[3] = leftDuration;
435 writeBuf[4] = leftPower;
436 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
440 writeBuf[9] = value << 1;
441 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
446 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
454 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
460 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
469 for(uint8_t i = 0; i < 6; i++)
470 buf[i + 2] = bdaddr[5 - i];
473 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
480 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
482 for(uint8_t i = 0; i < 6; i++)
483 bdaddr[5 - i] = buf[i + 2];
486 void PS3USB::enable_sixaxis() {
494 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
498 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
512 moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
516 #ifdef DEBUG_USB_HOST
517 if(rumble < 64 && rumble != 0)
518 Notify(
PSTR(
"\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
520 writeBuf[6] = rumble;
534 for(uint8_t i = 0; i < 6; i++)
535 buf[i + 1] = bdaddr[i];
538 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
545 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
547 for(uint8_t i = 0; i < 6; i++)
548 bdaddr[i] = buf[10 + i];
554 for(uint8_t i = 0; i < 3; i++) {
556 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
558 for(byte j = 0; j < 49; j++)
559 data[49 * i + j] = buf[j];
563 void PS3USB::onInit() {
void getBdaddr(uint8_t *bdaddr)
#define pgm_read_dword(addr)
#define USB_ERROR_EPINFO_IS_NULL
#define strcpy_P(dest, src)
void setLedRaw(uint8_t value)
bool PS3NavigationConnected
void setBdaddr(uint8_t *bdaddr)
#define HID_REQUEST_SET_REPORT
bool getButtonPress(ButtonEnum b)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
#define USB_TRANSFER_TYPE_INTERRUPT
void getMoveBdaddr(uint8_t *bdaddr)
#define pgm_read_byte(addr)
#define NotifyFailGetDevDescr(...)
uint8_t getAnalogButton(ButtonEnum a)
uint16_t getSensor(SensorEnum a)
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
const uint32_t PS3_BUTTONS[]
virtual void FreeAddress(uint8_t addr)=0
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
void setLedToggle(LEDEnum a)
#define NotifyFailUnknownDevice(...)
#define USB_NAK_MAX_POWER
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
#define MOVE_REPORT_BUFFER_SIZE
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
#define HID_REQUEST_GET_REPORT
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
uint8_t getAnalogHat(AnalogHatEnum a)
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
const uint8_t PS3_ANALOG_BUTTONS[]
double getAngle(AngleEnum a)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
#define PS3NAVIGATION_PID
void moveSetRumble(uint8_t rumble)
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define PS3_MAX_ENDPOINTS
EpInfo epInfo[PS3_MAX_ENDPOINTS]
void setRumbleOn(RumbleEnum mode)
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define strcat_P(dest, src)
AddressPool & GetAddressPool()
void setMoveBdaddr(uint8_t *bdaddr)
#define PS3_REPORT_BUFFER_SIZE
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
PS3USB(USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
void getMoveCalibration(uint8_t *data)
bool getStatus(StatusEnum c)
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
#define NotifyFailSetDevTblEntry(...)
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
bool getButtonClick(ButtonEnum b)