Przeglądaj źródła

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

main
Kurt Eckhardt 6 lat temu
rodzic
commit
9d9ac92829
2 zmienionych plików z 45 dodań i 18 usunięć
  1. +10
    -1
      USBHost_t36.h
  2. +35
    -17
      joystick.cpp

+ 10
- 1
USBHost_t36.h Wyświetl plik

{ return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_PROD]]; } { return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_PROD]]; }
const uint8_t *serialNumber() const uint8_t *serialNumber()
{ return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_SERIAL]]; } { return ((btdevice == nullptr) || (btdevice->strbuf == nullptr)) ? nullptr : &btdevice->strbuf->buffer[btdevice->strbuf->iStrings[strbuf_t::STR_ID_SERIAL]]; }

private: private:
virtual bool claim_bluetooth(BluetoothController *driver, uint32_t bluetooth_class) {return false;} 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;} virtual bool process_bluetooth_HID_data(const uint8_t *data, uint16_t length) {return false;}
// Class specific // Class specific
void init(); void init();
USBHIDParser *driver_ = nullptr; USBHIDParser *driver_ = nullptr;
BluetoothController *btdriver_ = nullptr;

joytype_t mapVIDPIDtoJoystickType(uint16_t idVendor, uint16_t idProduct, bool exclude_hid_devices); joytype_t mapVIDPIDtoJoystickType(uint16_t idVendor, uint16_t idProduct, bool exclude_hid_devices);
bool transmitPS4UserFeedbackMsg(); bool transmitPS4UserFeedbackMsg();
bool transmitPS3UserFeedbackMsg(); bool transmitPS3UserFeedbackMsg();
enum {BT_CLASS_DEVICE= 0x0804}; // Toy - Robot enum {BT_CLASS_DEVICE= 0x0804}; // Toy - Robot
static void driver_ready_for_bluetooth(BTHIDInput *driver); 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: protected:
virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len); virtual bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len);
virtual void control(const Transfer_t *transfer); virtual void control(const Transfer_t *transfer);


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

+ 35
- 17
joystick.cpp Wyświetl plik

} }


bool JoystickController::transmitPS4UserFeedbackMsg() { 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[] = { static const uint8_t PS3_USER_FEEDBACK_INIT[] = {
{ {
if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && ((bluetooth_class & 0x3C) == 0x08)) { if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && ((bluetooth_class & 0x3C) == 0x08)) {
Serial.printf("JoystickController::claim_bluetooth TRUE\n"); Serial.printf("JoystickController::claim_bluetooth TRUE\n");
//btdevice = driver;
btdriver_ = driver;
return true; return true;
} }
return false; return false;


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


} }

Ładowanie…
Anuluj
Zapisz