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);
124 PrintHex<uint8_t > (rcode, 0x80);
128 Notify(PSTR(
"\r\nAddr: "), 0x80);
129 PrintHex<uint8_t > (
bAddress, 0x80);
143 goto FailSetDevTblEntry;
166 goto FailSetDevTblEntry;
172 goto FailSetConfDescr;
176 #ifdef DEBUG_USB_HOST
177 Notify(PSTR(
"\r\nDualshock 3 Controller Connected"), 0x80);
181 #ifdef DEBUG_USB_HOST
182 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);
208 #ifdef DEBUG_USB_HOST
209 Notify(PSTR(
"\r\nBluetooth Address was set to: "), 0x80);
210 for (int8_t i = 5; i > 0; i--) {
211 PrintHex<uint8_t > (my_bdaddr[i], 0x80);
214 PrintHex<uint8_t > (my_bdaddr[0], 0x80);
218 Notify(PSTR(
"\r\n"), 0x80);
224 #ifdef DEBUG_USB_HOST
229 #ifdef DEBUG_USB_HOST
235 #ifdef DEBUG_USB_HOST
240 #ifdef DEBUG_USB_HOST
246 #ifdef DEBUG_USB_HOST
247 Notify(PSTR(
"\r\nPS3 Init Failed, error code: "), 0x80);
272 if (millis() - timer > 100) {
279 if (millis() - timer > 4000)
288 void PS3USB::readReport() {
292 ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
297 if (ButtonState != OldButtonState) {
298 ButtonClickState = ButtonState & ~OldButtonState;
299 OldButtonState = ButtonState;
303 void PS3USB::printReport() {
308 PrintHex<uint8_t > (readBuf[i], 0x80);
311 Notify(PSTR(
"\r\n"), 0x80);
316 return (ButtonState & pgm_read_dword(&
BUTTONS[(uint8_t)b]));
320 uint32_t button = pgm_read_dword(&
BUTTONS[(uint8_t)b]);
321 bool click = (ButtonClickState & button);
322 ButtonClickState &= ~button;
329 return (uint8_t)(readBuf[(pgm_read_byte(&
ANALOGBUTTONS[(uint8_t)a])) - 9]);
335 return (uint8_t)(readBuf[((uint8_t)a + 6)]);
341 return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
351 const double zeroG = 511.5;
360 double angle = (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
363 double angle = (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
373 if (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff))
380 char statusOutput[100];
382 strcpy(statusOutput,
"ConnectionStatus: ");
386 else strcat(statusOutput,
"Error");
389 strcat(statusOutput,
" - PowerRating: ");
398 else strcat(statusOutput,
"Error");
400 strcat(statusOutput,
" - WirelessStatus: ");
403 else if (
getStatus(
Cable)) strcat(statusOutput,
"Cable - Rumble is off");
406 else strcat(statusOutput,
"Error");
414 void PS3USB::PS3_Command(uint8_t* data, uint16_t nbytes) {
416 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
423 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
432 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
436 if ((mode & 0x30) > 0x00) {
437 uint8_t power[2] = {0xff, 0x00};
446 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
447 writeBuf[1] = rightDuration;
448 writeBuf[2] = rightPower;
449 writeBuf[3] = leftDuration;
450 writeBuf[4] = leftPower;
451 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
455 writeBuf[9] = value << 1;
456 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
460 writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1));
461 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
465 writeBuf[9] |= (uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1);
466 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
470 writeBuf[9] ^= (uint8_t)((pgm_read_byte(&
LEDS[(uint8_t)a]) & 0x0f) << 1);
471 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
479 for (uint8_t i = 0; i < 6; i++)
480 buf[i + 2] = BDADDR[5 - i];
483 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
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);
521 writeBuf[6] = rumble;
535 for (uint8_t i = 0; i < 6; i++)
536 buf[i + 1] = BDADDR[i];
539 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);