mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
A few minor changes
This commit is contained in:
parent
d7464b16b4
commit
67a8969711
2 changed files with 28 additions and 31 deletions
20
PS3USB.cpp
20
PS3USB.cpp
|
@ -74,7 +74,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
// get memory address of USB device address pool
|
// get memory address of USB device address pool
|
||||||
AddressPool &addrPool = pUsb->GetAddressPool();
|
AddressPool &addrPool = pUsb->GetAddressPool();
|
||||||
#ifdef EXTRADEBUG
|
#ifdef EXTRADEBUG
|
||||||
Notify(PSTR("\r\nPS3BT Init"));
|
Notify(PSTR("\r\nPS3USB Init"));
|
||||||
#endif
|
#endif
|
||||||
// check if address has already been assigned to an instance
|
// check if address has already been assigned to an instance
|
||||||
if (bAddress)
|
if (bAddress)
|
||||||
|
@ -209,6 +209,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
/* Set internal bluetooth address and request for data */
|
/* Set internal bluetooth address and request for data */
|
||||||
setBdaddr(my_bdaddr);
|
setBdaddr(my_bdaddr);
|
||||||
enable_sixaxis();
|
enable_sixaxis();
|
||||||
|
setLedOn(LED1);
|
||||||
|
|
||||||
// Needed for PS3 Dualshock and Navigation commands to work
|
// Needed for PS3 Dualshock and Navigation commands to work
|
||||||
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
|
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
|
||||||
|
@ -216,10 +217,6 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
|
|
||||||
for (uint8_t i = 6; i < 10; i++)
|
for (uint8_t i = 6; i < 10; i++)
|
||||||
readBuf[i] = 0x7F; // Set the analog joystick values to center position
|
readBuf[i] = 0x7F; // Set the analog joystick values to center position
|
||||||
|
|
||||||
setLedOn(LED1);
|
|
||||||
|
|
||||||
timer = millis();
|
|
||||||
}
|
}
|
||||||
else // must be a Motion controller
|
else // must be a Motion controller
|
||||||
{
|
{
|
||||||
|
@ -233,8 +230,6 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
// Needed for Move commands to work
|
// Needed for Move commands to work
|
||||||
for (uint8_t i = 0; i < MOVE_REPORT_BUFFER_SIZE; i++)
|
for (uint8_t i = 0; i < MOVE_REPORT_BUFFER_SIZE; i++)
|
||||||
writeBuf[i] = pgm_read_byte(&MOVE_REPORT_BUFFER[i]);
|
writeBuf[i] = pgm_read_byte(&MOVE_REPORT_BUFFER[i]);
|
||||||
|
|
||||||
timer = millis();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -242,6 +237,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
|
|
||||||
bPollEnable = true;
|
bPollEnable = true;
|
||||||
Notify(PSTR("\r\n"));
|
Notify(PSTR("\r\n"));
|
||||||
|
timer = millis();
|
||||||
return 0; // successful configuration
|
return 0; // successful configuration
|
||||||
|
|
||||||
/* diagnostic messages */
|
/* diagnostic messages */
|
||||||
|
@ -377,24 +373,24 @@ uint8_t PS3USB::getAnalogHat(AnalogHat a)
|
||||||
return 0;
|
return 0;
|
||||||
return (uint8_t)(readBuf[(uint16_t)a]);
|
return (uint8_t)(readBuf[(uint16_t)a]);
|
||||||
}
|
}
|
||||||
int32_t PS3USB::getSensor(Sensor a)
|
uint16_t PS3USB::getSensor(Sensor a)
|
||||||
{
|
{
|
||||||
if (readBuf == NULL)
|
if (readBuf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
return ((readBuf[(uint16_t)a] << 8) | readBuf[(uint16_t)a + 1]);
|
return ((readBuf[(uint16_t)a] << 8) | readBuf[(uint16_t)a + 1]);
|
||||||
}
|
}
|
||||||
double PS3USB::getAngle(Angle a) {
|
double PS3USB::getAngle(Angle a) {
|
||||||
|
if(PS3Connected) {
|
||||||
double accXval;
|
double accXval;
|
||||||
double accYval;
|
double accYval;
|
||||||
double accZval;
|
double accZval;
|
||||||
|
|
||||||
if(PS3Connected) {
|
|
||||||
// Data for the Kionix KXPC4 used in the DualShock 3
|
// Data for the Kionix KXPC4 used in the DualShock 3
|
||||||
const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
|
const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V)
|
||||||
accXval = -((double)getSensor(aX)-zeroG);
|
accXval = -((double)getSensor(aX)-zeroG);
|
||||||
accYval = -((double)getSensor(aY)-zeroG);
|
accYval = -((double)getSensor(aY)-zeroG);
|
||||||
accZval = -((double)getSensor(aZ)-zeroG);
|
accZval = -((double)getSensor(aZ)-zeroG);
|
||||||
}
|
|
||||||
// Convert to 360 degrees resolution
|
// Convert to 360 degrees resolution
|
||||||
// atan2 outputs the value of -π to π (radians)
|
// atan2 outputs the value of -π to π (radians)
|
||||||
// We are then converting it to 0 to 2π and then to degrees
|
// We are then converting it to 0 to 2π and then to degrees
|
||||||
|
@ -405,6 +401,9 @@ double PS3USB::getAngle(Angle a) {
|
||||||
double angle = (atan2(accXval,accZval)+PI)*RAD_TO_DEG;
|
double angle = (atan2(accXval,accZval)+PI)*RAD_TO_DEG;
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
bool PS3USB::getStatus(Status c)
|
bool PS3USB::getStatus(Status c)
|
||||||
{
|
{
|
||||||
|
@ -428,6 +427,7 @@ String PS3USB::getStatusString()
|
||||||
|
|
||||||
|
|
||||||
strcat(statusOutput," - PowerRating: ");
|
strcat(statusOutput," - PowerRating: ");
|
||||||
|
|
||||||
if (getStatus(Charging)) strcat(statusOutput,"Charging");
|
if (getStatus(Charging)) strcat(statusOutput,"Charging");
|
||||||
else if (getStatus(NotCharging)) strcat(statusOutput,"Not Charging");
|
else if (getStatus(NotCharging)) strcat(statusOutput,"Not Charging");
|
||||||
else if (getStatus(Shutdown)) strcat(statusOutput,"Shutdown");
|
else if (getStatus(Shutdown)) strcat(statusOutput,"Shutdown");
|
||||||
|
|
7
PS3USB.h
7
PS3USB.h
|
@ -46,9 +46,6 @@
|
||||||
#define PS3_REPORT_BUFFER_SIZE 48 // Size of the output report buffer for the Dualshock and Navigation controllers
|
#define PS3_REPORT_BUFFER_SIZE 48 // Size of the output report buffer for the Dualshock and Navigation controllers
|
||||||
#define MOVE_REPORT_BUFFER_SIZE 7 // Size of the output report buffer for the Move Controller
|
#define MOVE_REPORT_BUFFER_SIZE 7 // Size of the output report buffer for the Move Controller
|
||||||
|
|
||||||
// used in control endpoint header for HCI Commands
|
|
||||||
#define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
|
|
||||||
|
|
||||||
// used in control endpoint header for HID Commands
|
// used in control endpoint header for HID Commands
|
||||||
#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
|
#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
|
||||||
#define HID_REQUEST_SET_REPORT 0x09
|
#define HID_REQUEST_SET_REPORT 0x09
|
||||||
|
@ -163,7 +160,7 @@ enum Status
|
||||||
CableRumble = (31 << 8) | 0x10, // Opperating by USB and rumble is turned on
|
CableRumble = (31 << 8) | 0x10, // Opperating by USB and rumble is turned on
|
||||||
Cable = (31 << 8) | 0x12, // Opperating by USB and rumble is turned off
|
Cable = (31 << 8) | 0x12, // Opperating by USB and rumble is turned off
|
||||||
BluetoothRumble = (31 << 8) | 0x14, // Opperating by bluetooth and rumble is turned on
|
BluetoothRumble = (31 << 8) | 0x14, // Opperating by bluetooth and rumble is turned on
|
||||||
Bluetooth = (30 << 8) | 0x16, // Opperating by bluetooth and rumble is turned off
|
Bluetooth = (31 << 8) | 0x16, // Opperating by bluetooth and rumble is turned off
|
||||||
};
|
};
|
||||||
enum Rumble
|
enum Rumble
|
||||||
{
|
{
|
||||||
|
@ -190,7 +187,7 @@ public:
|
||||||
bool getButton(Button b);
|
bool getButton(Button b);
|
||||||
uint8_t getAnalogButton(AnalogButton a);
|
uint8_t getAnalogButton(AnalogButton a);
|
||||||
uint8_t getAnalogHat(AnalogHat a);
|
uint8_t getAnalogHat(AnalogHat a);
|
||||||
int32_t getSensor(Sensor a);
|
uint16_t getSensor(Sensor a);
|
||||||
double getAngle(Angle a);
|
double getAngle(Angle a);
|
||||||
bool getStatus(Status c);
|
bool getStatus(Status c);
|
||||||
String getStatusString();
|
String getStatusString();
|
||||||
|
|
Loading…
Reference in a new issue