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) {
57 Notify(PSTR(
"\r\nPS3USB Init"), 0x80);
62 Notify(PSTR(
"\r\nAddress in use"), 0x80);
72 Notify(PSTR(
"\r\nAddress not found"), 0x80);
79 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
104 goto FailUnknownDevice;
121 #ifdef DEBUG_USB_HOST
122 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
123 D_PrintHex<uint8_t > (rcode, 0x80);
128 Notify(PSTR(
"\r\nAddr: "), 0x80);
129 D_PrintHex<uint8_t > (
bAddress, 0x80);
145 goto FailSetDevTblEntry;
168 goto FailSetDevTblEntry;
174 goto FailSetConfDescr;
178 #ifdef DEBUG_USB_HOST
179 Notify(PSTR(
"\r\nDualshock 3 Controller Connected"), 0x80);
183 #ifdef DEBUG_USB_HOST
184 Notify(PSTR(
"\r\nNavigation Controller Connected"), 0x80);
194 for (uint8_t i = 6; i < 10; i++)
197 #ifdef DEBUG_USB_HOST
198 Notify(PSTR(
"\r\nMotion Controller Connected"), 0x80);
203 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) {
209 #ifdef DEBUG_USB_HOST
210 Notify(PSTR(
"\r\nBluetooth Address was set to: "), 0x80);
211 for (int8_t i = 5; i > 0; i--) {
212 D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
215 D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
221 Notify(PSTR(
"\r\n"), 0x80);
227 #ifdef DEBUG_USB_HOST
232 #ifdef DEBUG_USB_HOST
238 #ifdef DEBUG_USB_HOST
243 #ifdef DEBUG_USB_HOST
249 #ifdef DEBUG_USB_HOST
250 Notify(PSTR(
"\r\nPS3 Init Failed, error code: "), 0x80);
275 if (millis() - timer > 100) {
282 if (millis() - timer > 4000)
291 void PS3USB::readReport() {
295 ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
300 if (ButtonState != OldButtonState) {
301 ButtonClickState = ButtonState & ~OldButtonState;
302 OldButtonState = ButtonState;
306 void PS3USB::printReport() {
311 D_PrintHex<uint8_t > (readBuf[i], 0x80);
314 Notify(PSTR(
"\r\n"), 0x80);
319 return (ButtonState & pgm_read_dword(&
BUTTONS[(uint8_t)b]));
323 uint32_t button = pgm_read_dword(&
BUTTONS[(uint8_t)b]);
324 bool click = (ButtonClickState & button);
325 ButtonClickState &= ~button;
332 return (uint8_t)(readBuf[(pgm_read_byte(&
ANALOGBUTTONS[(uint8_t)a])) - 9]);
338 return (uint8_t)(readBuf[((uint8_t)a + 6)]);
344 return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
354 const double zeroG = 511.5;
363 double angle = (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
366 double angle = (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
376 if (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff))
383 char statusOutput[100];
385 strcpy(statusOutput,
"ConnectionStatus: ");
389 else strcat(statusOutput,
"Error");
392 strcat(statusOutput,
" - PowerRating: ");
401 else strcat(statusOutput,
"Error");
403 strcat(statusOutput,
" - WirelessStatus: ");
406 else if (
getStatus(
Cable)) strcat(statusOutput,
"Cable - Rumble is off");
409 else strcat(statusOutput,
"Error");
417 void PS3USB::PS3_Command(uint8_t* data, uint16_t nbytes) {
419 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
426 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
435 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
439 if ((mode & 0x30) > 0x00) {
440 uint8_t power[2] = {0xff, 0x00};
449 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
450 writeBuf[1] = rightDuration;
451 writeBuf[2] = rightPower;
452 writeBuf[3] = leftDuration;
453 writeBuf[4] = leftPower;
454 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
458 writeBuf[9] = value << 1;
459 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
463 writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1));
464 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
468 writeBuf[9] |= (uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1);
469 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
473 writeBuf[9] ^= (uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1);
474 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
482 for (uint8_t i = 0; i < 6; i++)
483 buf[i + 2] = BDADDR[5 - i];
486 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
489 void PS3USB::enable_sixaxis() {
497 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
501 void PS3USB::Move_Command(uint8_t* data, uint16_t nbytes) {
515 moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
519 #ifdef DEBUG_USB_HOST
520 if (rumble < 64 && rumble != 0)
521 Notify(PSTR(
"\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
524 writeBuf[6] = rumble;
538 for (uint8_t i = 0; i < 6; i++)
539 buf[i + 1] = BDADDR[i];
542 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
545 void PS3USB::onInit() {