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);
324 bool click = (ButtonClickState & button);
325 ButtonClickState &= ~button;
335 return (uint8_t)(readBuf[((uint8_t)a + 6)]);
339 return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]);
344 float accXval, accYval, accZval;
347 const float zeroG = 511.5f;
356 return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG;
358 return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG;
364 return (readBuf[((uint16_t)c >> 8) - 9] == ((uint8_t)c & 0xff));
368 char statusOutput[102];
401 void PS3USB::PS3_Command(uint8_t *data, uint16_t nbytes) {
403 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x01, 0x02, 0x00, nbytes, nbytes, data, NULL);
424 if((mode & 0x30) > 0x00) {
425 uint8_t power[2] = {0xff, 0x00};
434 void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
437 rumbleBuf[1] = rightDuration;
438 rumbleBuf[2] = rightPower;
439 rumbleBuf[3] = leftDuration;
440 rumbleBuf[4] = leftPower;
445 writeBuf[9] = value << 1;
474 for(uint8_t i = 0; i < 6; i++)
475 buf[i + 2] = bdaddr[5 - i];
478 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
485 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0xF5, 0x03, 0x00, 8, 8, buf, NULL);
487 for(uint8_t i = 0; i < 6; i++)
488 bdaddr[5 - i] = buf[i + 2];
491 void PS3USB::enable_sixaxis() {
499 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0xF4, 0x03, 0x00, 4, 4, cmd_buf, NULL);
503 void PS3USB::Move_Command(uint8_t *data, uint16_t nbytes) {
517 moveSetBulb((uint8_t)(color >> 16), (uint8_t)(color >> 8), (uint8_t)(color));
521 #ifdef DEBUG_USB_HOST
522 if(rumble < 64 && rumble != 0)
523 Notify(
PSTR(
"\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
525 writeBuf[6] = rumble;
539 for(uint8_t i = 0; i < 6; i++)
540 buf[i + 1] = bdaddr[i];
543 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
550 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x04, 0x03, 0x00, 16, 16, buf, NULL);
552 for(uint8_t i = 0; i < 6; i++)
553 bdaddr[i] = buf[10 + i];
559 for(uint8_t i = 0; i < 3; i++) {
561 pUsb->
ctrlReq(
bAddress,
epInfo[
PS3_CONTROL_PIPE].epAddr,
bmREQ_HID_IN,
HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
563 for(uint8_t j = 0; j < 49; j++)
564 data[49 * i + j] = buf[j];
568 void PS3USB::onInit() {
#define PS3NAVIGATION_PID
#define MOVE_REPORT_BUFFER_SIZE
#define PS3_REPORT_BUFFER_SIZE
int8_t getButtonIndexPS3(ButtonEnum b)
const uint32_t PS3_BUTTONS[]
const uint8_t PS3_REPORT_BUFFER[PS3_REPORT_BUFFER_SIZE]
const uint8_t PS3_ANALOG_BUTTONS[]
#define PS3_MAX_ENDPOINTS
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_NAK_MAX_POWER
virtual void FreeAddress(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
uint8_t getAnalogHat(AnalogHatEnum a)
void getBdaddr(uint8_t *bdaddr)
EpInfo epInfo[PS3_MAX_ENDPOINTS]
float getAngle(AngleEnum a)
void setMoveBdaddr(uint8_t *bdaddr)
bool PS3NavigationConnected
void moveSetRumble(uint8_t rumble)
uint8_t getAnalogButton(ButtonEnum a)
void getMoveBdaddr(uint8_t *bdaddr)
void setRumbleOn(RumbleEnum mode)
void setLedToggle(LEDEnum a)
bool getButtonPress(ButtonEnum b)
uint16_t getSensor(SensorEnum a)
void setLedRaw(uint8_t value)
void getMoveCalibration(uint8_t *data)
bool getButtonClick(ButtonEnum b)
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)
bool getStatus(StatusEnum c)
void setBdaddr(uint8_t *bdaddr)
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b)
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
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)
AddressPool & GetAddressPool()
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
#define NotifyFailSetConfDescr(...)
#define NotifyFailUnknownDevice(...)
#define NotifyFailSetDevTblEntry(...)
#define NotifyFailGetDevDescr(...)
#define USB_TRANSFER_TYPE_INTERRUPT
#define HID_REQUEST_GET_REPORT
#define HID_REQUEST_SET_REPORT
#define strcat_P(dest, src)
#define pgm_read_byte(addr)
#define pgm_read_dword(addr)
#define strcpy_P(dest, src)