ソースを参照

Psuedo rebase in our Multi BT branch to current master sources

This is from our WIP2 Bluetooth branch which is about a year out of date.

I copied files to other location, then created this branch and used WinMerge to merge in all related changes,

Without hopefully undoing any of the other changes
main
Kurt Eckhardt 4年前
コミット
a965e9238e
6個のファイルの変更652行の追加130行の削除
  1. +28
    -12
      USBHost_t36.h
  2. +153
    -115
      bluetooth.cpp
  3. +453
    -0
      examples/Bluetooth/Mouse_KeyboardBT/Mouse_KeyboardBT.ino
  4. +5
    -0
      joystick.cpp
  5. +9
    -2
      keyboard.cpp
  6. +4
    -1
      mouse.cpp

+ 28
- 12
USBHost_t36.h ファイルの表示

@@ -57,7 +57,7 @@
// your best effort to read chapter 4 before asking USB questions!


//#define USBHOST_PRINT_DEBUG
#define USBHOST_PRINT_DEBUG
//#define USBHDBGSerial Serial1

#ifndef USBHDBGSerial
@@ -1718,6 +1718,26 @@ private:

class BluetoothController: public USBDriver {
public:
static const uint8_t MAX_CONNECTIONS = 4;
typedef struct {
BTHIDInput * device_driver_ = nullptr;;
uint16_t connection_rxid_ = 0;
uint16_t control_dcid_ = 0x70;
uint16_t interrupt_dcid_ = 0x71;
uint16_t interrupt_scid_;
uint16_t control_scid_;

uint8_t device_bdaddr_[6];// remember devices address
uint8_t device_ps_repetion_mode_ ; // mode
uint8_t device_clock_offset_[2];
uint32_t device_class_; // class of device.
uint16_t device_connection_handle_; // handle to connection
uint8_t remote_ver_;
uint16_t remote_man_;
uint8_t remote_subv_;
uint8_t connection_complete_ = false; //
} connection_info_t;

BluetoothController(USBHost &host, bool pair = false, const char *pin = "0000") : do_pair_device_(pair), pair_pincode_(pin), delayTimer_(this)
{ init(); }

@@ -1740,12 +1760,18 @@ protected:
BTHIDInput * find_driver(uint32_t device_type, uint8_t *remoteName=nullptr);

// Hack to allow PS3 to maybe change values
uint16_t next_dcid_ = 0x70; // Lets try not hard coding control and interrupt dcid
#if 0
uint16_t connection_rxid_ = 0;
uint16_t control_dcid_ = 0x70;
uint16_t interrupt_dcid_ = 0x71;
uint16_t interrupt_scid_;
uint16_t control_scid_;

#else
connection_info_t connections_[MAX_CONNECTIONS];
uint8_t count_connections_ = 0;
uint8_t current_connection_ = 0; // need to figure out when this changes and/or...
#endif

private:
friend class BTHIDInput;
@@ -1835,16 +1861,6 @@ private:
USBDriverTimer delayTimer_;
uint8_t my_bdaddr_[6]; // The bluetooth dongles Bluetooth address.
uint8_t features[8]; // remember our local features.
BTHIDInput * device_driver_ = nullptr;;
uint8_t device_bdaddr_[6];// remember devices address
uint8_t device_ps_repetion_mode_ ; // mode
uint8_t device_clock_offset_[2];
uint32_t device_class_; // class of device.
uint16_t device_connection_handle_; // handle to connection
uint8_t remote_ver_;
uint16_t remote_man_;
uint8_t remote_subv_;
uint8_t connection_complete_ = false; //

typedef struct {
uint16_t idVendor;

+ 153
- 115
bluetooth.cpp ファイルの表示

@@ -30,8 +30,8 @@
#define print USBHost::print_
#define println USBHost::println_//#define DEBUG_BT

//#define DEBUG_BT
//#define DEBUG_BT_VERBOSE
#define DEBUG_BT
#define DEBUG_BT_VERBOSE

#ifndef DEBUG_BT
#undef DEBUG_BT_VERBOSE
@@ -320,12 +320,12 @@ bool BluetoothController::claim(Device_t *dev, int type, const uint8_t *descript
void BluetoothController::disconnect()
{
USBHDBGSerial.printf("Bluetooth Disconnect");
if (device_driver_) {
device_driver_->release_bluetooth();
device_driver_->remote_name_[0] = 0;
device_driver_ = nullptr;
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_->remote_name_[0] = 0;
connections_[current_connection_].device_driver_ = nullptr;
}
connection_complete_ = false;
connections_[current_connection_].connection_complete_ = false;
}

void BluetoothController::timer_event(USBDriverTimer *whichTimer)
@@ -555,9 +555,9 @@ void BluetoothController::handle_hci_command_complete()
case HCI_WRITE_SCAN_ENABLE: //0x0c1a
DBGPrintf("Write_Scan_enable Completed\n");
// See if we have driver and a remote
if (device_driver_ && connection_complete_) { // We have a driver call their
device_driver_->connectionComplete();
connection_complete_ = false; // only call once
if (connections_[current_connection_].device_driver_ && connections_[current_connection_].connection_complete_) { // We have a driver call their
connections_[current_connection_].device_driver_->connectionComplete();
connections_[current_connection_].connection_complete_ = false; // only call once
}
break;
case HCI_WRITE_SSP_MODE: //0x0c56
@@ -638,9 +638,9 @@ void BluetoothController::queue_next_hci_command()
void BluetoothController::handle_hci_command_status()
{
// <event type><param count><status><num packets allowed to be sent><CMD><CMD>
#ifdef DEBUG_BT
uint16_t hci_command = rxbuf_[4] + (rxbuf_[5] << 8);
if (rxbuf_[2]) {
#ifdef DEBUG_BT
DBGPrintf(" Command %x Status %x - ", hci_command, rxbuf_[2]);
switch (rxbuf_[2]) {
case 0x01: DBGPrintf("Unknown HCI Command\n"); break;
@@ -660,10 +660,23 @@ void BluetoothController::handle_hci_command_status()
case 0x0F: DBGPrintf("Connection Rejected due to Unacceptable BD_ADDR\n"); break;
default: DBGPrintf("???\n"); break;
}
#endif
// lets try recovering from some errors...
switch (hci_command) {
case HCI_OP_ACCEPT_CONN_REQ:
// We assume that the connection failed...
DBGPrintf("### Connection Failed ###");
if (count_connections_) count_connections_--;
break;
default:
break;
}

} else {
#ifdef DEBUG_BT
VDBGPrintf(" Command %x Status %x\n", hci_command, rxbuf_[2]);
#endif
}
#endif
}

void BluetoothController::handle_hci_inquiry_result(bool fRSSI)
@@ -704,13 +717,13 @@ void BluetoothController::handle_hci_inquiry_result(bool fRSSI)
}

// BUGBUG, lets hard code to go to new state...
for (uint8_t i = 0; i < 6; i++) device_bdaddr_[i] = rxbuf_[index_bd+i];
device_class_ = bluetooth_class;
device_driver_ = find_driver(device_class_);
for (uint8_t i = 0; i < 6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[index_bd+i];
connections_[current_connection_].device_class_ = bluetooth_class;
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_);

device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
device_clock_offset_[0] = rxbuf_[index_clock_offset];
device_clock_offset_[1] = rxbuf_[index_clock_offset+1];
connections_[current_connection_].device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
connections_[current_connection_].device_clock_offset_[0] = rxbuf_[index_clock_offset];
connections_[current_connection_].device_clock_offset_[1] = rxbuf_[index_clock_offset+1];

// Now we need to bail from inquiry and setup to try to connect...
sendHCIInquiryCancel();
@@ -768,22 +781,22 @@ void BluetoothController::handle_hci_extended_inquiry_result()
}

// BUGBUG, lets hard code to go to new state...
for (uint8_t i = 0; i < 6; i++) device_bdaddr_[i] = rxbuf_[index_bd+i];
device_class_ = bluetooth_class;
device_driver_ = find_driver(device_class_, index_local_name? &rxbuf_[index_local_name] : nullptr);
for (uint8_t i = 0; i < 6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[index_bd+i];
connections_[current_connection_].device_class_ = bluetooth_class;
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_, index_local_name? &rxbuf_[index_local_name] : nullptr);

device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
device_clock_offset_[0] = rxbuf_[index_clock_offset];
device_clock_offset_[1] = rxbuf_[index_clock_offset+1];
connections_[current_connection_].device_ps_repetion_mode_ = rxbuf_[index_ps]; // mode
connections_[current_connection_].device_clock_offset_[0] = rxbuf_[index_clock_offset];
connections_[current_connection_].device_clock_offset_[1] = rxbuf_[index_clock_offset+1];

// and if we found a driver, save away the name
if (device_driver_ && index_local_name && size_local_name) {
if (connections_[current_connection_].device_driver_ && index_local_name && size_local_name) {
uint8_t buffer_index;
for (buffer_index = 0; size_local_name && (buffer_index < BTHIDInput::REMOTE_NAME_SIZE-1); buffer_index++) {
device_driver_->remote_name_[buffer_index] = rxbuf_[index_local_name+buffer_index];
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = rxbuf_[index_local_name+buffer_index];
size_local_name--;
}
device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated
}

// Now we need to bail from inquiry and setup to try to connect...
@@ -800,16 +813,16 @@ void BluetoothController::handle_hci_connection_complete() {
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// ST CH CH BD BD BD BD BD BD LT EN
// 03 0b 04 00 00 40 25 00 58 4b 00 01 00
device_connection_handle_ = rxbuf_[3]+ (uint16_t)(rxbuf_[4]<<8);
DBGPrintf(" Connection Complete - ST:%x LH:%x\n", rxbuf_[2], device_connection_handle_);
if (do_pair_device_ && !(device_driver_ && (device_driver_->special_process_required & BTHIDInput::SP_DONT_NEED_CONNECT))) {
connections_[current_connection_].device_connection_handle_ = rxbuf_[3]+ (uint16_t)(rxbuf_[4]<<8);
DBGPrintf(" Connection Complete - ST:%x LH:%x\n", rxbuf_[2], connections_[current_connection_].device_connection_handle_);
if (do_pair_device_ && !(connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_DONT_NEED_CONNECT))) {
sendHCIAuthenticationRequested();
pending_control_ = PC_AUTHENTICATION_REQUESTED;
} else if (device_driver_ && (device_driver_->special_process_required & BTHIDInput::SP_NEED_CONNECT)) {
} else if (connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_NEED_CONNECT)) {
DBGPrintf(" Needs connect to device(PS4?)\n");
// The PS4 requires a connection request to it.
delay(1);
sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, control_dcid_, HID_CTRL_PSM);
sendl2cap_ConnectionRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_dcid_, HID_CTRL_PSM);
#if 0
delay(1);
@@ -838,11 +851,13 @@ void BluetoothController::handle_hci_incoming_connect() {
case 8: DBGPrintf(" Gamepad\n"); break;
case 0xc: DBGPrintf(" Remote Control\n"); break;
}
device_driver_ = find_driver(class_of_device);
if (count_connections_ < MAX_CONNECTIONS) current_connection_ = count_connections_++;

connections_[current_connection_].device_driver_ = find_driver(class_of_device);

// We need to save away the BDADDR and class link type?
for(uint8_t i=0; i<6; i++) device_bdaddr_[i] = rxbuf_[i+2];
device_class_ = class_of_device;
for(uint8_t i=0; i<6; i++) connections_[current_connection_].device_bdaddr_[i] = rxbuf_[i+2];
connections_[current_connection_].device_class_ = class_of_device;
sendHCIRemoteNameRequest();
}

@@ -888,19 +903,31 @@ void BluetoothController::handle_hci_disconnect_complete()
//5 4 0 48 0 13
DBGPrintf(" Event: HCI Disconnect complete(%d): handle: %x, reason:%x\n", rxbuf_[2],
rxbuf_[3]+(rxbuf_[4]<<8), rxbuf_[5]);
if (device_driver_) {
device_driver_->release_bluetooth();
device_driver_->remote_name_[0] = 0;
device_driver_ = nullptr;
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_->remote_name_[0] = 0;
connections_[current_connection_].device_driver_ = nullptr;
// Restore to normal...
control_dcid_ = 0x70;
interrupt_dcid_ = 0x71;
connections_[current_connection_].control_dcid_ = 0x70;
connections_[current_connection_].interrupt_dcid_ = 0x71;
}
// Probably should clear out connection data.
device_connection_handle_ = 0;
device_class_ = 0;
memset(device_bdaddr_, 0, sizeof(device_bdaddr_));
#if 0
connections_[current_connection_].device_connection_handle_ = 0;
connections_[current_connection_].device_class_ = 0;
memset(connections_[current_connection_].device_bdaddr_, 0, sizeof(connections_[current_connection_].device_bdaddr_));
#endif
// Now we need to remove that item from our list of connections.
count_connections_--;
if (count_connections_ == 0) {
// reset the next connection counts back to initial states.
next_dcid_ = 0x70; // Lets try not hard coding control and interrupt dcid
}

for (uint8_t i = current_connection_; i < count_connections_; i++) connections_[i] = connections_[i+1];
current_connection_ = 0;

}

