mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Typos, whitespace and some other cleanup stuff
This commit is contained in:
parent
22efbd4d60
commit
7469ff099e
8 changed files with 38 additions and 37 deletions
8
BTD.cpp
8
BTD.cpp
|
@ -36,7 +36,7 @@ qNextPollTime(0), // Reset NextPollTime
|
||||||
pollInterval(0),
|
pollInterval(0),
|
||||||
bPollEnable(false) // Don't start polling before dongle is connected
|
bPollEnable(false) // Don't start polling before dongle is connected
|
||||||
{
|
{
|
||||||
for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
|
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
|
||||||
btService[i] = NULL;
|
btService[i] = NULL;
|
||||||
|
|
||||||
Initialize(); // Set all variables, endpoint structs etc. to default values
|
Initialize(); // Set all variables, endpoint structs etc. to default values
|
||||||
|
@ -293,7 +293,7 @@ void BTD::Initialize() {
|
||||||
epInfo[i].epAttribs = 0;
|
epInfo[i].epAttribs = 0;
|
||||||
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
||||||
}
|
}
|
||||||
for(i = 0; i < BTD_NUMSERVICES; i++) {
|
for(i = 0; i < BTD_NUM_SERVICES; i++) {
|
||||||
if(btService[i])
|
if(btService[i])
|
||||||
btService[i]->Reset(); // Reset all Bluetooth services
|
btService[i]->Reset(); // Reset all Bluetooth services
|
||||||
}
|
}
|
||||||
|
@ -898,7 +898,7 @@ void BTD::ACL_event_task() {
|
||||||
|
|
||||||
if(!rcode) { // Check for errors
|
if(!rcode) { // Check for errors
|
||||||
if(length > 0) { // Check if any data was read
|
if(length > 0) { // Check if any data was read
|
||||||
for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
|
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
|
||||||
if(btService[i])
|
if(btService[i])
|
||||||
btService[i]->ACLData(l2capinbuf);
|
btService[i]->ACLData(l2capinbuf);
|
||||||
}
|
}
|
||||||
|
@ -910,7 +910,7 @@ void BTD::ACL_event_task() {
|
||||||
D_PrintHex<uint8_t > (rcode, 0x80);
|
D_PrintHex<uint8_t > (rcode, 0x80);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
|
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
|
||||||
if(btService[i])
|
if(btService[i])
|
||||||
btService[i]->Run();
|
btService[i]->Run();
|
||||||
}
|
}
|
||||||
|
|
34
BTD.h
34
BTD.h
|
@ -187,7 +187,7 @@
|
||||||
#define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
|
#define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
|
||||||
|
|
||||||
#define BTD_MAX_ENDPOINTS 4
|
#define BTD_MAX_ENDPOINTS 4
|
||||||
#define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
|
#define BTD_NUM_SERVICES 4 // Max number of Bluetooth services - if you need more than 4 simply increase this number
|
||||||
|
|
||||||
#define PAIR 1
|
#define PAIR 1
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ public:
|
||||||
|
|
||||||
/** @name USBDeviceConfig implementation */
|
/** @name USBDeviceConfig implementation */
|
||||||
/**
|
/**
|
||||||
* Address assignment and basic initilization is done here.
|
* Address assignment and basic initialization is done here.
|
||||||
* @param parent Hub number.
|
* @param parent Hub number.
|
||||||
* @param port Port number on the hub.
|
* @param port Port number on the hub.
|
||||||
* @param lowspeed Speed of the device.
|
* @param lowspeed Speed of the device.
|
||||||
|
@ -258,7 +258,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual uint8_t Release();
|
virtual uint8_t Release();
|
||||||
/**
|
/**
|
||||||
* Poll the USB Input endpoins and run the state machines.
|
* Poll the USB Input endpoints and run the state machines.
|
||||||
* @return 0 on success.
|
* @return 0 on success.
|
||||||
*/
|
*/
|
||||||
virtual uint8_t Poll();
|
virtual uint8_t Poll();
|
||||||
|
@ -320,18 +320,18 @@ public:
|
||||||
|
|
||||||
/** Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services. */
|
/** Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services. */
|
||||||
void disconnect() {
|
void disconnect() {
|
||||||
for(uint8_t i = 0; i < BTD_NUMSERVICES; i++)
|
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
|
||||||
if(btService[i])
|
if(btService[i])
|
||||||
btService[i]->disconnect();
|
btService[i]->disconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register bluetooth dongle members/services.
|
* Register Bluetooth dongle members/services.
|
||||||
* @param pService Pointer to BluetoothService class instance.
|
* @param pService Pointer to BluetoothService class instance.
|
||||||
* @return The serice ID on succes or -1 on fail.
|
* @return The service ID on success or -1 on fail.
|
||||||
*/
|
*/
|
||||||
int8_t registerServiceClass(BluetoothService *pService) {
|
int8_t registerServiceClass(BluetoothService *pService) {
|
||||||
for(uint8_t i = 0; i < BTD_NUMSERVICES; i++) {
|
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
|
||||||
if(!btService[i]) {
|
if(!btService[i]) {
|
||||||
btService[i] = pService;
|
btService[i] = pService;
|
||||||
return i; // Return ID
|
return i; // Return ID
|
||||||
|
@ -501,7 +501,7 @@ public:
|
||||||
pairWithWii = true;
|
pairWithWii = true;
|
||||||
hci_state = HCI_CHECK_DEVICE_SERVICE;
|
hci_state = HCI_CHECK_DEVICE_SERVICE;
|
||||||
};
|
};
|
||||||
/** Used to only send the ACL data to the wiimote. */
|
/** Used to only send the ACL data to the Wiimote. */
|
||||||
bool connectToWii;
|
bool connectToWii;
|
||||||
/** True if a Wiimote is connecting. */
|
/** True if a Wiimote is connecting. */
|
||||||
bool incomingWii;
|
bool incomingWii;
|
||||||
|
@ -517,7 +517,7 @@ public:
|
||||||
pairWithHIDDevice = true;
|
pairWithHIDDevice = true;
|
||||||
hci_state = HCI_CHECK_DEVICE_SERVICE;
|
hci_state = HCI_CHECK_DEVICE_SERVICE;
|
||||||
};
|
};
|
||||||
/** Used to only send the ACL data to the wiimote. */
|
/** Used to only send the ACL data to the Wiimote. */
|
||||||
bool connectToHIDDevice;
|
bool connectToHIDDevice;
|
||||||
/** True if a Wiimote is connecting. */
|
/** True if a Wiimote is connecting. */
|
||||||
bool incomingHIDDevice;
|
bool incomingHIDDevice;
|
||||||
|
@ -564,7 +564,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Initialize(); // Set all variables, endpoint structs etc. to default values
|
void Initialize(); // Set all variables, endpoint structs etc. to default values
|
||||||
BluetoothService* btService[BTD_NUMSERVICES];
|
BluetoothService *btService[BTD_NUM_SERVICES];
|
||||||
|
|
||||||
uint16_t PID, VID; // PID and VID of device connected
|
uint16_t PID, VID; // PID and VID of device connected
|
||||||
|
|
||||||
|
@ -575,15 +575,15 @@ private:
|
||||||
uint8_t classOfDevice[3]; // Class of device of last device
|
uint8_t classOfDevice[3]; // Class of device of last device
|
||||||
|
|
||||||
/* Variables used by high level HCI task */
|
/* Variables used by high level HCI task */
|
||||||
uint8_t hci_state; //current state of bluetooth hci connection
|
uint8_t hci_state; // Current state of Bluetooth HCI connection
|
||||||
uint16_t hci_counter; // counter used for bluetooth hci reset loops
|
uint16_t hci_counter; // Counter used for Bluetooth HCI reset loops
|
||||||
uint16_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
|
uint16_t hci_num_reset_loops; // This value indicate how many times it should read before trying to reset
|
||||||
uint16_t hci_event_flag; // hci flags of received bluetooth events
|
uint16_t hci_event_flag; // HCI flags of received Bluetooth events
|
||||||
uint8_t inquiry_counter;
|
uint8_t inquiry_counter;
|
||||||
|
|
||||||
uint8_t hcibuf[BULK_MAXPKTSIZE]; //General purpose buffer for hci data
|
uint8_t hcibuf[BULK_MAXPKTSIZE]; // General purpose buffer for HCI data
|
||||||
uint8_t l2capinbuf[BULK_MAXPKTSIZE]; //General purpose buffer for l2cap in data
|
uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data
|
||||||
uint8_t l2capoutbuf[14]; //General purpose buffer for l2cap out data
|
uint8_t l2capoutbuf[14]; // General purpose buffer for L2CAP out data
|
||||||
|
|
||||||
/* State machines */
|
/* State machines */
|
||||||
void HCI_event_task(); // Poll the HCI event pipe
|
void HCI_event_task(); // Poll the HCI event pipe
|
||||||
|
|
12
PS4BT.cpp
12
PS4BT.cpp
|
@ -48,9 +48,9 @@ const uint8_t PS4_BUTTONS[] PROGMEM = {
|
||||||
|
|
||||||
/** Analog buttons on the controller */
|
/** Analog buttons on the controller */
|
||||||
const uint8_t PS4_ANALOG_BUTTONS[] PROGMEM = {
|
const uint8_t PS4_ANALOG_BUTTONS[] PROGMEM = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, // Skip UP_ANALOG, RIGHT_ANALOG, DOWN_ANALOG, LEFT_ANALOG, SELECT, L3, R3 and START
|
0, 0, 0, 0, 0, 0, 0, 0, // Skip UP, RIGHT, DOWN, LEFT, SHARE, OPTIONS, L3, and R3
|
||||||
0, // L2_ANALOG
|
0, // L2
|
||||||
1, // R2_ANALOG
|
1, // R2
|
||||||
};
|
};
|
||||||
|
|
||||||
bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) {
|
bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) {
|
||||||
|
@ -59,7 +59,7 @@ bool PS4BT::checkDpad(PS4Buttons ps4Buttons, DPADEnum b) {
|
||||||
|
|
||||||
bool PS4BT::getButtonPress(ButtonEnum b) {
|
bool PS4BT::getButtonPress(ButtonEnum b) {
|
||||||
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
|
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
|
||||||
if (b < 4) // Dpad
|
if (b <= LEFT) // Dpad
|
||||||
return checkDpad(ps4Data.btn, (DPADEnum)button);
|
return checkDpad(ps4Data.btn, (DPADEnum)button);
|
||||||
else {
|
else {
|
||||||
uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
|
uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
|
||||||
|
@ -70,7 +70,7 @@ bool PS4BT::getButtonPress(ButtonEnum b) {
|
||||||
|
|
||||||
bool PS4BT::getButtonClick(ButtonEnum b) {
|
bool PS4BT::getButtonClick(ButtonEnum b) {
|
||||||
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
|
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
|
||||||
if (b < 4) { // Dpad
|
if (b <= LEFT) { // Dpad
|
||||||
if (checkDpad(buttonClickState, (DPADEnum)button)) {
|
if (checkDpad(buttonClickState, (DPADEnum)button)) {
|
||||||
buttonClickState.dpad = DPAD_OFF;
|
buttonClickState.dpad = DPAD_OFF;
|
||||||
return true;
|
return true;
|
||||||
|
@ -87,7 +87,7 @@ bool PS4BT::getButtonClick(ButtonEnum b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t PS4BT::getAnalogButton(ButtonEnum a) {
|
uint8_t PS4BT::getAnalogButton(ButtonEnum a) {
|
||||||
return (uint8_t)(ps4Data.trigger[pgm_read_byte(&PS4_ANALOG_BUTTONS[(uint8_t)a])]);
|
return ps4Data.trigger[pgm_read_byte(&PS4_ANALOG_BUTTONS[(uint8_t)a])];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t PS4BT::getAnalogHat(AnalogHatEnum a) {
|
uint8_t PS4BT::getAnalogHat(AnalogHatEnum a) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
||||||
/* You can create the instance of the class in two ways */
|
/* You can create the instance of the class in two ways */
|
||||||
// This will start an inquiry and then pair with your device - you only have to do this once
|
// This will start an inquiry and then pair with your device - you only have to do this once
|
||||||
// If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter
|
// If you are using a Bluetooth keyboard, then you should type in the password on the keypad and then press enter
|
||||||
BTHID hid(&Btd, PAIR, "0000");
|
BTHID bthid(&Btd, PAIR, "0000");
|
||||||
|
|
||||||
// After that you can simply create the instance like so and then press any button on the device
|
// After that you can simply create the instance like so and then press any button on the device
|
||||||
//BTHID hid(&Btd);
|
//BTHID hid(&Btd);
|
||||||
|
@ -36,13 +36,13 @@ void setup() {
|
||||||
while (1); // Halt
|
while (1); // Halt
|
||||||
}
|
}
|
||||||
|
|
||||||
hid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
|
bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs);
|
||||||
hid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
|
bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs);
|
||||||
|
|
||||||
// If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
|
// If "Boot Protocol Mode" does not work, then try "Report Protocol Mode"
|
||||||
// If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
|
// If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report
|
||||||
hid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
|
bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode
|
||||||
//hid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
|
//bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode
|
||||||
|
|
||||||
Serial.print(F("\r\nHID Bluetooth Library Started"));
|
Serial.print(F("\r\nHID Bluetooth Library Started"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ USB Usb;
|
||||||
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
||||||
/* You can create the instance of the class in two ways */
|
/* You can create the instance of the class in two ways */
|
||||||
PS3BT PS3(&Btd); // This will just create the instance
|
PS3BT PS3(&Btd); // This will just create the instance
|
||||||
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
//PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
||||||
|
|
||||||
boolean printTemperature;
|
boolean printTemperature;
|
||||||
boolean printAngle;
|
boolean printAngle;
|
||||||
|
@ -52,7 +52,7 @@ void loop() {
|
||||||
if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
|
if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
|
||||||
Serial.print(F("\r\nL2: "));
|
Serial.print(F("\r\nL2: "));
|
||||||
Serial.print(PS3.getAnalogButton(L2));
|
Serial.print(PS3.getAnalogButton(L2));
|
||||||
if (!PS3.PS3NavigationConnected) {
|
if (PS3.PS3Connected) {
|
||||||
Serial.print(F("\tR2: "));
|
Serial.print(F("\tR2: "));
|
||||||
Serial.print(PS3.getAnalogButton(R2));
|
Serial.print(PS3.getAnalogButton(R2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ void loop() {
|
||||||
if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
|
if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
|
||||||
Serial.print(F("\r\nL2: "));
|
Serial.print(F("\r\nL2: "));
|
||||||
Serial.print(PS3[i]->getAnalogButton(L2));
|
Serial.print(PS3[i]->getAnalogButton(L2));
|
||||||
if (!PS3[i]->PS3NavigationConnected) {
|
if (PS3[i]->PS3Connected) {
|
||||||
Serial.print(F("\tR2: "));
|
Serial.print(F("\tR2: "));
|
||||||
Serial.print(PS3[i]->getAnalogButton(R2));
|
Serial.print(PS3[i]->getAnalogButton(R2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
||||||
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
|
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
|
||||||
//SPP SerialBTBT(&Btd,"Lauszus's Arduino","0000"); // You can also set the name and pin like so
|
//SPP SerialBTBT(&Btd,"Lauszus's Arduino","0000"); // You can also set the name and pin like so
|
||||||
PS3BT PS3(&Btd); // This will just create the instance
|
PS3BT PS3(&Btd); // This will just create the instance
|
||||||
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
//PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
||||||
|
|
||||||
boolean firstMessage = true;
|
boolean firstMessage = true;
|
||||||
String output = ""; // We will store the data in this string
|
String output = ""; // We will store the data in this string
|
||||||
|
@ -77,7 +77,7 @@ void loop() {
|
||||||
output += "\r\n";
|
output += "\r\n";
|
||||||
output += "L2: ";
|
output += "L2: ";
|
||||||
output += PS3.getAnalogButton(L2);
|
output += PS3.getAnalogButton(L2);
|
||||||
if (!PS3.PS3NavigationConnected) {
|
if (PS3.PS3Connected) {
|
||||||
output += "\tR2: ";
|
output += "\tR2: ";
|
||||||
output += PS3.getAnalogButton(R2);
|
output += PS3.getAnalogButton(R2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
|
||||||
|
|
||||||
/* You can create the instance of the BTHID class in two ways */
|
/* You can create the instance of the BTHID class in two ways */
|
||||||
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
|
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
|
||||||
|
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode
|
||||||
BTHID bthid(&Btd, PAIR);
|
BTHID bthid(&Btd, PAIR);
|
||||||
|
|
||||||
// After that you can simply create the instance like so and then press the PS button on the device
|
// After that you can simply create the instance like so and then press the PS button on the device
|
||||||
|
|
Loading…
Reference in a new issue