23 PS3USB::PS3USB(
USB *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) :
39 my_bdaddr[5] = btadr5;
40 my_bdaddr[4] = btadr4;
41 my_bdaddr[3] = btadr3;
42 my_bdaddr[2] = btadr2;
43 my_bdaddr[1] = btadr1;
44 my_bdaddr[0] = btadr0;
47 uint8_t
PS3USB::Init(uint8_t parent, uint8_t port,
bool lowspeed) {
100 goto FailGetDevDescr;
103 PID = udd->idProduct;
106 goto FailUnknownDevice;
123 #ifdef DEBUG_USB_HOST
125 D_PrintHex<uint8_t > (rcode, 0x80);
131 D_PrintHex<uint8_t > (
bAddress, 0x80);
147 goto FailSetDevTblEntry;
170 goto FailSetDevTblEntry;
176 goto FailSetConfDescr;
180 #ifdef DEBUG_USB_HOST
181 Notify(
PSTR(
"\r\nDualshock 3 Controller Connected"), 0x80);
185 #ifdef DEBUG_USB_HOST
186 Notify(
PSTR(
"\r\nNavigation Controller Connected"), 0x80);
196 for(uint8_t i = 6; i < 10; i++)
199 #ifdef DEBUG_USB_HOST
200 Notify(
PSTR(
"\r\nMotion Controller Connected"), 0x80);
205 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) {
211 #ifdef DEBUG_USB_HOST
212 Notify(
PSTR(
"\r\nBluetooth Address was set to: "), 0x80);
213 for(int8_t i = 5; i > 0; i--) {
214 D_PrintHex<uint8_t > (my_bdaddr[i], 0x80);
217 D_PrintHex<uint8_t > (my_bdaddr[0], 0x80);
224 timer = (uint32_t)millis();
229 #ifdef DEBUG_USB_HOST
235 #ifdef DEBUG_USB_HOST
241 #ifdef DEBUG_USB_HOST
247 #ifdef DEBUG_USB_HOST
253 #ifdef DEBUG_USB_HOST
254 Notify(
PSTR(
"\r\nPS3 Init Failed, error code: "), 0x80);
279 if((int32_t)((uint32_t)millis() - timer) > 100) {
286 if((int32_t)((uint32_t)millis() - timer) > 4000) {
288 timer = (uint32_t)millis();
294 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() {
309 D_PrintHex<uint8_t > (readBuf[i], 0x80);
322 bool click = (ButtonClickState & button);
323 ButtonClickState &= ~button;
332 return (uint8_t)(readBuf[((uint8_t)a + 6)]);
336 return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
341 float accXval, accYval, accZval;
344 const float zeroG = 511.5f;
353 return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG;
355 return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG;
361 return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
365 char statusOutput[102];
398 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
400 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
407 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
417 PS3_Command(rumbleBuf, 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) {
434 rumbleBuf[1] = rightDuration;
435 rumbleBuf[2] = rightPower;
436 rumbleBuf[3] = leftDuration;
437 rumbleBuf[4] = leftPower;
438 PS3_Command(rumbleBuf, PS3_REPORT_BUFFER_SIZE);
442 writeBuf[9] = value << 1;
443 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
448 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
456 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
462 PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
471 for(uint8_t i = 0; i < 6; i++)
472 buf[i + 2] = bdaddr[5 - i];
475 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
482 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
484 for(uint8_t i = 0; i < 6; i++)
485 bdaddr[5 - i] = buf[i + 2];
488 void PS3USB::enable_sixaxis() {
496 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
500 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
514 moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
518 #ifdef DEBUG_USB_HOST
519 if(rumble < 64 && rumble != 0)
520 Notify(
PSTR(
"\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
522 writeBuf[6] = rumble;
536 for(uint8_t i = 0; i < 6; i++)
537 buf[i + 1] = bdaddr[i];
540 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
547 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
549 for(uint8_t i = 0; i < 6; i++)
550 bdaddr[i] = buf[10 + i];
556 for(uint8_t i = 0; i < 3; i++) {
558 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
560 for(uint8_t j = 0; j < 49; j++)
561 data[49 * i + j] = buf[j];
565 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)
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)
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[]
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#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)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
#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
float getAngle(AngleEnum a)
#define HID_REQUEST_SET_REPORT
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
#define HID_REQUEST_GET_REPORT
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)