mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added attachOnInit
This will allow the user to call a function when the controller is initialized
This commit is contained in:
parent
c3c80924ec
commit
2dc817f84a
11 changed files with 160 additions and 38 deletions
15
PS3BT.cpp
15
PS3BT.cpp
|
@ -516,25 +516,23 @@ void PS3BT::Run() {
|
|||
case L2CAP_HID_PS3_LED:
|
||||
if (millis() - timer > 1000) { // loop 1 second before sending the command
|
||||
if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
|
||||
setLedOn(LED1);
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
|
||||
#endif
|
||||
PS3Connected = true;
|
||||
} else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
|
||||
setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
|
||||
#endif
|
||||
PS3NavigationConnected = true;
|
||||
} else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M')
|
||||
moveSetBulb(Red);
|
||||
timerBulbRumble = millis();
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
|
||||
#endif
|
||||
PS3MoveConnected = true;
|
||||
}
|
||||
onInit(); // Turn on the LED on the controller
|
||||
l2cap_state = L2CAP_DONE;
|
||||
}
|
||||
break;
|
||||
|
@ -659,3 +657,14 @@ void PS3BT::moveSetRumble(uint8_t rumble) {
|
|||
|
||||
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
|
||||
}
|
||||
|
||||
void PS3BT::onInit() {
|
||||
if (pFuncOnInit)
|
||||
pFuncOnInit(); // Call the user function
|
||||
else {
|
||||
if (PS3MoveConnected)
|
||||
moveSetBulb(Red);
|
||||
else // Dualshock 3 or Navigation controller
|
||||
setLedOn(LED1);
|
||||
}
|
||||
}
|
26
PS3BT.h
26
PS3BT.h
|
@ -207,19 +207,35 @@ public:
|
|||
* @param rumble The desired value in the range from 64-255.
|
||||
*/
|
||||
void moveSetRumble(uint8_t rumble);
|
||||
|
||||
/**
|
||||
* Used to call your own function when the controller is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit;
|
||||
};
|
||||
/**@}*/
|
||||
|
||||
/** Variable used to indicate if the normal playstation controller is successfully connected. */
|
||||
/** Variable used to indicate if the normal Playstation controller is successfully connected. */
|
||||
bool PS3Connected;
|
||||
/** Variable used to indicate if the move controller is successfully connected. */
|
||||
/** Variable used to indicate if the Move controller is successfully connected. */
|
||||
bool PS3MoveConnected;
|
||||
/** Variable used to indicate if the navigation controller is successfully connected. */
|
||||
/** Variable used to indicate if the Navigation controller is successfully connected. */
|
||||
bool PS3NavigationConnected;
|
||||
|
||||
private:
|
||||
/* mandatory members */
|
||||
/* Mandatory members */
|
||||
BTD *pBtd;
|
||||
|
||||
/**
|
||||
* Called when the controller is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
void onInit();
|
||||
void (*pFuncOnInit)(void); // Pointer to function called in onInit()
|
||||
|
||||
void L2CAP_task(); // L2CAP state machine
|
||||
|
||||
/* Variables filled from HCI event management */
|
||||
|
@ -229,7 +245,7 @@ private:
|
|||
|
||||
/* variables used by high level L2CAP task */
|
||||
uint8_t l2cap_state;
|
||||
uint16_t l2cap_event_flag; // L2CAP flags of received bluetooth events
|
||||
uint16_t l2cap_event_flag; // L2CAP flags of received Bluetooth events
|
||||
|
||||
unsigned long timer;
|
||||
|
||||
|
|
18
PS3USB.cpp
18
PS3USB.cpp
|
@ -183,10 +183,9 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
|||
#endif
|
||||
PS3NavigationConnected = true;
|
||||
}
|
||||
/* Set internal bluetooth address and request for data */
|
||||
/* Set internal Bluetooth address and request for data */
|
||||
setBdaddr(my_bdaddr);
|
||||
enable_sixaxis();
|
||||
setLedOn(LED1);
|
||||
|
||||
// Needed for PS3 Dualshock and Navigation commands to work
|
||||
for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++)
|
||||
|
@ -199,11 +198,11 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
|||
Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
|
||||
#endif
|
||||
PS3MoveConnected = true;
|
||||
setMoveBdaddr(my_bdaddr); // Set internal bluetooth address
|
||||
moveSetBulb(Red);
|
||||
setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
|
||||
|
||||
writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
|
||||
}
|
||||
onInit();
|
||||
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
|
||||
|
@ -538,3 +537,14 @@ void PS3USB::setMoveBdaddr(uint8_t* BDADDR) {
|
|||
//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)
|
||||
pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x05, 0x03, 0x00, 11, 11, buf, NULL);
|
||||
}
|
||||
|
||||
void PS3USB::onInit() {
|
||||
if (pFuncOnInit)
|
||||
pFuncOnInit(); // Call the user function
|
||||
else {
|
||||
if (PS3MoveConnected)
|
||||
moveSetBulb(Red);
|
||||
else // Dualshock 3 or Navigation controller
|
||||
setLedOn(LED1);
|
||||
}
|
||||
}
|
16
PS3USB.h
16
PS3USB.h
|
@ -224,6 +224,14 @@ public:
|
|||
* @param rumble The desired value in the range from 64-255.
|
||||
*/
|
||||
void moveSetRumble(uint8_t rumble);
|
||||
|
||||
/**
|
||||
* Used to call your own function when the controller is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit;
|
||||
};
|
||||
/**@}*/
|
||||
|
||||
/** Variable used to indicate if the normal playstation controller is successfully connected. */
|
||||
|
@ -242,6 +250,14 @@ protected:
|
|||
EpInfo epInfo[PS3_MAX_ENDPOINTS];
|
||||
|
||||
private:
|
||||
/**
|
||||
* Called when the controller is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
void onInit();
|
||||
void (*pFuncOnInit)(void); // Pointer to function called in onInit()
|
||||
|
||||
bool bPollEnable;
|
||||
|
||||
uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values
|
||||
|
|
14
Wii.cpp
14
Wii.cpp
|
@ -326,7 +326,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
|||
#endif
|
||||
nunchuckConnected = false; // It must be the Nunchuck controller then
|
||||
l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED;
|
||||
setLedStatus();
|
||||
onInit();
|
||||
setReportMode(false, 0x31); // If there is no extension connected we will read the button and accelerometer
|
||||
} else {
|
||||
setReportMode(false, 0x31); // If there is no extension connected we will read the button and accelerometer
|
||||
|
@ -779,7 +779,7 @@ void WII::Run() {
|
|||
case L2CAP_LED_STATE:
|
||||
if (nunchuck_connected_flag)
|
||||
nunchuckConnected = true;
|
||||
setLedStatus();
|
||||
onInit();
|
||||
l2cap_state = L2CAP_DONE;
|
||||
break;
|
||||
|
||||
|
@ -824,7 +824,7 @@ void WII::Run() {
|
|||
else if (stateCounter == 400)
|
||||
readExtensionType(); // Check if it has been activated
|
||||
else if (stateCounter == 450) {
|
||||
//setLedStatus();
|
||||
onInit();
|
||||
stateCounter = 0;
|
||||
unknownExtensionConnected = false;
|
||||
}
|
||||
|
@ -1062,6 +1062,14 @@ uint16_t WII::getAnalogHat(AnalogHat a) {
|
|||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
void WII::onInit() {
|
||||
if (pFuncOnInit)
|
||||
pFuncOnInit(); // Call the user function
|
||||
else
|
||||
setLedStatus();
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* The following functions are for the IR camera */
|
||||
/************************************************************/
|
||||
|
|
23
Wii.h
23
Wii.h
|
@ -233,6 +233,14 @@ public:
|
|||
uint8_t getWiiState() {
|
||||
return wiiState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to call your own function when the controller is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit;
|
||||
};
|
||||
/**@}*/
|
||||
|
||||
/**@{*/
|
||||
|
@ -418,8 +426,15 @@ public:
|
|||
#endif
|
||||
|
||||
private:
|
||||
/* Mandatory members */
|
||||
BTD *pBtd;
|
||||
BTD *pBtd; // Pointer to BTD instance
|
||||
|
||||
/**
|
||||
* Called when the controller is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
void onInit();
|
||||
void (*pFuncOnInit)(void); // Pointer to function called in onInit()
|
||||
|
||||
void L2CAP_task(); // L2CAP state machine
|
||||
|
||||
|
@ -427,9 +442,9 @@ private:
|
|||
uint16_t hci_handle;
|
||||
bool activeConnection; // Used to indicate if it's already has established a connection
|
||||
|
||||
/* variables used by high level L2CAP task */
|
||||
/* Variables used by high level L2CAP task */
|
||||
uint8_t l2cap_state;
|
||||
uint16_t l2cap_event_flag; // l2cap flags of received bluetooth events
|
||||
uint16_t l2cap_event_flag; // l2cap flags of received Bluetooth events
|
||||
|
||||
uint32_t ButtonState;
|
||||
uint32_t OldButtonState;
|
||||
|
|
32
XBOXRECV.cpp
32
XBOXRECV.cpp
|
@ -310,7 +310,7 @@ void XBOXRECV::readReport(uint8_t controller) {
|
|||
#endif
|
||||
if (Xbox360Connected[controller]) {
|
||||
#ifdef DEBUG_USB_HOST
|
||||
char* str = 0;
|
||||
const char* str = 0;
|
||||
switch (readBuf[1]) {
|
||||
case 0x80: str = PSTR(" as controller\r\n");
|
||||
break;
|
||||
|
@ -322,18 +322,7 @@ void XBOXRECV::readReport(uint8_t controller) {
|
|||
Notify(PSTR(": connected"), 0x80);
|
||||
Notify(str, 0x80);
|
||||
#endif
|
||||
LED led;
|
||||
switch (controller) {
|
||||
case 0: led = LED1;
|
||||
break;
|
||||
case 1: led = LED2;
|
||||
break;
|
||||
case 2: led = LED3;
|
||||
break;
|
||||
case 3: led = LED4;
|
||||
break;
|
||||
}
|
||||
setLedOn(led, controller);
|
||||
onInit(controller);
|
||||
}
|
||||
#ifdef DEBUG_USB_HOST
|
||||
else
|
||||
|
@ -529,3 +518,20 @@ void XBOXRECV::setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller) {
|
|||
|
||||
XboxCommand(controller, writeBuf, 7);
|
||||
}
|
||||
|
||||
void XBOXRECV::onInit(uint8_t controller) {
|
||||
if (pFuncOnInit)
|
||||
pFuncOnInit(); // Call the user function
|
||||
else {
|
||||
LED led;
|
||||
if (controller == 0)
|
||||
led = LED1;
|
||||
else if (controller == 1)
|
||||
led = LED2;
|
||||
if (controller == 2)
|
||||
led = LED3;
|
||||
else
|
||||
led = LED4;
|
||||
setLedOn(led, controller);
|
||||
}
|
||||
}
|
||||
|
|
17
XBOXRECV.h
17
XBOXRECV.h
|
@ -200,6 +200,14 @@ public:
|
|||
* @return True if a button has changed.
|
||||
*/
|
||||
bool buttonChanged(uint8_t controller = 0);
|
||||
|
||||
/**
|
||||
* Used to call your own function when the controller is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit;
|
||||
};
|
||||
/**@}*/
|
||||
|
||||
/** True if a wireless receiver is connected. */
|
||||
|
@ -216,6 +224,15 @@ protected:
|
|||
EpInfo epInfo[XBOX_MAX_ENDPOINTS];
|
||||
|
||||
private:
|
||||
/**
|
||||
* Called when the controller is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
* @param controller The initialized controller.
|
||||
*/
|
||||
void onInit(uint8_t controller);
|
||||
void (*pFuncOnInit)(void); // Pointer to function called in onInit()
|
||||
|
||||
bool bPollEnable;
|
||||
|
||||
/* Variables to store the buttons */
|
||||
|
|
13
XBOXUSB.cpp
13
XBOXUSB.cpp
|
@ -176,12 +176,12 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
|||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80);
|
||||
#endif
|
||||
setLedOn(LED1);
|
||||
onInit();
|
||||
Xbox360Connected = true;
|
||||
bPollEnable = true;
|
||||
return 0; // successful configuration
|
||||
return 0; // Successful configuration
|
||||
|
||||
/* diagnostic messages */
|
||||
/* Diagnostic messages */
|
||||
FailGetDevDescr:
|
||||
#ifdef DEBUG_USB_HOST
|
||||
NotifyFailGetDevDescr();
|
||||
|
@ -345,3 +345,10 @@ void XBOXUSB::setRumbleOn(uint8_t lValue, uint8_t rValue) {
|
|||
|
||||
XboxCommand(writeBuf, 8);
|
||||
}
|
||||
|
||||
void XBOXUSB::onInit() {
|
||||
if (pFuncOnInit)
|
||||
pFuncOnInit(); // Call the user function
|
||||
else
|
||||
setLedOn(LED1);
|
||||
}
|
||||
|
|
16
XBOXUSB.h
16
XBOXUSB.h
|
@ -168,6 +168,14 @@ public:
|
|||
* @param lm See ::LEDMode.
|
||||
*/
|
||||
void setLedMode(LEDMode lm);
|
||||
|
||||
/**
|
||||
* Used to call your own function when the controller is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit;
|
||||
};
|
||||
/**@}*/
|
||||
|
||||
/** True if a Xbox 360 controller is connected. */
|
||||
|
@ -182,6 +190,14 @@ protected:
|
|||
EpInfo epInfo[XBOX_MAX_ENDPOINTS];
|
||||
|
||||
private:
|
||||
/**
|
||||
* Called when the controller is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
void onInit();
|
||||
void (*pFuncOnInit)(void); // Pointer to function called in onInit()
|
||||
|
||||
bool bPollEnable;
|
||||
|
||||
/* Variables to store the buttons */
|
||||
|
|
|
@ -56,6 +56,8 @@ setLedToggle KEYWORD2
|
|||
moveSetBulb KEYWORD2
|
||||
moveSetRumble KEYWORD2
|
||||
|
||||
attachOnInit KEYWORD2
|
||||
|
||||
PS3Connected KEYWORD2
|
||||
PS3MoveConnected KEYWORD2
|
||||
PS3NavigationConnected KEYWORD2
|
||||
|
|
Loading…
Reference in a new issue