void BluetoothController::handle_hci_authentication_complete()
@@ -909,8 +936,8 @@ void BluetoothController::handle_hci_authentication_complete()
DBGPrintf(" Event: HCI Authentication complete(%d): handle: %x\n", rxbuf_[2],
rxbuf_[3]+(rxbuf_[4]<<8));
// Start up lcap connection...
connection_rxid_ = 0;
sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, control_dcid_, HID_CTRL_PSM);
connections_[current_connection_].connection_rxid_ = 0;
sendl2cap_ConnectionRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_dcid_, HID_CTRL_PSM);
}


@@ -925,41 +952,44 @@ void BluetoothController::handle_hci_remote_name_complete() {
DBGPrintf("\n");
}

if (device_driver_) {
if (!device_driver_->remoteNameComplete(&rxbuf_[9])) {
device_driver_->release_bluetooth();
device_driver_ = nullptr;
if (connections_[current_connection_].device_driver_) {
if (!connections_[current_connection_].device_driver_->remoteNameComplete(&rxbuf_[9])) {
connections_[current_connection_].device_driver_->release_bluetooth();
connections_[current_connection_].device_driver_ = nullptr;
}
}
if (!device_driver_) {
device_driver_ = find_driver(device_class_, &rxbuf_[9]);
if (!connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_ = find_driver(connections_[current_connection_].device_class_, &rxbuf_[9]);
// not sure I should call remote name again, but they already process...
if (device_driver_) {
device_driver_->remoteNameComplete(&rxbuf_[9]);
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->remoteNameComplete(&rxbuf_[9]);
}
}
if (device_driver_) {
if (connections_[current_connection_].device_driver_) {
// lets save away the string.
uint8_t buffer_index;
for (buffer_index = 0; buffer_index < BTHIDInput::REMOTE_NAME_SIZE-1; buffer_index++) {
device_driver_->remote_name_[buffer_index] = rxbuf_[9+buffer_index];
if (!device_driver_->remote_name_[buffer_index]) break;
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = rxbuf_[9+buffer_index];
if (!connections_[current_connection_].device_driver_->remote_name_[buffer_index]) break;
}
device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated
connections_[current_connection_].device_driver_->remote_name_[buffer_index] = 0; // make sure null terminated

if (device_driver_->special_process_required & BTHIDInput::SP_PS3_IDS) {
if (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_PS3_IDS) {
// Real hack see if PS3...
control_dcid_ = 0x40;
interrupt_dcid_ = 0x41;
connections_[current_connection_].control_dcid_ = 0x40;
connections_[current_connection_].interrupt_dcid_ = 0x41;
} else {
connections_[current_connection_].control_dcid_ = next_dcid_++;
connections_[current_connection_].interrupt_dcid_ = next_dcid_++;
}
}

// If we are in the connection complete mode, then this is a pairing state and needed to call
// get remote name later.
if (connection_complete_) {
if (device_driver_) { // We have a driver call their
device_driver_->connectionComplete();
connection_complete_ = false; // only call once
if (connections_[current_connection_].connection_complete_) {
if (connections_[current_connection_].device_driver_) { // We have a driver call their
connections_[current_connection_].device_driver_->connectionComplete();
connections_[current_connection_].connection_complete_ = false; // only call once
}
} else {
sendHCIAcceptConnectionRequest();
@@ -969,13 +999,13 @@ void BluetoothController::handle_hci_remote_name_complete() {
void BluetoothController::handle_hci_remote_version_information_complete() {
// STAT bd bd bd bd bd bd
//c 8 0 48 0 5 45 0 0 0
remote_ver_ = rxbuf_[6];
remote_man_ = rxbuf_[7]+((uint16_t)rxbuf_[8]<< 8);
remote_subv_ = rxbuf_[9];
connections_[current_connection_].remote_ver_ = rxbuf_[6];
connections_[current_connection_].remote_man_ = rxbuf_[7]+((uint16_t)rxbuf_[8]<< 8);
connections_[current_connection_].remote_subv_ = rxbuf_[9];
DBGPrintf(" Event: handle_hci_remote_version_information_complete(%d): ", rxbuf_[2]);
DBGPrintf(" Handle: %x, Ver:%x, Man: %x, SV: %x\n",
rxbuf_[3]+((uint16_t)rxbuf_[4]<< 8), remote_ver_, remote_man_, remote_subv_);
rxbuf_[3]+((uint16_t)rxbuf_[4]<< 8), connections_[current_connection_].remote_ver_, connections_[current_connection_].remote_man_, connections_[current_connection_].remote_subv_);
// Lets now try to accept the connection.
sendHCIAcceptConnectionRequest();
}
@@ -997,6 +1027,14 @@ void BluetoothController::rx2_data(const Transfer_t *transfer)
// uint16_t rsp_packet_length = buffer[10] + ((uint16_t)buffer[11]<<8);
if ((hci_length == (l2cap_length + 4)) /*&& (hci_length == (rsp_packet_length+8))*/) {
// All the lengths appear to be correct... need to do more...
// See if we should set the current_connection...
for (uint8_t i = 0; i < count_connections_; i++) {
//if (connections_[i].interrupt_dcid_ == buffer[6]) {
if (connections_[i].device_connection_handle_ == buffer[0]) {
current_connection_ = i;
break;
}
}
switch (buffer[8]) {
case L2CAP_CMD_CONNECTION_REQUEST:
process_l2cap_connection_request(&buffer[8]);
@@ -1089,10 +1127,10 @@ void BluetoothController::sendHCICreateConnection() {
//0x05 0x04 0x0D 0x79 0x22 0x23 0x0A 0xC5 0xCC 0x18 0xCC 0x01 0x00 0x00 0x00 0x00
// 05 04 0d 40 25 00 c4 01 00 18 cc 01 00 00 00 00

for (uint8_t i=0; i<6; i++) connection_data[i] = device_bdaddr_[i];
for (uint8_t i=0; i<6; i++) connection_data[i] = connections_[current_connection_].device_bdaddr_[i];
connection_data[6] = 0x18; //DM1/DH1
connection_data[7] = 0xcc; //
connection_data[8] = device_ps_repetion_mode_; // from device
connection_data[8] = connections_[current_connection_].device_ps_repetion_mode_; // from device
connection_data[9] = 0; //
connection_data[10] = 0; // clock offset
connection_data[11] = 0; // clock offset
@@ -1108,7 +1146,7 @@ void BluetoothController::sendHCIAcceptConnectionRequest() {
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// BD BD BD BD BD BD role
//0x79 0x22 0x23 0x0A 0xC5 0xCC 0x00
for (uint8_t i=0; i<6; i++) connection_data[i] = device_bdaddr_[i];
for (uint8_t i=0; i<6; i++) connection_data[i] = connections_[current_connection_].device_bdaddr_[i];
connection_data[6] = 0; // Role as master
sendHCICommand(HCI_OP_ACCEPT_CONN_REQ, sizeof(connection_data), connection_data);
}
@@ -1117,8 +1155,8 @@ void BluetoothController::sendHCIAcceptConnectionRequest() {
void BluetoothController::sendHCIAuthenticationRequested() {
DBGPrintf("HCI_AUTH_REQUESTED called (");
uint8_t connection_data[2];
connection_data[0] = device_connection_handle_ & 0xff;
connection_data[1] = (device_connection_handle_>>8) & 0xff;
connection_data[0] = connections_[current_connection_].device_connection_handle_ & 0xff;
connection_data[1] = (connections_[current_connection_].device_connection_handle_>>8) & 0xff;
sendHCICommand(HCI_AUTH_REQUESTED, sizeof(connection_data), connection_data);
}

@@ -1126,7 +1164,7 @@ void BluetoothController::sendHCIAuthenticationRequested() {
void BluetoothController::sendHCILinkKeyNegativeReply() {
DBGPrintf("HCI_LINK_KEY_NEG_REPLY called (");
uint8_t connection_data[6];
for (uint8_t i=0; i<6; i++) connection_data[i] = device_bdaddr_[i];
for (uint8_t i=0; i<6; i++) connection_data[i] = connections_[current_connection_].device_bdaddr_[i];
sendHCICommand(HCI_LINK_KEY_NEG_REPLY, sizeof(connection_data), connection_data);
}

@@ -1139,7 +1177,7 @@ void BluetoothController::sendHCIPinCodeReply() {
uint8_t connection_data[23];
uint8_t i;

for (i=0; i<6; i++) connection_data[i] = device_bdaddr_[i];
for (i=0; i<6; i++) connection_data[i] = connections_[current_connection_].device_bdaddr_[i];

for (i=0; pair_pincode_[i] !=0; i++) connection_data[7+i] = pair_pincode_[i];
connection_data[6] = i; // remember the length
@@ -1185,7 +1223,7 @@ void BluetoothController::sendHCIRemoteNameRequest() { // 0x0419

DBGPrintf("HCI_OP_REMOTE_NAME_REQ called (");
uint8_t connection_data[10];
for (uint8_t i=0; i<6; i++) connection_data[i] = device_bdaddr_[i];
for (uint8_t i=0; i<6; i++) connection_data[i] = connections_[current_connection_].device_bdaddr_[i];
connection_data[6] = 1; // page scan repeat mode...
connection_data[7] = 0; // 0
connection_data[8] = 0; // Clk offset
@@ -1199,8 +1237,8 @@ void BluetoothController::sendHCIRemoteVersionInfoRequest() { // 0x041D

DBGPrintf("HCI_OP_READ_REMOTE_VERSION_INFORMATION called (");
uint8_t connection_data[2];
connection_data[0] = device_connection_handle_ & 0xff;
connection_data[1] = (device_connection_handle_>>8) & 0xff;
connection_data[0] = connections_[current_connection_].device_connection_handle_ & 0xff;
connection_data[1] = (connections_[current_connection_].device_connection_handle_>>8) & 0xff;
sendHCICommand(HCI_OP_READ_REMOTE_VERSION_INFORMATION, sizeof(connection_data), connection_data);
}

@@ -1296,30 +1334,30 @@ void BluetoothController::tx_data(const Transfer_t *transfer)
switch (pending_control_tx_) {
case STATE_TX_SEND_CONNECT_INT:
delay(1);
connection_rxid_++;
sendl2cap_ConnectionRequest(device_connection_handle_, connection_rxid_, interrupt_dcid_, HID_INTR_PSM);
connections_[current_connection_].connection_rxid_++;
sendl2cap_ConnectionRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].interrupt_dcid_, HID_INTR_PSM);
pending_control_tx_ = 0;
break;
case STATE_TX_SEND_CONECT_RSP_SUCCESS:
delay(1);
// Tell the device we are ready
sendl2cap_ConnectionResponse(device_connection_handle_, connection_rxid_++, control_dcid_, control_scid_, SUCCESSFUL);
sendl2cap_ConnectionResponse(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_++, connections_[current_connection_].control_dcid_, connections_[current_connection_].control_scid_, SUCCESSFUL);
pending_control_tx_ = STATE_TX_SEND_CONFIG_REQ;
break;
case STATE_TX_SEND_CONFIG_REQ:
delay(1);
sendl2cap_ConfigRequest(device_connection_handle_, connection_rxid_, control_scid_);
sendl2cap_ConfigRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_scid_);
pending_control_tx_ = 0;
break;
case STATE_TX_SEND_CONECT_ISR_RSP_SUCCESS:
delay(1);
// Tell the device we are ready
sendl2cap_ConnectionResponse(device_connection_handle_, connection_rxid_++, interrupt_dcid_, interrupt_scid_, SUCCESSFUL);
sendl2cap_ConnectionResponse(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_++, connections_[current_connection_].interrupt_dcid_, connections_[current_connection_].interrupt_scid_, SUCCESSFUL);
pending_control_tx_ = STATE_TX_SEND_CONFIG_ISR_REQ;
break;
case STATE_TX_SEND_CONFIG_ISR_REQ:
delay(1);
sendl2cap_ConfigRequest(device_connection_handle_, connection_rxid_, interrupt_scid_);
sendl2cap_ConfigRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].interrupt_scid_);
pending_control_tx_ = 0;
break;
}
@@ -1341,16 +1379,16 @@ void BluetoothController::sendL2CapCommand(uint8_t* data, uint8_t nbytes, int ch
uint16_t channel_out;
switch (channel) {
case CONTROL_SCID:
channel_out = control_scid_;
channel_out = connections_[current_connection_].control_scid_;
break;
case INTERRUPT_SCID:
channel_out = interrupt_scid_;
channel_out = connections_[current_connection_].interrupt_scid_;
break;
default:
channel_out = (uint16_t)channel;
}
DBGPrintf("sendL2CapCommand: %x %d %x\n", (uint32_t)data, nbytes, channel, channel_out);
sendL2CapCommand (device_connection_handle_, data, nbytes, channel_out & 0xff, (channel_out >> 8) & 0xff);
sendL2CapCommand (connections_[current_connection_].device_connection_handle_, data, nbytes, channel_out & 0xff, (channel_out >> 8) & 0xff);
}


@@ -1382,19 +1420,19 @@ void BluetoothController::process_l2cap_connection_request(uint8_t *data) {

uint16_t psm = data[4]+((uint16_t)data[5] << 8);
uint16_t scid = data[6]+((uint16_t)data[7] << 8);
connection_rxid_ = data[1];
DBGPrintf(" L2CAP Connection Request: ID: %d, PSM: %x, SCID: %x\n",connection_rxid_, psm, scid);
connections_[current_connection_].connection_rxid_ = data[1];
DBGPrintf(" L2CAP Connection Request: ID: %d, PSM: %x, SCID: %x\n",connections_[current_connection_].connection_rxid_, psm, scid);

// Assuming not pair mode Send response like:
// RXID Len LEN DCID DCID SCID SCID RES 0 0 0
// 0x03 0x02 0x08 0x00 0x70 0x00 0x43 0x00 0x01 0x00 0x00 0x00
if (psm == HID_CTRL_PSM) {
control_scid_ = scid;
sendl2cap_ConnectionResponse(device_connection_handle_, connection_rxid_, control_dcid_, control_scid_, PENDING);
connections_[current_connection_].control_scid_ = scid;
sendl2cap_ConnectionResponse(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].control_dcid_, connections_[current_connection_].control_scid_, PENDING);
pending_control_tx_ = STATE_TX_SEND_CONECT_RSP_SUCCESS;
} else if (psm == HID_INTR_PSM) {
interrupt_scid_ = scid;
sendl2cap_ConnectionResponse(device_connection_handle_, connection_rxid_, interrupt_dcid_, interrupt_scid_, PENDING);
connections_[current_connection_].interrupt_scid_ = scid;
sendl2cap_ConnectionResponse(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, connections_[current_connection_].interrupt_dcid_, connections_[current_connection_].interrupt_scid_, PENDING);
pending_control_tx_ = STATE_TX_SEND_CONECT_ISR_RSP_SUCCESS;

}
@@ -1411,15 +1449,15 @@ void BluetoothController::process_l2cap_connection_response(uint8_t *data) {
data[8]+((uint16_t)data[9] << 8), data[10]+((uint16_t)data[11] << 8));

//48 20 10 0 | c 0 1 0 | 3 0 8 0 44 0 70 0 0 0 0 0
if (dcid == interrupt_dcid_) {
interrupt_scid_ = scid;
if (dcid == connections_[current_connection_].interrupt_dcid_) {
connections_[current_connection_].interrupt_scid_ = scid;
DBGPrintf(" Interrupt Response\n");
connection_rxid_++;
sendl2cap_ConfigRequest(device_connection_handle_, connection_rxid_, scid);
} else if (dcid == control_dcid_) {
control_scid_ = scid;
connections_[current_connection_].connection_rxid_++;
sendl2cap_ConfigRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, scid);
} else if (dcid == connections_[current_connection_].control_dcid_) {
connections_[current_connection_].control_scid_ = scid;
DBGPrintf(" Control Response\n");
sendl2cap_ConfigRequest(device_connection_handle_, connection_rxid_, scid);
sendl2cap_ConfigRequest(connections_[current_connection_].device_connection_handle_, connections_[current_connection_].connection_rxid_, scid);
}
}

@@ -1430,12 +1468,12 @@ void BluetoothController::process_l2cap_config_request(uint8_t *data) {
data[1], dcid, data[6]+((uint16_t)data[7] << 8),
data[8], data[9], data[10], data[11]);
// Now see which dest was specified
if (dcid == control_dcid_) {
if (dcid == connections_[current_connection_].control_dcid_) {
DBGPrintf(" Control Configuration request\n");
sendl2cap_ConfigResponse(device_connection_handle_, data[1], control_scid_);
} else if (dcid == interrupt_dcid_) {
sendl2cap_ConfigResponse(connections_[current_connection_].device_connection_handle_, data[1], connections_[current_connection_].control_scid_);
} else if (dcid == connections_[current_connection_].interrupt_dcid_) {
DBGPrintf(" Interrupt Configuration request\n");
sendl2cap_ConfigResponse(device_connection_handle_, data[1], interrupt_scid_);
sendl2cap_ConfigResponse(connections_[current_connection_].device_connection_handle_, data[1], connections_[current_connection_].interrupt_scid_);
}
}

@@ -1445,25 +1483,25 @@ void BluetoothController::process_l2cap_config_response(uint8_t *data) {
DBGPrintf(" L2CAP config Response: ID: %d, Source:%x, Flags:%x, Result:%x, Config: %x\n",
data[1], scid, data[6]+((uint16_t)data[7] << 8),
data[8]+((uint16_t)data[9] << 8), data[10]+((uint16_t)data[11] << 8));
if (scid == control_dcid_) {
if (scid == connections_[current_connection_].control_dcid_) {
// Set HID Boot mode
// Don't do if PS3...
if (!(device_driver_->special_process_required & BTHIDInput::SP_PS3_IDS)) {
if (!(connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_PS3_IDS)) {
setHIDProtocol(HID_BOOT_PROTOCOL); //
}
//setHIDProtocol(HID_RPT_PROTOCOL); //HID_RPT_PROTOCOL
if (do_pair_device_ && !(device_driver_ && (device_driver_->special_process_required & BTHIDInput::SP_DONT_NEED_CONNECT))) {
if (do_pair_device_ && !(connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_DONT_NEED_CONNECT))) {
pending_control_tx_ = STATE_TX_SEND_CONNECT_INT;
} else if (device_driver_ && (device_driver_->special_process_required & BTHIDInput::SP_NEED_CONNECT)) {
} else if (connections_[current_connection_].device_driver_ && (connections_[current_connection_].device_driver_->special_process_required & BTHIDInput::SP_NEED_CONNECT)) {
DBGPrintf(" Needs connect to device INT(PS4?)\n");
// The PS4 requires a connection request to it.
pending_control_tx_ = STATE_TX_SEND_CONNECT_INT;
} else {
pending_control_ = 0;
}
} else if (scid == interrupt_dcid_) {
} else if (scid == connections_[current_connection_].interrupt_dcid_) {
// Enable SCan to page mode
connection_complete_ = true;
connections_[current_connection_].connection_complete_ = true;
sendHCIWriteScanEnable(2);
}
}
@@ -1488,7 +1526,7 @@ void BluetoothController::setHIDProtocol(uint8_t protocol) {
uint8_t l2capbuf[1];
l2capbuf[0] = 0x70 | protocol; // Set Protocol, see Bluetooth HID specs page 33
DBGPrintf("Set HID Protocol %d (", protocol);
sendL2CapCommand(device_connection_handle_, l2capbuf, sizeof(l2capbuf), control_scid_ & 0xff, control_scid_ >> 8);
sendL2CapCommand(connections_[current_connection_].device_connection_handle_, l2capbuf, sizeof(l2capbuf), connections_[current_connection_].control_scid_ & 0xff, connections_[current_connection_].control_scid_ >> 8);
}

void BluetoothController::handleHIDTHDRData(uint8_t *data) {
@@ -1496,11 +1534,11 @@ void BluetoothController::handleHIDTHDRData(uint8_t *data) {
// T HID data
//48 20 d 0 9 0 71 0 a1 3 8a cc c5 a 23 22 79
uint16_t len = data[4] + ((uint16_t)data[5] << 8);
DBGPrintf("HID HDR Data: len: %d, Type: %d\n", len, data[9]);
DBGPrintf("HID HDR Data: len: %d, Type: %d Con:%d\n", len, data[9], current_connection_);

// ??? How to parse??? Use HID object???
if (device_driver_) {
device_driver_->process_bluetooth_HID_data(&data[9], len-1); // We skip the first byte...
if (connections_[current_connection_].device_driver_) {
connections_[current_connection_].device_driver_->process_bluetooth_HID_data(&data[9], len-1); // We skip the first byte...
} else {
switch (data[9]) {
case 1:

+ 453
- 0
examples/Bluetooth/Mouse_KeyboardBT/Mouse_KeyboardBT.ino ファイルの表示

@@ -0,0 +1,453 @@
// Simple test of USB Host Mouse/Keyboard
//
// This example is in the public domain

#include "USBHost_t36.h"

USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
KeyboardController keyboard1(myusb);
//KeyboardController keyboard2(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
USBHIDParser hid4(myusb);
USBHIDParser hid5(myusb);
MouseController mouse1(myusb);
//JoystickController joystick1(myusb);
//BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device

BluetoothController bluet(myusb); // version assumes it already was paired

USBDriver *drivers[] = {&hub1, &hub2, &keyboard1, &bluet, &hid1, &hid2, &hid3, &hid4, &hid5};

#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "Hub2", "KB1", "Bluet", "HID1" , "HID2", "HID3", "HID4", "HID5"};

bool driver_active[CNT_DEVICES] = {false, false, false, false};

// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = {&mouse1};

#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_HIDDEVICES] = {"Mouse1"};

bool hid_driver_active[CNT_HIDDEVICES] = {false};

BTHIDInput *bthiddrivers[] = {&keyboard1, &mouse1};
#define CNT_BTHIDDEVICES (sizeof(bthiddrivers)/sizeof(bthiddrivers[0]))
const char * bthid_driver_names[CNT_BTHIDDEVICES] = {"Keyboard(BT)", "Mouse(BT)"};
bool bthid_driver_active[CNT_BTHIDDEVICES] = {false};



bool show_changed_only = false;

uint8_t joystick_left_trigger_value = 0;
uint8_t joystick_right_trigger_value = 0;
uint64_t joystick_full_notify_mask = (uint64_t) - 1;

void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.begin(115200);
Serial1.begin(115200);
Serial.println("\n\nUSB Host Testing");
Serial.println(sizeof(USBHub), DEC);
myusb.begin();
keyboard1.attachPress(OnPress);
//keyboard2.attachPress(OnPress);
keyboard1.attachExtrasPress(OnHIDExtrasPress);
keyboard1.attachExtrasRelease(OnHIDExtrasRelease);
//keyboard2.attachExtrasPress(OnHIDExtrasPress);
//keyboard2.attachExtrasRelease(OnHIDExtrasRelease);
}


void loop()
{
// check to see if the device list has changed:
UpdateActiveDeviceInfo();

myusb.Task();

if (mouse1.available()) {
Serial.print("Mouse: buttons = ");
Serial.print(mouse1.getButtons());
Serial.print(", mouseX = ");
Serial.print(mouse1.getMouseX());
Serial.print(", mouseY = ");
Serial.print(mouse1.getMouseY());
Serial.print(", wheel = ");
Serial.print(mouse1.getWheel());
Serial.print(", wheelH = ");
Serial.print(mouse1.getWheelH());
Serial.println();
mouse1.mouseDataClear();
}
}

void OnPress(int key)
{
Serial.print("key '");
switch (key) {
case KEYD_UP : Serial.print("UP"); break;
case KEYD_DOWN : Serial.print("DN"); break;
case KEYD_LEFT : Serial.print("LEFT"); break;
case KEYD_RIGHT : Serial.print("RIGHT"); break;
case KEYD_INSERT : Serial.print("Ins"); break;
case KEYD_DELETE : Serial.print("Del"); break;
case KEYD_PAGE_UP : Serial.print("PUP"); break;
case KEYD_PAGE_DOWN: Serial.print("PDN"); break;
case KEYD_HOME : Serial.print("HOME"); break;
case KEYD_END : Serial.print("END"); break;
case KEYD_F1 : Serial.print("F1"); break;
case KEYD_F2 : Serial.print("F2"); break;
case KEYD_F3 : Serial.print("F3"); break;
case KEYD_F4 : Serial.print("F4"); break;
case KEYD_F5 : Serial.print("F5"); break;
case KEYD_F6 : Serial.print("F6"); break;
case KEYD_F7 : Serial.print("F7"); break;
case KEYD_F8 : Serial.print("F8"); break;
case KEYD_F9 : Serial.print("F9"); break;
case KEYD_F10 : Serial.print("F10"); break;
case KEYD_F11 : Serial.print("F11"); break;
case KEYD_F12 : Serial.print("F12"); break;
default: Serial.print((char)key); break;
}
Serial.print("' ");
Serial.print(key);
Serial.print(" MOD: ");
if (keyboard1) {
Serial.print(keyboard1.getModifiers(), HEX);
Serial.print(" OEM: ");
Serial.print(keyboard1.getOemKey(), HEX);
Serial.print(" LEDS: ");
Serial.println(keyboard1.LEDS(), HEX);
//} else {
//Serial.print(keyboard2.getModifiers(), HEX);
//Serial.print(" OEM: ");
//Serial.print(keyboard2.getOemKey(), HEX);
//Serial.print(" LEDS: ");
//Serial.println(keyboard2.LEDS(), HEX);
}

//Serial.print("key ");
//Serial.print((char)keyboard1.getKey());
//Serial.print(" ");
//Serial.print((char)keyboard2.getKey());
//Serial.println();
}
void OnHIDExtrasPress(uint32_t top, uint16_t key)
{
Serial.print("HID (");
Serial.print(top, HEX);
Serial.print(") key press:");
Serial.print(key, HEX);
if (top == 0xc0000) {
switch (key) {
case 0x20 : Serial.print(" - +10"); break;
case 0x21 : Serial.print(" - +100"); break;
case 0x22 : Serial.print(" - AM/PM"); break;
case 0x30 : Serial.print(" - Power"); break;
case 0x31 : Serial.print(" - Reset"); break;
case 0x32 : Serial.print(" - Sleep"); break;
case 0x33 : Serial.print(" - Sleep After"); break;
case 0x34 : Serial.print(" - Sleep Mode"); break;
case 0x35 : Serial.print(" - Illumination"); break;
case 0x36 : Serial.print(" - Function Buttons"); break;
case 0x40 : Serial.print(" - Menu"); break;
case 0x41 : Serial.print(" - Menu Pick"); break;
case 0x42 : Serial.print(" - Menu Up"); break;
case 0x43 : Serial.print(" - Menu Down"); break;
case 0x44 : Serial.print(" - Menu Left"); break;
case 0x45 : Serial.print(" - Menu Right"); break;
case 0x46 : Serial.print(" - Menu Escape"); break;
case 0x47 : Serial.print(" - Menu Value Increase"); break;
case 0x48 : Serial.print(" - Menu Value Decrease"); break;
case 0x60 : Serial.print(" - Data On Screen"); break;
case 0x61 : Serial.print(" - Closed Caption"); break;
case 0x62 : Serial.print(" - Closed Caption Select"); break;
case 0x63 : Serial.print(" - VCR/TV"); break;
case 0x64 : Serial.print(" - Broadcast Mode"); break;
case 0x65 : Serial.print(" - Snapshot"); break;
case 0x66 : Serial.print(" - Still"); break;
case 0x80 : Serial.print(" - Selection"); break;
case 0x81 : Serial.print(" - Assign Selection"); break;
case 0x82 : Serial.print(" - Mode Step"); break;
case 0x83 : Serial.print(" - Recall Last"); break;
case 0x84 : Serial.print(" - Enter Channel"); break;
case 0x85 : Serial.print(" - Order Movie"); break;
case 0x86 : Serial.print(" - Channel"); break;
case 0x87 : Serial.print(" - Media Selection"); break;
case 0x88 : Serial.print(" - Media Select Computer"); break;
case 0x89 : Serial.print(" - Media Select TV"); break;
case 0x8A : Serial.print(" - Media Select WWW"); break;
case 0x8B : Serial.print(" - Media Select DVD"); break;
case 0x8C : Serial.print(" - Media Select Telephone"); break;
case 0x8D : Serial.print(" - Media Select Program Guide"); break;
case 0x8E : Serial.print(" - Media Select Video Phone"); break;
case 0x8F : Serial.print(" - Media Select Games"); break;
case 0x90 : Serial.print(" - Media Select Messages"); break;
case 0x91 : Serial.print(" - Media Select CD"); break;
case 0x92 : Serial.print(" - Media Select VCR"); break;
case 0x93 : Serial.print(" - Media Select Tuner"); break;
case 0x94 : Serial.print(" - Quit"); break;
case 0x95 : Serial.print(" - Help"); break;
case 0x96 : Serial.print(" - Media Select Tape"); break;
case 0x97 : Serial.print(" - Media Select Cable"); break;
case 0x98 : Serial.print(" - Media Select Satellite"); break;
case 0x99 : Serial.print(" - Media Select Security"); break;
case 0x9A : Serial.print(" - Media Select Home"); break;
case 0x9B : Serial.print(" - Media Select Call"); break;
case 0x9C : Serial.print(" - Channel Increment"); break;
case 0x9D : Serial.print(" - Channel Decrement"); break;
case 0x9E : Serial.print(" - Media Select SAP"); break;
case 0xA0 : Serial.print(" - VCR Plus"); break;
case 0xA1 : Serial.print(" - Once"); break;
case 0xA2 : Serial.print(" - Daily"); break;
case 0xA3 : Serial.print(" - Weekly"); break;
case 0xA4 : Serial.print(" - Monthly"); break;
case 0xB0 : Serial.print(" - Play"); break;
case 0xB1 : Serial.print(" - Pause"); break;
case 0xB2 : Serial.print(" - Record"); break;
case 0xB3 : Serial.print(" - Fast Forward"); break;
case 0xB4 : Serial.print(" - Rewind"); break;
case 0xB5 : Serial.print(" - Scan Next Track"); break;
case 0xB6 : Serial.print(" - Scan Previous Track"); break;
case 0xB7 : Serial.print(" - Stop"); break;
case 0xB8 : Serial.print(" - Eject"); break;
case 0xB9 : Serial.print(" - Random Play"); break;
case 0xBA : Serial.print(" - Select DisC"); break;
case 0xBB : Serial.print(" - Enter Disc"); break;
case 0xBC : Serial.print(" - Repeat"); break;
case 0xBD : Serial.print(" - Tracking"); break;
case 0xBE : Serial.print(" - Track Normal"); break;
case 0xBF : Serial.print(" - Slow Tracking"); break;
case 0xC0 : Serial.print(" - Frame Forward"); break;
case 0xC1 : Serial.print(" - Frame Back"); break;
case 0xC2 : Serial.print(" - Mark"); break;
case 0xC3 : Serial.print(" - Clear Mark"); break;
case 0xC4 : Serial.print(" - Repeat From Mark"); break;
case 0xC5 : Serial.print(" - Return To Mark"); break;
case 0xC6 : Serial.print(" - Search Mark Forward"); break;
case 0xC7 : Serial.print(" - Search Mark Backwards"); break;
case 0xC8 : Serial.print(" - Counter Reset"); break;
case 0xC9 : Serial.print(" - Show Counter"); break;
case 0xCA : Serial.print(" - Tracking Increment"); break;
case 0xCB : Serial.print(" - Tracking Decrement"); break;
case 0xCD : Serial.print(" - Pause/Continue"); break;
case 0xE0 : Serial.print(" - Volume"); break;
case 0xE1 : Serial.print(" - Balance"); break;
case 0xE2 : Serial.print(" - Mute"); break;
case 0xE3 : Serial.print(" - Bass"); break;
case 0xE4 : Serial.print(" - Treble"); break;
case 0xE5 : Serial.print(" - Bass Boost"); break;
case 0xE6 : Serial.print(" - Surround Mode"); break;
case 0xE7 : Serial.print(" - Loudness"); break;
case 0xE8 : Serial.print(" - MPX"); break;
case 0xE9 : Serial.print(" - Volume Up"); break;
case 0xEA : Serial.print(" - Volume Down"); break;
case 0xF0 : Serial.print(" - Speed Select"); break;
case 0xF1 : Serial.print(" - Playback Speed"); break;
case 0xF2 : Serial.print(" - Standard Play"); break;
case 0xF3 : Serial.print(" - Long Play"); break;
case 0xF4 : Serial.print(" - Extended Play"); break;
case 0xF5 : Serial.print(" - Slow"); break;
case 0x100: Serial.print(" - Fan Enable"); break;
case 0x101: Serial.print(" - Fan Speed"); break;
case 0x102: Serial.print(" - Light"); break;
case 0x103: Serial.print(" - Light Illumination Level"); break;
case 0x104: Serial.print(" - Climate Control Enable"); break;
case 0x105: Serial.print(" - Room Temperature"); break;
case 0x106: Serial.print(" - Security Enable"); break;
case 0x107: Serial.print(" - Fire Alarm"); break;
case 0x108: Serial.print(" - Police Alarm"); break;
case 0x150: Serial.print(" - Balance Right"); break;
case 0x151: Serial.print(" - Balance Left"); break;
case 0x152: Serial.print(" - Bass Increment"); break;
case 0x153: Serial.print(" - Bass Decrement"); break;
case 0x154: Serial.print(" - Treble Increment"); break;
case 0x155: Serial.print(" - Treble Decrement"); break;
case 0x160: Serial.print(" - Speaker System"); break;
case 0x161: Serial.print(" - Channel Left"); break;
case 0x162: Serial.print(" - Channel Right"); break;
case 0x163: Serial.print(" - Channel Center"); break;
case 0x164: Serial.print(" - Channel Front"); break;
case 0x165: Serial.print(" - Channel Center Front"); break;
case 0x166: Serial.print(" - Channel Side"); break;
case 0x167: Serial.print(" - Channel Surround"); break;
case 0x168: Serial.print(" - Channel Low Frequency Enhancement"); break;
case 0x169: Serial.print(" - Channel Top"); break;
case 0x16A: Serial.print(" - Channel Unknown"); break;
case 0x170: Serial.print(" - Sub-channel"); break;
case 0x171: Serial.print(" - Sub-channel Increment"); break;
case 0x172: Serial.print(" - Sub-channel Decrement"); break;
case 0x173: Serial.print(" - Alternate Audio Increment"); break;
case 0x174: Serial.print(" - Alternate Audio Decrement"); break;
case 0x180: Serial.print(" - Application Launch Buttons"); break;
case 0x181: Serial.print(" - AL Launch Button Configuration Tool"); break;
case 0x182: Serial.print(" - AL Programmable Button Configuration"); break;
case 0x183: Serial.print(" - AL Consumer Control Configuration"); break;
case 0x184: Serial.print(" - AL Word Processor"); break;
case 0x185: Serial.print(" - AL Text Editor"); break;
case 0x186: Serial.print(" - AL Spreadsheet"); break;
case 0x187: Serial.print(" - AL Graphics Editor"); break;
case 0x188: Serial.print(" - AL Presentation App"); break;
case 0x189: Serial.print(" - AL Database App"); break;
case 0x18A: Serial.print(" - AL Email Reader"); break;
case 0x18B: Serial.print(" - AL Newsreader"); break;
case 0x18C: Serial.print(" - AL Voicemail"); break;
case 0x18D: Serial.print(" - AL Contacts/Address Book"); break;
case 0x18E: Serial.print(" - AL Calendar/Schedule"); break;
case 0x18F: Serial.print(" - AL Task/Project Manager"); break;
case 0x190: Serial.print(" - AL Log/Journal/Timecard"); break;
case 0x191: Serial.print(" - AL Checkbook/Finance"); break;
case 0x192: Serial.print(" - AL Calculator"); break;
case 0x193: Serial.print(" - AL A/V Capture/Playback"); break;
case 0x194: Serial.print(" - AL Local Machine Browser"); break;
case 0x195: Serial.print(" - AL LAN/WAN Browser"); break;
case 0x196: Serial.print(" - AL Internet Browser"); break;
case 0x197: Serial.print(" - AL Remote Networking/ISP Connect"); break;
case 0x198: Serial.print(" - AL Network Conference"); break;
case 0x199: Serial.print(" - AL Network Chat"); break;
case 0x19A: Serial.print(" - AL Telephony/Dialer"); break;
case 0x19B: Serial.print(" - AL Logon"); break;
case 0x19C: Serial.print(" - AL Logoff"); break;
case 0x19D: Serial.print(" - AL Logon/Logoff"); break;
case 0x19E: Serial.print(" - AL Terminal Lock/Screensaver"); break;
case 0x19F: Serial.print(" - AL Control Panel"); break;
case 0x1A0: Serial.print(" - AL Command Line Processor/Run"); break;
case 0x1A1: Serial.print(" - AL Process/Task Manager"); break;
case 0x1A2: Serial.print(" - AL Select Tast/Application"); break;
case 0x1A3: Serial.print(" - AL Next Task/Application"); break;
case 0x1A4: Serial.print(" - AL Previous Task/Application"); break;
case 0x1A5: Serial.print(" - AL Preemptive Halt Task/Application"); break;
case 0x200: Serial.print(" - Generic GUI Application Controls"); break;
case 0x201: Serial.print(" - AC New"); break;
case 0x202: Serial.print(" - AC Open"); break;
case 0x203: Serial.print(" - AC Close"); break;
case 0x204: Serial.print(" - AC Exit"); break;
case 0x205: Serial.print(" - AC Maximize"); break;
case 0x206: Serial.print(" - AC Minimize"); break;
case 0x207: Serial.print(" - AC Save"); break;
case 0x208: Serial.print(" - AC Print"); break;
case 0x209: Serial.print(" - AC Properties"); break;
case 0x21A: Serial.print(" - AC Undo"); break;
case 0x21B: Serial.print(" - AC Copy"); break;
case 0x21C: Serial.print(" - AC Cut"); break;
case 0x21D: Serial.print(" - AC Paste"); break;
case 0x21E: Serial.print(" - AC Select All"); break;
case 0x21F: Serial.print(" - AC Find"); break;
case 0x220: Serial.print(" - AC Find and Replace"); break;
case 0x221: Serial.print(" - AC Search"); break;
case 0x222: Serial.print(" - AC Go To"); break;
case 0x223: Serial.print(" - AC Home"); break;
case 0x224: Serial.print(" - AC Back"); break;
case 0x225: Serial.print(" - AC Forward"); break;
case 0x226: Serial.print(" - AC Stop"); break;
case 0x227: Serial.print(" - AC Refresh"); break;
case 0x228: Serial.print(" - AC Previous Link"); break;
case 0x229: Serial.print(" - AC Next Link"); break;
case 0x22A: Serial.print(" - AC Bookmarks"); break;
case 0x22B: Serial.print(" - AC History"); break;
case 0x22C: Serial.print(" - AC Subscriptions"); break;
case 0x22D: Serial.print(" - AC Zoom In"); break;
case 0x22E: Serial.print(" - AC Zoom Out"); break;
case 0x22F: Serial.print(" - AC Zoom"); break;
case 0x230: Serial.print(" - AC Full Screen View"); break;
case 0x231: Serial.print(" - AC Normal View"); break;
case 0x232: Serial.print(" - AC View Toggle"); break;
case 0x233: Serial.print(" - AC Scroll Up"); break;
case 0x234: Serial.print(" - AC Scroll Down"); break;
case 0x235: Serial.print(" - AC Scroll"); break;
case 0x236: Serial.print(" - AC Pan Left"); break;
case 0x237: Serial.print(" - AC Pan Right"); break;
case 0x238: Serial.print(" - AC Pan"); break;
case 0x239: Serial.print(" - AC New Window"); break;
case 0x23A: Serial.print(" - AC Tile Horizontally"); break;
case 0x23B: Serial.print(" - AC Tile Vertically"); break;
case 0x23C: Serial.print(" - AC Format"); break;

}
}
Serial.println();
}

void OnHIDExtrasRelease(uint32_t top, uint16_t key)
{
Serial.print("HID (");
Serial.print(top, HEX);
Serial.print(") key release:");
Serial.println(key, HEX);
}

//=============================================================================
// UpdateActiveDeviceInfo
//=============================================================================
void UpdateActiveDeviceInfo() {
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;

const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);

if (drivers[i] == &bluet) {
const uint8_t *bdaddr = bluet.myBDAddr();
// remember it...
Serial.printf(" BDADDR: %x:%x:%x:%x:%x:%x\n", bdaddr[0], bdaddr[1], bdaddr[2], bdaddr[3], bdaddr[4], bdaddr[5]);
}
}
}
}
for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
if (*hiddrivers[i] != hid_driver_active[i]) {
if (hid_driver_active[i]) {
Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
hid_driver_active[i] = false;
} else {
Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
hid_driver_active[i] = true;

const uint8_t *psz = hiddrivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = hiddrivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = hiddrivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
}
}
}
// Then Bluetooth devices
for (uint8_t i = 0; i < CNT_BTHIDDEVICES; i++) {
if (*bthiddrivers[i] != bthid_driver_active[i]) {
if (bthid_driver_active[i]) {
Serial.printf("*** BTHID Device %s - disconnected ***\n", bthid_driver_names[i]);
bthid_driver_active[i] = false;
} else {
Serial.printf("*** BTHID Device %s - connected ***\n", bthid_driver_names[i]); Serial.flush();
bthid_driver_active[i] = true;
#if 0

const uint8_t *psz = bthiddrivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = bthiddrivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = bthiddrivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
#endif
}
}
}
}

+ 5
- 0
joystick.cpp ファイルの表示

@@ -738,6 +738,11 @@ void JoystickController::disconnect()

bool JoystickController::claim_bluetooth(BluetoothController *driver, uint32_t bluetooth_class, uint8_t *remoteName)
{
// If we are already in use than don't grab another one. Likewise don't grab if it is used as USB or HID object
if (btdevice && (btdevice != (Device_t*)driver)) return false;
if (mydevice != NULL) return false;
if (device != nullptr) return false;

if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && ((bluetooth_class & 0x3C) == 0x08)) {
DBGPrintf("JoystickController::claim_bluetooth TRUE\n");
btdriver_ = driver;

+ 9
- 2
keyboard.cpp ファイルの表示

@@ -521,13 +521,20 @@ void KeyboardController::hid_input_end()
bool KeyboardController::claim_bluetooth(BluetoothController *driver, uint32_t bluetooth_class, uint8_t *remoteName)
{
USBHDBGSerial.printf("Keyboard Controller::claim_bluetooth - Class %x\n", bluetooth_class);
// If we are already in use than don't grab another one. Likewise don't grab if it is used as USB or HID object
if (btdevice && (btdevice != (Device_t*)driver)) return false;
if (mydevice != NULL) return false;
if (device != nullptr) return false;

if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && (bluetooth_class & 0x40)) {
if (remoteName && (strncmp((const char *)remoteName, "PLAYSTATION(R)3", 15) == 0)) {
USBHDBGSerial.printf("KeyboardController::claim_bluetooth Reject PS3 hack\n");
btdevice = nullptr; // remember this way

return false;
}
USBHDBGSerial.printf("KeyboardController::claim_bluetooth TRUE\n");
//btdevice = driver;
btdevice = (Device_t*)driver; // remember this way
return true;
}
return false;
@@ -578,7 +585,7 @@ bool KeyboardController::process_bluetooth_HID_data(const uint8_t *data, uint16_

void KeyboardController::release_bluetooth()
{
//btdevice = nullptr;
btdevice = nullptr;
}

//*****************************************************************************

+ 4
- 1
mouse.cpp ファイルの表示

@@ -111,6 +111,9 @@ bool MouseController::claim_bluetooth(BluetoothController *driver, uint32_t blue
{
// How to handle combo devices?
USBHDBGSerial.printf("MouseController Controller::claim_bluetooth - Class %x\n", bluetooth_class);
// If we are already in use than don't grab another one. Likewise don't grab if it is used as USB or HID object
if (btdevice && (btdevice != (Device_t*)driver)) return false;
if (mydevice != NULL) return false;
if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && (bluetooth_class & 0x80)) {
USBHDBGSerial.printf("MouseController::claim_bluetooth TRUE\n");
btdevice = (Device_t*)driver; // remember this way
@@ -159,5 +162,5 @@ bool MouseController::process_bluetooth_HID_data(const uint8_t *data, uint16_t l

void MouseController::release_bluetooth()
{
//btdevice = nullptr;
btdevice = nullptr;
}

読み込み中…
キャンセル
保存