USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PS3USB.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Lauszus, TKJ Electronics
14  Web : http://www.tkjelectronics.com
15  e-mail : kristianl@tkjelectronics.com
16  */
17 
18 #include "PS3USB.h"
19 // To enable serial debugging see "settings.h"
20 //#define EXTRADEBUG // Uncomment to get even more debugging data
21 //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers
22 
23 PS3USB::PS3USB(USB *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) :
24 pUsb(p), // pointer to USB class instance - mandatory
25 bAddress(0), // device address - mandatory
26 bPollEnable(false) // don't start polling before dongle is connected
27 {
28  for (uint8_t i = 0; i < PS3_MAX_ENDPOINTS; i++) {
29  epInfo[i].epAddr = 0;
30  epInfo[i].maxPktSize = (i) ? 0 : 8;
31  epInfo[i].epAttribs = 0;
33  }
34 
35  if (pUsb) // register in USB subsystem
36  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
37 
38  my_bdaddr[5] = btadr5; // Change to your dongle's Bluetooth address instead
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;
44 }
45 
46 uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
47  uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
48  uint8_t rcode;
49  UsbDevice *p = NULL;
50  EpInfo *oldep_ptr = NULL;
51  uint16_t PID;
52  uint16_t VID;
53 
54  // get memory address of USB device address pool
55  AddressPool &addrPool = pUsb->GetAddressPool();
56 #ifdef EXTRADEBUG
57  Notify(PSTR("\r\nPS3USB Init"), 0x80);
58 #endif
59  // check if address has already been assigned to an instance
60  if (bAddress) {
61 #ifdef DEBUG_USB_HOST
62  Notify(PSTR("\r\nAddress in use"), 0x80);
63 #endif
65  }
66 
67  // Get pointer to pseudo device with address 0 assigned
68  p = addrPool.GetUsbDevicePtr(0);
69 
70  if (!p) {
71 #ifdef DEBUG_USB_HOST
72  Notify(PSTR("\r\nAddress not found"), 0x80);
73 #endif
75  }
76 
77  if (!p->epinfo) {
78 #ifdef DEBUG_USB_HOST
79  Notify(PSTR("\r\nepinfo is null"), 0x80);
80 #endif
82  }
83 
84  // Save old pointer to EP_RECORD of address 0
85  oldep_ptr = p->epinfo;
86 
87  // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
88  p->epinfo = epInfo;
89 
90  p->lowspeed = lowspeed;
91 
92  // Get device descriptor
93  rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
94  // Restore p->epinfo
95  p->epinfo = oldep_ptr;
96 
97  if (rcode)
98  goto FailGetDevDescr;
99 
100  VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
101  PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
102 
103  if (VID != PS3_VID || (PID != PS3_PID && PID != PS3NAVIGATION_PID && PID != PS3MOVE_PID))
104  goto FailUnknownDevice;
105 
106  // Allocate new address according to device class
107  bAddress = addrPool.AllocAddress(parent, false, port);
108 
109  if (!bAddress)
111 
112  // Extract Max Packet Size from device descriptor
113  epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
114 
115  // Assign new address to the device
116  rcode = pUsb->setAddr(0, 0, bAddress);
117  if (rcode) {
118  p->lowspeed = false;
119  addrPool.FreeAddress(bAddress);
120  bAddress = 0;
121 #ifdef DEBUG_USB_HOST
122  Notify(PSTR("\r\nsetAddr: "), 0x80);
123  D_PrintHex<uint8_t > (rcode, 0x80);
124 #endif
125  return rcode;
126  }
127 #ifdef EXTRADEBUG
128  Notify(PSTR("\r\nAddr: "), 0x80);
129  D_PrintHex<uint8_t > (bAddress, 0x80);
130 #endif
131  delay(300); // Spec says you should wait at least 200ms
132 
133  p->lowspeed = false;
134 
135  //get pointer to assigned address record
136  p = addrPool.GetUsbDevicePtr(bAddress);
137  if (!p)
139 
140  p->lowspeed = lowspeed;
141 
142  // Assign epInfo to epinfo pointer - only EP0 is known
143  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
144  if (rcode)
145  goto FailSetDevTblEntry;
146 
147 
148  /* The application will work in reduced host mode, so we can save program and data
149  memory space. After verifying the PID and VID we will use known values for the
150  configuration values for device, interface, endpoints and HID for the PS3 Controllers */
151 
152  /* Initialize data structures for endpoints of device */
153  epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint
155  epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
159  epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint
161  epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
165 
166  rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
167  if (rcode)
168  goto FailSetDevTblEntry;
169 
170  delay(200); //Give time for address change
171 
172  rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1);
173  if (rcode)
174  goto FailSetConfDescr;
175 
176  if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
177  if (PID == PS3_PID) {
178 #ifdef DEBUG_USB_HOST
179  Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
180 #endif
181  PS3Connected = true;
182  } else { // must be a navigation controller
183 #ifdef DEBUG_USB_HOST
184  Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
185 #endif
186  PS3NavigationConnected = true;
187  }
188  enable_sixaxis(); // The PS3 controller needs a special command before it starts sending data
189 
190  // Needed for PS3 Dualshock and Navigation commands to work
191  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
192  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]);
193 
194  for (uint8_t i = 6; i < 10; i++)
195  readBuf[i] = 0x7F; // Set the analog joystick values to center position
196  } else { // must be a Motion controller
197 #ifdef DEBUG_USB_HOST
198  Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
199 #endif
200  PS3MoveConnected = true;
201  writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
202  }
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) {
204  if (PS3MoveConnected)
205  setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
206  else
207  setBdaddr(my_bdaddr); // Set internal Bluetooth address
208 
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);
213  Notify(PSTR(":"), 0x80);
214  }
215  D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
216 #endif
217  }
218  onInit();
219 
220  bPollEnable = true;
221  Notify(PSTR("\r\n"), 0x80);
222  timer = millis();
223  return 0; // successful configuration
224 
225  /* diagnostic messages */
226 FailGetDevDescr:
227 #ifdef DEBUG_USB_HOST
229  goto Fail;
230 #endif
231 FailSetDevTblEntry:
232 #ifdef DEBUG_USB_HOST
234  goto Fail;
235 #endif
236 
237 FailSetConfDescr:
238 #ifdef DEBUG_USB_HOST
240 #endif
241  goto Fail;
242 FailUnknownDevice:
243 #ifdef DEBUG_USB_HOST
244  NotifyFailUnknownDevice(VID, PID);
245 #endif
247 Fail:
248 
249 #ifdef DEBUG_USB_HOST
250  Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80);
251  NotifyFail(rcode);
252 #endif
253  Release();
254  return rcode;
255 }
256 
257 /* Performs a cleanup after failed Init() attempt */
258 uint8_t PS3USB::Release() {
259  PS3Connected = false;
260  PS3MoveConnected = false;
261  PS3NavigationConnected = false;
263  bAddress = 0;
264  bPollEnable = false;
265  return 0;
266 }
267 
268 uint8_t PS3USB::Poll() {
269  if (!bPollEnable)
270  return 0;
271 
273  uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
274  pUsb->inTransfer(bAddress, epInfo[ PS3_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
275  if (millis() - timer > 100) { // Loop 100ms before processing data
276  readReport();
277 #ifdef PRINTREPORT
278  printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
279 #endif
280  }
281  } else if (PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB
282  if (millis() - timer > 4000) { // Send at least every 4th second
283  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on
284  timer = millis();
285  }
286  }
287  return 0;
288 }
289 
290 void PS3USB::readReport() {
291  ButtonState = (uint32_t)(readBuf[2] | ((uint16_t)readBuf[3] << 8) | ((uint32_t)readBuf[4] << 16));
292 
293  //Notify(PSTR("\r\nButtonState", 0x80);
294  //PrintHex<uint32_t>(ButtonState, 0x80);
295 
296  if (ButtonState != OldButtonState) {
297  ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
298  OldButtonState = ButtonState;
299  }
300 }
301 
302 void PS3USB::printReport() { // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
303 #ifdef PRINTREPORT
304  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) {
305  D_PrintHex<uint8_t > (readBuf[i], 0x80);
306  Notify(PSTR(" "), 0x80);
307  }
308  Notify(PSTR("\r\n"), 0x80);
309 #endif
310 }
311 
313  return (ButtonState & pgm_read_dword(&BUTTONS[(uint8_t)b]));
314 }
315 
317  uint32_t button = pgm_read_dword(&BUTTONS[(uint8_t)b]);
318  bool click = (ButtonClickState & button);
319  ButtonClickState &= ~button; // Clear "click" event
320  return click;
321 }
322 
324  return (uint8_t)(readBuf[(pgm_read_byte(&ANALOGBUTTONS[(uint8_t)a])) - 9]);
325 }
326 
328  return (uint8_t)(readBuf[((uint8_t)a + 6)]);
329 }
330 
332  return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
333 }
334 
336  if (PS3Connected) {
337  double accXval;
338  double accYval;
339  double accZval;
340 
341  // Data for the Kionix KXPC4 used in the DualShock 3
342  const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
343  accXval = -((double)getSensor(aX) - zeroG);
344  accYval = -((double)getSensor(aY) - zeroG);
345  accZval = -((double)getSensor(aZ) - zeroG);
346 
347  // Convert to 360 degrees resolution
348  // atan2 outputs the value of -Ï€ to Ï€ (radians)
349  // We are then converting it to 0 to 2Ï€ and then to degrees
350  if (a == Pitch)
351  return (atan2(accYval, accZval) + PI) * RAD_TO_DEG;
352  else
353  return (atan2(accXval, accZval) + PI) * RAD_TO_DEG;
354  } else
355  return 0;
356 }
357 
359  return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
360 }
361 
364  char statusOutput[100];
365 
366  strcpy(statusOutput, "ConnectionStatus: ");
367 
368  if (getStatus(Plugged)) strcat(statusOutput, "Plugged");
369  else if (getStatus(Unplugged)) strcat(statusOutput, "Unplugged");
370  else strcat(statusOutput, "Error");
371 
372 
373  strcat(statusOutput, " - PowerRating: ");
374 
375  if (getStatus(Charging)) strcat(statusOutput, "Charging");
376  else if (getStatus(NotCharging)) strcat(statusOutput, "Not Charging");
377  else if (getStatus(Shutdown)) strcat(statusOutput, "Shutdown");
378  else if (getStatus(Dying)) strcat(statusOutput, "Dying");
379  else if (getStatus(Low)) strcat(statusOutput, "Low");
380  else if (getStatus(High)) strcat(statusOutput, "High");
381  else if (getStatus(Full)) strcat(statusOutput, "Full");
382  else strcat(statusOutput, "Error");
383 
384  strcat(statusOutput, " - WirelessStatus: ");
385 
386  if (getStatus(CableRumble)) strcat(statusOutput, "Cable - Rumble is on");
387  else if (getStatus(Cable)) strcat(statusOutput, "Cable - Rumble is off");
388  else if (getStatus(BluetoothRumble)) strcat(statusOutput, "Bluetooth - Rumble is on");
389  else if (getStatus(Bluetooth)) strcat(statusOutput, "Bluetooth - Rumble is off");
390  else strcat(statusOutput, "Error");
391 
392  return statusOutput;
393  } else
394  return "Error";
395 }
396 
397 /* Playstation Sixaxis Dualshock and Navigation Controller commands */
398 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
399  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x01), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
400  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
401 }
402 
404  for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
405  writeBuf[i] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // Reset buffer
406 
407  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
408 }
409 
411  writeBuf[1] = 0x00;
412  writeBuf[2] = 0x00; // Low mode off
413  writeBuf[3] = 0x00;
414  writeBuf[4] = 0x00; // High mode off
415 
416  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
417 }
418 
420  if ((mode & 0x30) > 0x00) {
421  uint8_t power[2] = {0xff, 0x00}; // Defaults to RumbleLow
422  if (mode == RumbleHigh) {
423  power[0] = 0x00;
424  power[1] = 0xff;
425  }
426  setRumbleOn(0xfe, power[0], 0xfe, power[1]);
427  }
428 }
429 
430 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
431  writeBuf[1] = rightDuration;
432  writeBuf[2] = rightPower;
433  writeBuf[3] = leftDuration;
434  writeBuf[4] = leftPower;
435  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
436 }
437 
438 void PS3USB::setLedRaw(uint8_t value) {
439  writeBuf[9] = value << 1;
440  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
441 }
442 
444  writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
445  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
446 }
447 
449  writeBuf[9] |= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
450  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
451 }
452 
454  writeBuf[9] ^= (uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1);
455  PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
456 }
457 
458 void PS3USB::setBdaddr(uint8_t *bdaddr) {
459  /* Set the internal Bluetooth address */
460  uint8_t buf[8];
461  buf[0] = 0x01;
462  buf[1] = 0x00;
463 
464  for (uint8_t i = 0; i < 6; i++)
465  buf[i + 2] = bdaddr[5 - i]; // Copy into buffer, has to be written reversed, so it is MSB first
466 
467  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
468  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
469 }
470 
471 void PS3USB::getBdaddr(uint8_t *bdaddr) {
472  uint8_t buf[8];
473 
474  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0xF5), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
475  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
476 
477  for (uint8_t i = 0; i < 6; i++)
478  bdaddr[5 - i] = buf[i + 2]; // Copy into buffer reversed, so it is LSB first
479 }
480 
481 void PS3USB::enable_sixaxis() { // Command used to enable the Dualshock 3 and Navigation controller to send data via USB
482  uint8_t cmd_buf[4];
483  cmd_buf[0] = 0x42; // Special PS3 Controller enable commands
484  cmd_buf[1] = 0x0c;
485  cmd_buf[2] = 0x00;
486  cmd_buf[3] = 0x00;
487 
488  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0xF4), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data)
489  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
490 }
491 
492 /* Playstation Move Controller commands */
493 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
494  pUsb->outTransfer(bAddress, epInfo[ PS3_OUTPUT_PIPE ].epAddr, nbytes, data);
495 }
496 
497 void PS3USB::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values
498  // Set the Bulb's values into the write buffer
499  writeBuf[2] = r;
500  writeBuf[3] = g;
501  writeBuf[4] = b;
502 
503  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
504 }
505 
506 void PS3USB::moveSetBulb(Colors color) { // Use this to set the Color using the predefined colors in "enums.h"
507  moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
508 }
509 
510 void PS3USB::moveSetRumble(uint8_t rumble) {
511 #ifdef DEBUG_USB_HOST
512  if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
513  Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
514 #endif
515  writeBuf[6] = rumble; // Set the rumble value into the write buffer
516 
517  Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE);
518 }
519 
520 void PS3USB::setMoveBdaddr(uint8_t *bdaddr) {
521  /* Set the internal Bluetooth address */
522  uint8_t buf[11];
523  buf[0] = 0x05;
524  buf[7] = 0x10;
525  buf[8] = 0x01;
526  buf[9] = 0x02;
527  buf[10] = 0x12;
528 
529  for (uint8_t i = 0; i < 6; i++)
530  buf[i + 1] = bdaddr[i];
531 
532  // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x05), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
533  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
534 }
535 
536 void PS3USB::getMoveBdaddr(uint8_t *bdaddr) {
537  uint8_t buf[16];
538 
539  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x04), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
540  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
541 
542  for (uint8_t i = 0; i < 6; i++)
543  bdaddr[i] = buf[10 + i];
544 }
545 
546 void PS3USB::getMoveCalibration(uint8_t *data) {
547  uint8_t buf[49];
548 
549  for (uint8_t i = 0; i < 3; i++) {
550  // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x10), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
551  pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
552 
553  for (byte j = 0; j < 49; j++)
554  data[49 * i + j] = buf[j];
555  }
556 }
557 
558 void PS3USB::onInit() {
559  if (pFuncOnInit)
560  pFuncOnInit(); // Call the user function
561  else {
562  if (PS3MoveConnected)
563  moveSetBulb(Red);
564  else // Dualshock 3 or Navigation controller
565  setLedOn(LED1);
566  }
567 }
uint8_t bmRcvToggle
Definition: address.h:41
uint16_t getSensor(Sensor a)
Definition: PS3USB.cpp:331
void getBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:471
Definition: PS3Enums.h:117
EpInfo * epinfo
Definition: address.h:76
bool lowspeed
Definition: address.h:79
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:67
uint8_t bmNakPower
Definition: address.h:42
void setLedRaw(uint8_t value)
Definition: PS3USB.cpp:438
bool PS3NavigationConnected
Definition: PS3USB.h:273
void setLedOff()
Definition: PS3USB.h:224
#define PS3_INPUT_PIPE
Definition: PS3USB.h:33
Definition: PS3Enums.h:192
Sensor
Definition: PS3Enums.h:141
#define PS3MOVE_PID
Definition: BTD.h:27
const uint8_t PS3_REPORT_BUFFER[]
Definition: PS3Enums.h:24
void setBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:458
virtual uint8_t Release()
Definition: PS3USB.cpp:258
#define PS3_OUTPUT_PIPE
Definition: PS3USB.h:32
#define NotifyFail(...)
Definition: message.h:55
bool PS3MoveConnected
Definition: PS3USB.h:271
Definition: PS3Enums.h:193
Definition: PS3Enums.h:194
const uint8_t LEDS[]
Definition: PS3Enums.h:43
const uint8_t ANALOGBUTTONS[]
Definition: PS3Enums.h:93
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:798
uint8_t getAnalogButton(Button a)
Definition: PS3USB.cpp:323
void getMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:536
#define PS3_VID
Definition: BTD.h:24
#define NotifyFailGetDevDescr(...)
Definition: message.h:50
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
void setRumbleOff()
Definition: PS3USB.cpp:410
#define EP_MAXPKTSIZE
Definition: PS3USB.h:25
bool PS3Connected
Definition: PS3USB.h:265
virtual void FreeAddress(uint8_t addr)=0
String getStatusString()
Definition: PS3USB.cpp:362
uint8_t epAttribs
Definition: address.h:37
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)
Definition: Usb.cpp:126
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
bool getStatus(Status c)
Definition: PS3USB.cpp:358
bool getButtonClick(Button b)
Definition: PS3USB.cpp:316
#define Notify(...)
Definition: message.h:44
#define PS3_CONTROL_PIPE
Definition: PS3USB.h:31
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:793
void setRumbleOn(Rumble mode)
Definition: PS3USB.cpp:419
uint8_t epAddr
Definition: address.h:33
Definition: PS3Enums.h:147
#define NotifyFailUnknownDevice(...)
Definition: message.h:54
Status
Definition: PS3Enums.h:182
Colors
Definition: PS3Enums.h:115
#define USB_NAK_MAX_POWER
Definition: address.h:27
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
Definition: PS3USB.cpp:497
void setLedToggle(LED a)
Definition: PS3USB.cpp:453
Rumble
Definition: PS3Enums.h:210
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: PS3USB.cpp:46
#define EP_INTERRUPT
Definition: PS3USB.h:28
Definition: address.h:32
#define MOVE_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:40
void setAllOff()
Definition: PS3USB.cpp:403
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:290
#define HID_REQUEST_SET_REPORT
Definition: BTD.h:39
#define HID_REQUEST_GET_REPORT
Definition: hid.h:66
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
uint8_t bmSndToggle
Definition: address.h:40
Definition: PS3Enums.h:143
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:69
Angle
Definition: PS3Enums.h:177
USB * pUsb
Definition: PS3USB.h:277
#define USB_NAK_NOWAIT
Definition: address.h:29
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:66
#define PS3_PID
Definition: BTD.h:25
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
Definition: Usb.cpp:206
#define PS3NAVIGATION_PID
Definition: BTD.h:26
void moveSetRumble(uint8_t rumble)
Definition: PS3USB.cpp:510
virtual uint8_t Poll()
Definition: PS3USB.cpp:268
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:61
#define PS3_MAX_ENDPOINTS
Definition: PS3USB.h:48
EpInfo epInfo[PS3_MAX_ENDPOINTS]
Definition: PS3USB.h:281
#define bmRCVTOG0
Definition: max3421e.h:185
#define bmREQ_HID_OUT
Definition: BTD.h:38
#define bmREQ_HID_IN
Definition: PS3USB.h:43
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:64
Button
#define bmSNDTOG0
Definition: max3421e.h:187
uint8_t maxPktSize
Definition: address.h:34
AddressPool & GetAddressPool()
Definition: UsbCore.h:168
uint8_t bAddress
Definition: PS3USB.h:279
void setMoveBdaddr(uint8_t *bdaddr)
Definition: PS3USB.cpp:520
#define PS3_REPORT_BUFFER_SIZE
Definition: PS3Enums.h:37
Definition: UsbCore.h:152
uint8_t getAnalogHat(AnalogHat a)
Definition: PS3USB.cpp:327
double getAngle(Angle a)
Definition: PS3USB.cpp:335
void setLedOn(LED a)
Definition: PS3USB.cpp:448
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:172
#define NotifyFailSetConfDescr(...)
Definition: message.h:53
bool getButtonPress(Button b)
Definition: PS3USB.cpp:312
AnalogHat
const uint32_t BUTTONS[]
Definition: PS3Enums.h:62
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)
Definition: PS3USB.cpp:23
void getMoveCalibration(uint8_t *data)
Definition: PS3USB.cpp:546
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:759
Definition: PS3Enums.h:145
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:51