mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added delay before bus reset and renamed some variables and cleanup example
This commit is contained in:
parent
859c9d0f80
commit
52858d502b
3 changed files with 59 additions and 56 deletions
10
XBOXRECV.cpp
10
XBOXRECV.cpp
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "XBOXRECV.h"
|
#include "XBOXRECV.h"
|
||||||
// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
|
// To enable serial debugging see "settings.h"
|
||||||
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
|
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
|
||||||
|
|
||||||
|
@ -106,6 +106,8 @@ uint8_t XBOXRECV::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
|
epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
|
||||||
epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
|
epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory
|
||||||
|
|
||||||
|
delay(20); // Wait a little before resetting device
|
||||||
|
|
||||||
return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
|
return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
|
||||||
|
|
||||||
/* Diagnostic messages */
|
/* Diagnostic messages */
|
||||||
|
@ -254,6 +256,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
#endif
|
#endif
|
||||||
XboxReceiverConnected = true;
|
XboxReceiverConnected = true;
|
||||||
bPollEnable = true;
|
bPollEnable = true;
|
||||||
|
checkStatusTimer = 0; // Reset timer
|
||||||
return 0; // Successful configuration
|
return 0; // Successful configuration
|
||||||
|
|
||||||
/* Diagnostic messages */
|
/* Diagnostic messages */
|
||||||
|
@ -298,10 +301,11 @@ uint8_t XBOXRECV::Release() {
|
||||||
uint8_t XBOXRECV::Poll() {
|
uint8_t XBOXRECV::Poll() {
|
||||||
if (!bPollEnable)
|
if (!bPollEnable)
|
||||||
return 0;
|
return 0;
|
||||||
if (!timer || ((millis() - timer) > 3000)) { // Run checkStatus every 3 seconds
|
if (!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds
|
||||||
timer = millis();
|
checkStatusTimer = millis();
|
||||||
checkStatus();
|
checkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t inputPipe;
|
uint8_t inputPipe;
|
||||||
uint16_t bufferSize;
|
uint16_t bufferSize;
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
|
|
@ -259,7 +259,7 @@ private:
|
||||||
bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
|
bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
|
||||||
bool R2Clicked[4];
|
bool R2Clicked[4];
|
||||||
|
|
||||||
unsigned long timer; // Timing for checkStatus() signals
|
uint32_t checkStatusTimer; // Timing for checkStatus() signals
|
||||||
|
|
||||||
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
|
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
|
||||||
uint8_t writeBuf[7]; // General purpose buffer for output data
|
uint8_t writeBuf[7]; // General purpose buffer for output data
|
||||||
|
|
|
@ -15,81 +15,81 @@ void setup() {
|
||||||
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
||||||
if (Usb.Init() == -1) {
|
if (Usb.Init() == -1) {
|
||||||
Serial.print(F("\r\nOSC did not start"));
|
Serial.print(F("\r\nOSC did not start"));
|
||||||
while(1); //halt
|
while (1); //halt
|
||||||
}
|
}
|
||||||
Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
|
Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
|
||||||
}
|
}
|
||||||
void loop() {
|
void loop() {
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
if(Xbox.XboxReceiverConnected) {
|
if (Xbox.XboxReceiverConnected) {
|
||||||
for(uint8_t i=0;i<4;i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
if(Xbox.Xbox360Connected[i]) {
|
if (Xbox.Xbox360Connected[i]) {
|
||||||
if(Xbox.getButtonPress(L2,i) || Xbox.getButtonPress(R2,i)) {
|
if (Xbox.getButtonPress(L2, i) || Xbox.getButtonPress(R2, i)) {
|
||||||
Serial.print("L2: ");
|
Serial.print("L2: ");
|
||||||
Serial.print(Xbox.getButtonPress(L2,i));
|
Serial.print(Xbox.getButtonPress(L2, i));
|
||||||
Serial.print("\tR2: ");
|
Serial.print("\tR2: ");
|
||||||
Serial.println(Xbox.getButtonPress(R2,i));
|
Serial.println(Xbox.getButtonPress(R2, i));
|
||||||
Xbox.setRumbleOn(Xbox.getButtonPress(L2,i),Xbox.getButtonPress(R2,i),i);
|
Xbox.setRumbleOn(Xbox.getButtonPress(L2, i), Xbox.getButtonPress(R2, i), i);
|
||||||
}
|
}
|
||||||
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500 || Xbox.getAnalogHat(LeftHatY,i) > 7500 || Xbox.getAnalogHat(LeftHatY,i) < -7500 || Xbox.getAnalogHat(RightHatX,i) > 7500 || Xbox.getAnalogHat(RightHatX,i) < -7500 || Xbox.getAnalogHat(RightHatY,i) > 7500 || Xbox.getAnalogHat(RightHatY,i) < -7500) {
|
if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500 || Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500 || Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500 || Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) {
|
||||||
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500) {
|
if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500) {
|
||||||
Serial.print(F("LeftHatX: "));
|
Serial.print(F("LeftHatX: "));
|
||||||
Serial.print(Xbox.getAnalogHat(LeftHatX,i));
|
Serial.print(Xbox.getAnalogHat(LeftHatX, i));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
}
|
}
|
||||||
if(Xbox.getAnalogHat(LeftHatY,i) > 7500 || Xbox.getAnalogHat(LeftHatY,i) < -7500) {
|
if (Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500) {
|
||||||
Serial.print(F("LeftHatY: "));
|
Serial.print(F("LeftHatY: "));
|
||||||
Serial.print(Xbox.getAnalogHat(LeftHatY,i));
|
Serial.print(Xbox.getAnalogHat(LeftHatY, i));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
}
|
}
|
||||||
if(Xbox.getAnalogHat(RightHatX,i) > 7500 || Xbox.getAnalogHat(RightHatX,i) < -7500) {
|
if (Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500) {
|
||||||
Serial.print(F("RightHatX: "));
|
Serial.print(F("RightHatX: "));
|
||||||
Serial.print(Xbox.getAnalogHat(RightHatX,i));
|
Serial.print(Xbox.getAnalogHat(RightHatX, i));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
}
|
}
|
||||||
if(Xbox.getAnalogHat(RightHatY,i) > 7500 || Xbox.getAnalogHat(RightHatY,i) < -7500) {
|
if (Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) {
|
||||||
Serial.print(F("RightHatY: "));
|
Serial.print(F("RightHatY: "));
|
||||||
Serial.print(Xbox.getAnalogHat(RightHatY,i));
|
Serial.print(Xbox.getAnalogHat(RightHatY, i));
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Xbox.getButtonClick(UP,i)) {
|
if (Xbox.getButtonClick(UP, i)) {
|
||||||
Xbox.setLedOn(LED1,i);
|
Xbox.setLedOn(LED1, i);
|
||||||
Serial.println(F("Up"));
|
Serial.println(F("Up"));
|
||||||
}
|
}
|
||||||
if(Xbox.getButtonClick(DOWN,i)) {
|
if (Xbox.getButtonClick(DOWN, i)) {
|
||||||
Xbox.setLedOn(LED4,i);
|
Xbox.setLedOn(LED4, i);
|
||||||
Serial.println(F("Down"));
|
Serial.println(F("Down"));
|
||||||
}
|
}
|
||||||
if(Xbox.getButtonClick(LEFT,i)) {
|
if (Xbox.getButtonClick(LEFT, i)) {
|
||||||
Xbox.setLedOn(LED3,i);
|
Xbox.setLedOn(LED3, i);
|
||||||
Serial.println(F("Left"));
|
Serial.println(F("Left"));
|
||||||
}
|
}
|
||||||
if(Xbox.getButtonClick(RIGHT,i)) {
|
if (Xbox.getButtonClick(RIGHT, i)) {
|
||||||
Xbox.setLedOn(LED2,i);
|
Xbox.setLedOn(LED2, i);
|
||||||
Serial.println(F("Right"));
|
Serial.println(F("Right"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Xbox.getButtonClick(START,i)) {
|
if (Xbox.getButtonClick(START, i)) {
|
||||||
Xbox.setLedMode(ALTERNATING,i);
|
Xbox.setLedMode(ALTERNATING, i);
|
||||||
Serial.println(F("Start"));
|
Serial.println(F("Start"));
|
||||||
}
|
}
|
||||||
if(Xbox.getButtonClick(BACK,i)) {
|
if (Xbox.getButtonClick(BACK, i)) {
|
||||||
Xbox.setLedBlink(ALL,i);
|
Xbox.setLedBlink(ALL, i);
|
||||||
Serial.println(F("Back"));
|
Serial.println(F("Back"));
|
||||||
}
|
}
|
||||||
if(Xbox.getButtonClick(L3,i))
|
if (Xbox.getButtonClick(L3, i))
|
||||||
Serial.println(F("L3"));
|
Serial.println(F("L3"));
|
||||||
if(Xbox.getButtonClick(R3,i))
|
if (Xbox.getButtonClick(R3, i))
|
||||||
Serial.println(F("R3"));
|
Serial.println(F("R3"));
|
||||||
|
|
||||||
if(Xbox.getButtonClick(L1,i))
|
if (Xbox.getButtonClick(L1, i))
|
||||||
Serial.println(F("L1"));
|
Serial.println(F("L1"));
|
||||||
if(Xbox.getButtonClick(R1,i))
|
if (Xbox.getButtonClick(R1, i))
|
||||||
Serial.println(F("R1"));
|
Serial.println(F("R1"));
|
||||||
if(Xbox.getButtonClick(XBOX,i)) {
|
if (Xbox.getButtonClick(XBOX, i)) {
|
||||||
Xbox.setLedMode(ROTATING,i);
|
Xbox.setLedMode(ROTATING, i);
|
||||||
Serial.print(F("Xbox (Battery: "));
|
Serial.print(F("Xbox (Battery: "));
|
||||||
Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
|
Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
|
||||||
Serial.println(F(")"));
|
Serial.println(F(")"));
|
||||||
|
@ -97,16 +97,15 @@ void loop() {
|
||||||
if(Xbox.getButtonClick(SYNC,i))
|
if(Xbox.getButtonClick(SYNC,i))
|
||||||
Serial.println(F("Sync"));
|
Serial.println(F("Sync"));
|
||||||
|
|
||||||
if(Xbox.getButtonClick(A,i))
|
if (Xbox.getButtonClick(A, i))
|
||||||
Serial.println(F("A"));
|
Serial.println(F("A"));
|
||||||
if(Xbox.getButtonClick(B,i))
|
if (Xbox.getButtonClick(B, i))
|
||||||
Serial.println(F("B"));
|
Serial.println(F("B"));
|
||||||
if(Xbox.getButtonClick(X,i))
|
if (Xbox.getButtonClick(X, i))
|
||||||
Serial.println(F("X"));
|
Serial.println(F("X"));
|
||||||
if(Xbox.getButtonClick(Y,i))
|
if (Xbox.getButtonClick(Y, i))
|
||||||
Serial.println(F("Y"));
|
Serial.println(F("Y"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(1);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue