Переглянути джерело

WIP - a way for maybe joystick to call off to L2CAPCommand?

main
Kurt Eckhardt 5 роки тому
джерело
коміт
9d9ac92829
2 змінених файлів з 45 додано та 18 видалено
  1. +10
    -1
      USBHost_t36.h
  2. +35
    -17
      joystick.cpp

+ 10
- 1
USBHost_t36.h Переглянути файл

@@ -539,7 +539,6 @@ public:
{ return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_PROD]]; }
const uint8_t *serialNumber()
{ return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_SERIAL]]; }

private:
virtual bool claim_bluetooth(BluetoothController *driver, uint32_t bluetooth_class) {return false;}
virtual bool process_bluetooth_HID_data(const uint8_t *data, uint16_t length) {return false;}
@@ -879,6 +878,8 @@ private:
// Class specific
void init();
USBHIDParser *driver_ = nullptr;
BluetoothController *btdriver_ = nullptr;

joytype_t mapVIDPIDtoJoystickType(uint16_t idVendor, uint16_t idProduct, bool exclude_hid_devices);
bool transmitPS4UserFeedbackMsg();
bool transmitPS3UserFeedbackMsg();
@@ -1609,6 +1610,13 @@ public:
enum {BT_CLASS_DEVICE= 0x0804}; // Toy - Robot
static void driver_ready_for_bluetooth(BTHIDInput *driver);


// BUGBUG version to allow some of the controlled objects to call?

void sendL2CapCommand(uint8_t* data, uint8_t nbytes, uint8_t channelLow = 0x01, uint8_t channelHigh = 0x00) {
sendL2CapCommand (device_connection_handle_, data, nbytes, channelLow, channelHigh);
}

protected:
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len);
virtual void control(const Transfer_t *transfer);
@@ -1617,6 +1625,7 @@ protected:

BTHIDInput * find_driver(uint32_t device_type);
private:
friend class BTHIDInput;
static void rx_callback(const Transfer_t *transfer);
static void rx2_callback(const Transfer_t *transfer);
static void tx_callback(const Transfer_t *transfer);

+ 35
- 17
joystick.cpp Переглянути файл

@@ -201,21 +201,39 @@ bool JoystickController::setLEDs(uint8_t lr, uint8_t lg, uint8_t lb)
}

bool JoystickController::transmitPS4UserFeedbackMsg() {
if (!driver_) return false;
uint8_t packet[32];
memset(packet, 0, sizeof(packet));

packet[0] = 0x05; // Report ID
packet[1]= 0xFF;

packet[4] = rumble_lValue_; // Small Rumble
packet[5] = rumble_rValue_; // Big rumble
packet[6] = leds_[0]; // RGB value
packet[7] = leds_[1];
packet[8] = leds_[2];
// 9, 10 flash ON, OFF times in 100ths of sedond? 2.5 seconds = 255
Serial.printf("Joystick update Rumble/LEDs");
return driver_->sendPacket(packet, 32);
if (driver_) {
uint8_t packet[32];
memset(packet, 0, sizeof(packet));

packet[0] = 0x05; // Report ID
packet[1]= 0xFF;

packet[4] = rumble_lValue_; // Small Rumble
packet[5] = rumble_rValue_; // Big rumble
packet[6] = leds_[0]; // RGB value
packet[7] = leds_[1];
packet[8] = leds_[2];
// 9, 10 flash ON, OFF times in 100ths of sedond? 2.5 seconds = 255
Serial.printf("Joystick update Rumble/LEDs");
return driver_->sendPacket(packet, 32);
} else if (btdriver_) {
uint8_t packet[32];
memset(packet, 0, sizeof(packet));

packet[0] = 0x05; // Report ID
packet[1]= 0xFF;

packet[4] = rumble_lValue_; // Small Rumble
packet[5] = rumble_rValue_; // Big rumble
packet[6] = leds_[0]; // RGB value
packet[7] = leds_[1];
packet[8] = leds_[2];
// 9, 10 flash ON, OFF times in 100ths of sedond? 2.5 seconds = 255
Serial.printf("Joystick update Rumble/LEDs");
btdriver_->sendL2CapCommand(packet, sizeof(packet));
return true;
}
return false;
}

static const uint8_t PS3_USER_FEEDBACK_INIT[] = {
@@ -648,7 +666,7 @@ bool JoystickController::claim_bluetooth(BluetoothController *driver, uint32_t b
{
if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && ((bluetooth_class & 0x3C) == 0x08)) {
Serial.printf("JoystickController::claim_bluetooth TRUE\n");
//btdevice = driver;
btdriver_ = driver;
return true;
}
return false;
@@ -675,7 +693,7 @@ bool JoystickController::process_bluetooth_HID_data(const uint8_t *data, uint16_

void JoystickController::release_bluetooth()
{
//btdevice = nullptr;
btdriver_ = nullptr;
connected_ = false;

}

Завантаження…
Відмінити
Зберегти