Forum Rule: Always post complete source code & details to reproduce any issue!
Page 28 of 28 FirstFirst ... 18 26 27 28
Results 676 to 683 of 683

Thread: T3.6 USB Host - Bluetooth

  1. #676
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,891
    FYI - I have been playing around some more trying to support multiple Bluetooth devices like a mouse and keyboard at the same time.

    This in between other distractions like: Life, health, T4, ...

    I am making some progress, but it is needing me to change a few underlying things. Like I was sort of hard coding:
    uint16_t control_dcid_ = 0x70;
    uint16_t interrupt_dcid_ = 0x71;

    to 0x70 and 0x71, except when PS3 overwrote it. So instead I start off at 0x70 and increment them... With this, when I do it, when both mouse and keyboard attach they are given different values...

    Then for example if I connect the keyboard and type a key... You see something like this (debug output on)

    Code:
    BT rx2_data(18): 48 20 e 0 a 0 71 0 a1 1 0 0 0 0 0 0 0 0 
    HID HDR Data: len: 10, Type: 1
    KeyboardController::process_bluetooth_HID_data
      KB Data: 01 00 00 00 00 00 00 00 00 
      release, key=11
    Then I connect the Mouse... And then start receiving mouse messages:
    Code:
    =====================
    BT rx2_data(14): 43 20 a 0 6 0 73 0 a1 2 0 0 0 0 
    HID HDR Data: len: 6, Type: 2
    MouseController::process_bluetooth_HID_data 5
      Mouse Data: 02 00 00 00 00 
    Mouse: buttons = 0,  mouseX = 0,  mouseY = 0,  wheel = 0,  wheelH = 0
    
    =====================
    BT rx2_data(14): 43 20 a 0 6 0 73 0 a1 2 0 0 2 0 
    HID HDR Data: len: 6, Type: 2
    MouseController::process_bluetooth_HID_data 5
      Mouse Data: 02 00 00 02 00 
    Mouse: buttons = 0,  mouseX = 0,  mouseY = 2,  wheel = 0,  wheelH = 0
    
    =====================
    Note at this point current code if I then typed a letter on the keyboard, the mouse code would try to process it...
    Both are actually connected at this point, but code is setup that last one wins...

    But the information is here, that is if you look at keyboard data above: 48 20 e 0 a 0 71 0 a1 1 0 0 0 0 0 0 0 0

    The green part is the actual keyboard data: the first 8 bytes are HCI and L2CAP headers, the interesting one in red 71 is the connection ID...

    Then again if you look at Mouse data: 43 20 a 0 6 0 73 0 a1 2 0 0 2 0

    You see, that Keyboard is on conversation 0x71 and mouse on 0x73, which current code ignores. So now in process of moving the connection information into an array of sub-structures which contain the connection information including pointer to which object (mouse or keyboard...), And then when rx2_data comes through look at that connection ID and pass it off to hopefully the right BT client object...

    Currently limiting to 4 BT connections... Will see how well this works and/or maybe instead move some/all of this data into the BTHID objects...

    Currently working in new github branch, so that if BT branch PR is integrated, this won't interfere... If the new branch works well, then will Pull it into BT branch...

  2. #677
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,891
    Quick update (in case anyone wants to play along)...

    Currently I have a keyboard (Rii) and Mouse (Tecknet) that were already paired with dongle... Then used test app Mouse_KeyboardBT ... I have most of the debug stuff turned off in the below run,
    But you can now see where it is now having the keyboard object processing the keyboard data and the mouse object support the mouse data...

    Still WIP, but I put it up in new branch: https://github.com/KurtE/USBHost_t36...luetooth-multi


    Code:
    USB Host Testing
    960
    *** Device Bluet a12:1 - connected ***
      product: CSR8510 A10
      BDADDR: 0:0:0:0:0:0
    BluetoothController::find_driver  driver 20003198
    Keyboard Controller::claim_bluetooth - Class 540
    KeyboardController::claim_bluetooth TRUE
        *** Claimed ***
    KeyboardController::process_bluetooth_HID_data
    KeyboardController::process_bluetooth_HID_data
    key 'a'  97 MOD: KeyboardController::process_bluetooth_HID_data
    KeyboardController::process_bluetooth_HID_data
    key 'b'  98 MOD: KeyboardController::process_bluetooth_HID_data
    KeyboardController::process_bluetooth_HID_data
    key 'c'  99 MOD: KeyboardController::process_bluetooth_HID_data
    KeyboardController::process_bluetooth_HID_data
    key 'd'  100 MOD: KeyboardController::process_bluetooth_HID_data
    BluetoothController::find_driver  driver 20003198
    Keyboard Controller::claim_bluetooth - Class 580
      driver 20006178
    MouseController Controller::claim_bluetooth - Class 580
    MouseController::claim_bluetooth TRUE
        *** Claimed ***
    *** BTHID Device Mouse(BT) - connected ***
    Mouse: buttons = 1,  mouseX = 0,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 0,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 3,  mouseY = -40,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 0,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 12,  mouseY = -3,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 2,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 13,  mouseY = -1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 13,  mouseY = -1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 10,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 7,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 4,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 3,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 1,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -1,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -1,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -1,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 2,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -3,  mouseY = 4,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 3,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -4,  mouseY = 3,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -5,  mouseY = 3,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -5,  mouseY = 4,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -4,  mouseY = 2,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -3,  mouseY = 2,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -4,  mouseY = 1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -5,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -2,  mouseY = 1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -3,  mouseY = 1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -6,  mouseY = 1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -7,  mouseY = 1,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -7,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -5,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -4,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = -3,  mouseY = 0,  wheel = 0,  wheelH = 0
    Mouse: buttons = 0,  mouseX = 0,  mouseY = 1,  wheel = 0,  wheelH = 0
    KeyboardController::process_bluetooth_HID_data
    key 'd'  100 MOD: KeyboardController::process_bluetooth_HID_data

  3. #678
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,811
    That looks like very good development KurtE!

    I've run lots of the samples - but never beyond the 'casual user' mode just expecting it to work, so having this low level code resolve out multiple devices where it would not before is a great advance.

  4. #679
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,811
    I'm seeing that BLE is its own thing versus regular Bluetooth - is getting BLE done/do-able on Teensy USBHost? I'm glancing around with web searches and not sure how much I don't know yet I'm supposing that would take a Bt dongle that has BLE support and then it would be a whole extra set of code to recognize and support BLW connects?

  5. #680
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,891
    @defragster - Thanks, some of it is me, learning (sometimes slowly ) as I go. So I am happy that I have at least some of the multiple devices working (limping) along... I still need to see about some of the message routing and picking right values in some cases.

    Example: When mouse connects and keyboard connects, and maybe the user code wants to send back to keyboard which LEDS should be set (Caps lock, Scroll lock...)

    Also need to check out multiple PS3 devices and see if I can change the 2nd one to not be 40, 41, but instead 42...

    BLE (Bluetooth Low Energy) - Has it's own volume (6) in the Bluetooth core manual, with all new different messages and data flows... Ran into this with the Microsoft Sculpt Bluetooth mouse, which I have not been able to setup yet... Maybe also with the Logitech...

    So yes some whole new set of code needs to be written...

  6. #681
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,891
    @defragster, @mjs513 and ... - Still playing here, mainly with trying to get two PS3 controllers to work with each other... Running into some issues, that I need to fix.

    Like, the BTHID objects need to test that they are not already being used before they try to accept a new connection... Have some other distractions for today...

    Here is start of hacked up viewer that should in the end show two different joysticks data at same time on ILI9341_t3n ...

    Code:
    //=============================================================================
    // Simple test viewer app for several of the USB devices on ili9341 display
    //
    // Currently requires the libraries
    //    ili9341_t3n that can be located: https://github.com/KurtE/ILI9341_t3n
    //    spin: https://github.com/KurtE/SPIN
    //
    // Teensy 3.6 Pins
    //   8 = RST
    //   9 = D/C
    //  10 = CS
    //
    // Teensy 4.0 Beta Pins
    //  23 = RST (Marked MCLK on T4 beta breakout)
    //  10 = CS (Marked CS)
    //  9 = DC  (Marked MEMCS)
    //
    // This example is in the public domain
    //=============================================================================
    
    #include "USBHost_t36.h"
    #include <ili9341_t3n_font_Arial.h>
    #define TEENSY64
    
    //=============================================================================
    // Connection configuration of ILI9341 LCD TFT
    //=============================================================================
    DMAMEM uint16_t frame_buffer[ILI9341_TFTWIDTH * ILI9341_TFTHEIGHT];
    #if defined(__MK66FX1M0__) && !defined(TEENSY64)
    #define TFT_RST 255
    #define TFT_DC 20
    #define TFT_CS 21
    ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
    #elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
    // On Teensy 4 beta with Paul's breakout out:
    // Using pins (MOSI, MISO, SCK which are labeled on Audio board breakout location
    // which are not in the Normal processor positions
    // Also DC=10(CS), CS=9(BCLK) and RST 23(MCLK)
    #define TFT_RST 23
    #define TFT_DC 9
    #define TFT_CS 10
    ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
    #elif defined(TEENSY64)
    #define TFT_RST 255
    #define TFT_DC 20
    #define TFT_CS 21
    #define TFT_SCK 14
    #define TFT_MISO 39
    #define TFT_MOSI 28
    ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
    #else
    #error "This example App will only work with Teensy 3.6 or Teensy 4."
    #endif
    
    //=============================================================================
    // USB Host Ojbects
    //=============================================================================
    USBHost myusb;
    USBHub hub1(myusb);
    USBHub hub2(myusb);
    USBHIDParser hid1(myusb);
    USBHIDParser hid2(myusb);
    JoystickController joystick1(myusb);
    JoystickController joystick2(myusb);
    //BluetoothController bluet(myusb, true, "0000");   // Version does pairing to device
    BluetoothController bluet(myusb);   // version assumes it already was paired
    
    // Lets only include in the lists The most top level type devices we wish to show information for.
    USBDriver *drivers[] = {&joystick1, &joystick2, &bluet, &hid1, &hid2};
    
    #define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
    const char * driver_names[CNT_DEVICES] = {"Joystick1(device)", "Joystick2(device)", "Bluet", "HID1" , "HID2"};
    bool driver_active[CNT_DEVICES] = {false, false, false, false};
    
    // Lets also look at HID Input devices
    USBHIDInput *hiddrivers[] = {&joystick1, &joystick2};
    #define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
    const char * hid_driver_names[CNT_HIDDEVICES] = {"joystick1", "joystick2"};
    
    bool hid_driver_active[CNT_HIDDEVICES] = {false};
    
    BTHIDInput *bthiddrivers[] = {&joystick1, &joystick2};
    #define CNT_BTHIDDEVICES (sizeof(bthiddrivers)/sizeof(bthiddrivers[0]))
    const char * bthid_driver_names[CNT_HIDDEVICES] = {"joystick1", "joystick2"};
    bool bthid_driver_active[CNT_HIDDEVICES] = {false};
    
    //=============================================================================
    // Other state variables.
    //=============================================================================
    
    // Save away values for buttons, x, y, wheel
    typedef struct {
      uint32_t buttons_cur = 0;
      int x = 0,
          y = 0,
          x2 = 0,
          y2 = 0,
          L1 = 0,
          R1 = 0;
      int wheel = 0;
      int axis[64];
      uint32_t buttons_prev = 0;
      uint32_t buttons;
      uint8_t left_trigger_value = 0;
      uint8_t right_trigger_value = 0;
    
    } joystick_save_data_t;
    
    joystick_save_data_t joy_data[2];
    
    elapsedMillis heartbeat;
    uint8_t heartbeat_index = 99;
    static const uint8_t heartbeat_chars[] = {'-', '/', '|', '\\'};
    
    
    bool show_changed_only = false;
    bool new_device_detected = false;
    int16_t y_position_after_device_info = 0;
    
    uint64_t joystick_full_notify_mask = (uint64_t) - 1;
    
    
    //=============================================================================
    // function declares
    //=============================================================================
    extern void ProcessJoystickData(JoystickController &joy, joystick_save_data_t &jsdata, uint16_t x_disp);
    
    
    //=============================================================================
    // Setup
    //=============================================================================
    void setup()
    {
    
      Serial1.begin(2000000);
      while (!Serial && millis() < 3000) ; // wait for Arduino Serial Monitor
      Serial.println("\n\nUSB Host multiple joystick Testing");
      myusb.begin();
    
      tft.begin();
      // explicitly set the frame buffer
      tft.setFrameBuffer(frame_buffer);
      delay(100);
      tft.setRotation(3); // 180
      delay(100);
    
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_YELLOW);
      tft.setTextSize(2);
      tft.println("Waiting for Device...");
      tft.useFrameBuffer(true);
      heartbeat = 0;
    }
    
    #define JOYSTICK_DATA_X1 75
    #define JOYSTICK_DATA_X2 175
    
    //=============================================================================
    // Loop
    //=============================================================================
    void loop()
    {
      myusb.Task();
    
      // Update the display with
      UpdateActiveDeviceInfo();
    
      // And joystick data
      ProcessJoystickData(joystick1, joy_data[0], JOYSTICK_DATA_X1);
      ProcessJoystickData(joystick2, joy_data[1], JOYSTICK_DATA_X2);
      if (heartbeat > 250) {
        heartbeat = 0;
        if (++heartbeat_index > sizeof(heartbeat_chars)) heartbeat_index = 0;
        tft.setCursor(tft.width() - 10, tft.height() - 10);
        tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
        tft.setFont(Arial_12);
        tft.write(heartbeat_chars[heartbeat_index]);
        tft.updateScreen();
    
      }
    }
    
    
    //=============================================================================
    // UpdateActiveDeviceInfo
    //=============================================================================
    //=============================================================================
    // UpdateActiveDeviceInfo
    //=============================================================================
    void UpdateActiveDeviceInfo() {
      // First see if any high level devices
      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 {
            new_device_detected = true;
            Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
            driver_active[i] = true;
            tft.fillScreen(ILI9341_BLACK);  // clear the screen.
            tft.setCursor(0, 0);
            tft.setTextColor(ILI9341_YELLOW);
            tft.setFont(Arial_12);
            tft.printf("Device %s %x:%x\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
    
            const uint8_t *psz = drivers[i]->manufacturer();
            if (psz && *psz) tft.printf("  manufacturer: %s\n", psz);
            psz = drivers[i]->product();
            if (psz && *psz) tft.printf("  product: %s\n", psz);
            psz = drivers[i]->serialNumber();
            if (psz && *psz) tft.printf("  Serial: %s\n", psz);
            tft.updateScreen(); // update the screen now
          }
        }
      }
      // Then Hid Devices
      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 {
            new_device_detected = true;
            Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
            hid_driver_active[i] = true;
            tft.fillScreen(ILI9341_BLACK);  // clear the screen.
            tft.setCursor(0, 0);
            tft.setTextColor(ILI9341_YELLOW);
            tft.setFont(Arial_12);
            tft.printf("HID Device %s %x:%x\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
    
            const uint8_t *psz = hiddrivers[i]->manufacturer();
            if (psz && *psz) tft.printf("  manufacturer: %s\n", psz);
            psz = hiddrivers[i]->product();
            if (psz && *psz) tft.printf("  product: %s\n", psz);
            psz = hiddrivers[i]->serialNumber();
            if (psz && *psz) tft.printf("  Serial: %s\n", psz);
            tft.updateScreen(); // update the screen now
          }
        }
      }
    
      // 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", hid_driver_names[i]);
            bthid_driver_active[i] = false;
          } else {
            new_device_detected = true;
            Serial.printf("*** BTHID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
            bthid_driver_active[i] = true;
            tft.fillScreen(ILI9341_BLACK);  // clear the screen.
            tft.setCursor(0, 0);
            tft.setTextColor(ILI9341_YELLOW);
            tft.setFont(Arial_12);
            tft.printf("Bluetooth Device %s %x:%x\n", bthid_driver_names[i], bthiddrivers[i]->idVendor(), bthiddrivers[i]->idProduct());
    
            const uint8_t *psz = bthiddrivers[i]->manufacturer();
            if (psz && *psz) tft.printf("  manufacturer: %s\n", psz);
            psz = bthiddrivers[i]->product();
            if (psz && *psz) tft.printf("  product: %s\n", psz);
            psz = bthiddrivers[i]->serialNumber();
            if (psz && *psz) tft.printf("  Serial: %s\n", psz);
            tft.updateScreen(); // update the screen now
            int16_t x;
            tft.getCursor(&x, &y_position_after_device_info);
    
          }
        }
      }
    }
    
    //=============================================================================
    // OutputNumberField
    //=============================================================================
    void OutputNumberField(int16_t x, int16_t y, int val, int16_t field_width) {
      int16_t x2, y2;
      tft.setCursor(x, y);
      tft.print(val, DEC); tft.getCursor(&x2, &y2);
      tft.fillRect(x2, y, field_width - (x2 - x), Arial_12.line_space, ILI9341_BLACK);
    }
    
    
    //=============================================================================
    // ProcessJoystickData
    //=============================================================================
    
    void ProcessJoystickData(JoystickController &joy, joystick_save_data_t &jsdata, uint16_t x_disp) {
      if (joy.available()) {
        uint64_t axis_mask = joy.axisMask();
        uint64_t axis_changed_mask = joy.axisChangedMask();
        Serial.print("Joystick: buttons = ");
        jsdata.buttons = joy.getButtons();
        Serial.print(jsdata.buttons, HEX);
        //Serial.printf(" AMasks: %x %x:%x", axis_mask, (uint32_t)(user_axis_mask >> 32), (uint32_t)(user_axis_mask & 0xffffffff));
        //Serial.printf(" M: %lx %lx", axis_mask, joy.axisChangedMask());
        if (show_changed_only) {
          for (uint8_t i = 0; axis_changed_mask != 0; i++, axis_changed_mask >>= 1) {
            if (axis_changed_mask & 1) {
              Serial.printf(" %d:%d", i, joy.getAxis(i));
            }
          }
        } else {
          for (uint8_t i = 0; axis_mask != 0; i++, axis_mask >>= 1) {
            if (axis_mask & 1) {
              Serial.printf(" %d:%d", i, joy.getAxis(i));
            }
          }
        }
        for (uint8_t i = 0; i < 64; i++) {
          jsdata.axis[i] = joy.getAxis(i);
        }
        uint8_t ltv;
        uint8_t rtv;
        switch (joy.joystickType()) {
          default:
            break;
          case JoystickController::PS4:
            ltv = joy.getAxis(3);
            rtv = joy.getAxis(4);
            if ((ltv != jsdata.left_trigger_value) || (rtv != jsdata.right_trigger_value)) {
              jsdata.left_trigger_value = ltv;
              jsdata.right_trigger_value = rtv;
              joy.setRumble(ltv, rtv);
            }
            break;
    
          case JoystickController::PS3:
            ltv = joy.getAxis(18);
            rtv = joy.getAxis(19);
            if ((ltv != jsdata.left_trigger_value) || (rtv != jsdata.right_trigger_value)) {
              jsdata.left_trigger_value = ltv;
              jsdata.right_trigger_value = rtv;
              joy.setRumble(ltv, rtv, 50);
            }
            break;
    
          case JoystickController::PS3_MOTION:
            ltv = joy.getAxis(18);
            rtv = joy.getAxis(19);
            if ((ltv != jsdata.left_trigger_value) || (rtv != jsdata.right_trigger_value)) {
              jsdata.left_trigger_value = ltv;
              jsdata.right_trigger_value = rtv;
              joy.setRumble(ltv, rtv, 50);
            }
            break;
    
          case JoystickController::XBOXONE:
          case JoystickController::XBOX360:
            ltv = joy.getAxis(4);
            rtv = joy.getAxis(5);
            if ((ltv != jsdata.left_trigger_value) || (rtv != jsdata.right_trigger_value)) {
              jsdata.left_trigger_value = ltv;
              jsdata.right_trigger_value = rtv;
              joy.setRumble(ltv, rtv);
              Serial.printf(" Set Rumble %d %d", ltv, rtv);
            }
            break;
        }
        if (jsdata.buttons != jsdata.buttons_cur) {
          if (joy.joystickType() == JoystickController::PS3) {
            joy.setLEDs((jsdata.buttons >> 12) & 0xf); //  try to get to TRI/CIR/X/SQuare
          } else {
            uint8_t lr = (jsdata.buttons & 1) ? 0xff : 0;
            uint8_t lg = (jsdata.buttons & 2) ? 0xff : 0;
            uint8_t lb = (jsdata.buttons & 4) ? 0xff : 0;
            joy.setLEDs(lr, lg, lb);
          }
          jsdata.buttons_cur = jsdata.buttons;
        }
        Serial.println();
        tft_JoystickData(joy, jsdata, x_disp);
        joy.joystickDataClear();
      }
    }
    
    
    //=============================================================================
    // TFT_joystick
    //=============================================================================
    void tft_JoystickData(JoystickController &joy, joystick_save_data_t &jsdata, uint16_t x_disp) {
      if (new_device_detected) {
        // Lets display the titles.
        //    tft.getCursor(&x, &y_position_after_device_info);
        tft.setCursor(0,y_position_after_device_info);
        tft.setTextColor(ILI9341_YELLOW);
        tft.printf("Buttons:\nX:\nY:\nX2\nY2(Z):\nL1:\nR1:\nHAT:");
        new_device_detected = false;
      }
    
      bool something_changed = false;
      if (jsdata.buttons != jsdata.buttons_prev) {  //buttons
        something_changed = true;
        jsdata.buttons_prev = jsdata.buttons;
      }
      if (jsdata.axis[0] != jsdata.x) {  //xL
        jsdata.x = jsdata.axis[0];
        something_changed = true;
      }
      if (jsdata.axis[1] != jsdata.y) {  //yL
        jsdata.y = jsdata.axis[1];
        something_changed = true;
      }
      if (jsdata.axis[9] != jsdata.wheel) {  //Hat
        jsdata.wheel = jsdata.axis[9];
        something_changed = true;
      }
      //Second Axis
      if (jsdata.axis[2] != jsdata.x2) {  //xR
        jsdata.x2 = jsdata.axis[2];
        something_changed = true;
      }
      if (jsdata.axis[5] != jsdata.y2) {  //yR or z-axis
        jsdata.y2 = jsdata.axis[5];
        something_changed = true;
      }
      //Rumble Axis
      switch (joy.joystickType()) {
        case JoystickController::XBOXONE:
        case JoystickController::XBOX360:
        case JoystickController::PS4:
          if (jsdata.axis[3] != jsdata.L1) {  //xR
            jsdata.L1 = jsdata.axis[3];
            something_changed = true;
          }
          if (jsdata.axis[4] != jsdata.R1) {  //yR or z-axis
            jsdata.R1 = jsdata.axis[4];
            something_changed = true;
          }
          break;
        case JoystickController::PS3:
          if (jsdata.axis[18] != jsdata.L1) {  //xR
            jsdata.L1 = jsdata.axis[18];
            something_changed = true;
          }
          if (jsdata.axis[19] != jsdata.R1) {  //yR or z-axis
            jsdata.R1 = jsdata.axis[19];
            something_changed = true;
          }
          break;
      }
      if (something_changed) {
        int16_t x, y2;
        unsigned char line_space = Arial_12.line_space;
        tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
        //tft.setTextDatum(BR_DATUM);
        int16_t y = y_position_after_device_info;
        tft.setCursor(x_disp, y);
        tft.printf("%d(%x)", jsdata.buttons, jsdata.buttons);
        tft.getCursor(&x, &y2);
        tft.fillRect(x, y, 320, line_space, ILI9341_BLACK);
    
        y += line_space; OutputNumberField(x_disp, y, jsdata.x, 100);  //x
        y += line_space; OutputNumberField(x_disp, y, jsdata.y, 100);  //y
        y += line_space; OutputNumberField(x_disp, y, jsdata.x2, 100); //x2(z)
        y += line_space; OutputNumberField(x_disp, y, jsdata.y2, 100); //y2
        switch (joy.joystickType()) {
          case JoystickController::PS4:
          case JoystickController::PS3:
          case JoystickController::XBOXONE:
          case JoystickController::XBOX360:
            y += line_space; OutputNumberField(x_disp, y, jsdata.L1, 100);
            y += line_space; OutputNumberField(x_disp, y, jsdata.R1, 100);
            break;
          default:
            y += line_space; OutputNumberField(x_disp, y, 0, 100);
            y += line_space; OutputNumberField(x_disp, y, 0, 100);
            y += line_space; OutputNumberField(x_disp, y, jsdata.wheel, 100); //hat
            break;
        }
        tft.updateScreen(); // update the screen now
      }
    }
    Now to get ready for distraction

  7. #682
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,489
    @KurtE

    Decided to give your Multi version a try with a little regression testing. Having a tough time connecting and running a PS4. Sees the dongle fine but never connects to the PS4 when I hit the pair button. This is the dump up to the point I hit the PS button:
    Code:
    USB Host Testing
    960
    USB2 PLL running
     reset waited 6
    USBHS_ASYNCLISTADDR = 0
    USBHS_PERIODICLISTBASE = 20008000
    periodictable = 20008000
    port change: 10001803
        connect
      begin reset
    port change: 10001805
      port enabled
      end recovery
    new_Device: 12 Mbit/sec
    new_Pipe
    enumeration:
    enumeration:
    enumeration:
    Device Descriptor:
      12 01 00 02 FF 01 01 40 5C 0A E8 21 12 01 01 02 03 01 
        VendorID = 0A5C, ProductID = 21E8, Version = 0112
        Class/Subclass/Protocol = 255 / 1 / 1
        Number of Configurations = 1
    enumeration:
    enumeration:
    Manufacturer: Broadcom Corp
    enumeration:
    Product: BCM20702A0
    enumeration:
    Serial Number: 5CF3707A13B9
    enumeration:
    Config data length = 218
    enumeration:
    Configuration Descriptor:
      09 02 DA 00 04 01 00 E0 00 
        NumInterfaces = 4
        ConfigurationValue = 1
      09 04 00 00 03 FF 01 01 00 
        Interface = 0
        Number of endpoints = 3
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 81 03 10 00 01 
        Endpoint = 1 IN
        Type = Interrupt
        Max Size = 16
        Polling Interval = 1
      07 05 82 02 40 00 01 
        Endpoint = 2 IN
        Type = Bulk
        Max Size = 64
        Polling Interval = 1
      07 05 02 02 40 00 01 
        Endpoint = 2 OUT
        Type = Bulk
        Max Size = 64
        Polling Interval = 1
      09 04 01 00 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 00 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 0
        Polling Interval = 1
      07 05 03 01 00 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 0
        Polling Interval = 1
      09 04 01 01 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 09 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 9
        Polling Interval = 1
      07 05 03 01 09 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 9
        Polling Interval = 1
      09 04 01 02 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 11 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 17
        Polling Interval = 1
      07 05 03 01 11 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 17
        Polling Interval = 1
      09 04 01 03 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 19 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 25
        Polling Interval = 1
      07 05 03 01 19 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 25
        Polling Interval = 1
      09 04 01 04 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 21 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 33
        Polling Interval = 1
      07 05 03 01 21 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 33
        Polling Interval = 1
      09 04 01 05 02 FF 01 01 00 
        Interface = 1
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 1 / 1
      07 05 83 01 31 00 01 
        Endpoint = 3 IN
        Type = Isochronous
        Max Size = 49
        Polling Interval = 1
      07 05 03 01 31 00 01 
        Endpoint = 3 OUT
        Type = Isochronous
        Max Size = 49
        Polling Interval = 1
      09 04 02 00 02 FF FF FF 00 
        Interface = 2
        Number of endpoints = 2
        Class/Subclass/Protocol = 255 / 255 / 255
      07 05 84 02 20 00 01 
        Endpoint = 4 IN
        Type = Bulk
        Max Size = 32
        Polling Interval = 1
      07 05 04 02 20 00 01 
        Endpoint = 4 OUT
        Type = Bulk
        Max Size = 32
        Polling Interval = 1
      09 04 03 00 00 FE 01 01 00 
        Interface = 3
        Number of endpoints = 0
        Class/Subclass/Protocol = 254 / 1 / 1
      09 21 05 88 13 40 00 10 01 
        HID, 64 report descriptors
    enumeration:
    USBHub memory usage = 960
    USBHub claim_device this=20006060
    USBHub memory usage = 960
    USBHub claim_device this=20006420
    HIDParser claim this=200047A0
    HIDParser claim this=20004DC0
    HIDParser claim this=20006880
    HIDParser claim this=20005400
    HIDParser claim this=20005A20
    JoystickController claim this=20007680
    BluetoothController claim this=20006F60
    BluetoothController claim this=20006f60 vid:pid=a5c:21e8
        9 4 0 0 3 ff 1 1 0 7 5 81 3 10 0 1 7 5 82 2 40 0 1 7 5 2 2 40 0 1 9 4 1 0 2 ff 1 1 0 7 5 83 1 0 0 1 7 5 3 1 0 0 1 9 4 1 1 2 ff 1 1 0 7 5 
        83 1 9 0 1 7 5 3 1 9 0 1 9 4 1 2 2 ff 1 1 0 7 5 83 1 11 0 1 7 5 3 1 11 0 1 9 4 1 3 2 ff 1 1 0 7 5 83 1 19 0 1 7 5 3 1 19 0 1 9 4 1 4 2 ff 
        1 1 0 7 5 83 1 21 0 1 7 5 3 1 21 0 1 9 4 1 5 2 ff 1 1 0 7 5 83 1 31 0 1 7 5 3 1 31 0 1 9 4 2 0 2 ff ff ff 0 7 5 84 2 20 0 1 7 5 4 2 20 0 1 9 
        4 3 0 0 fe 1 1 0 9 21 5 88 13 40 0 10 1 
          rxep=1(16) txep=2(64) rx2ep=2(64)
    BluetoothController, rxep=1(16), txep=2(64)
    new_Pipe
    allocate_interrupt_pipe_bandwidth
     best_bandwidth = 3, at offset = 0, shift= 0
    new_Pipe
    allocate_interrupt_pipe_bandwidth
     best_bandwidth = 6, at offset = 0, shift= 1
    new_Pipe
    HCI_RESET called (03 0c 00 )
        control callback (bluetooth) 1
        Control callback (bluetooth): 1 : 3 c 0 
    0E 04 01 03 0C 00 
    BT rx_data(6): e 4 1 3 c 0 
        Command Completed! 
    HCI_WRITE_CLASS_OF_DEV called (24 0c 03 04 08 00 )
        control callback (bluetooth) 3
        Control callback (bluetooth): 3 : 24 c 3 4 8 0 
    0E 04 01 24 0C 00 
    BT rx_data(6): e 4 1 24 c 0 
        Command Completed! 
    HCI_Read_BD_ADDR called (09 10 00 )
        control callback (bluetooth) 4
        Control callback (bluetooth): 4 : 9 10 0 
    0E 0A 01 09 10 00 B9 13 7A 70 F3 5C 
    BT rx_data(12): e a 1 9 10 0 b9 13 7a 70 f3 5c 
        Command Completed! 
       BD Addr 5c:f3:70:7a:13:b9
    HCI_Read_Local_Version_Information called (01 10 00 )
        control callback (bluetooth) 4
        Control callback (bluetooth): 4 : 1 10 0 
    0E 0C 01 01 10 00 06 00 10 06 0F 00 0E 22 
    BT rx_data(14): e c 1 1 10 0 6 0 10 6 f 0 e 22 
        Command Completed! 
        Local Version: 6
    HCI_WRITE_INQUIRY_MODE called (45 0c 01 02 )
        control callback (bluetooth) 6
        Control callback (bluetooth): 6 : 45 c 1 2 
    0E 04 01 45 0C 00 
    BT rx_data(6): e 4 1 45 c 0 
        Command Completed! 
    HCI_Set_Event_Mask called (01 0c 08 ff ff ff ff ff 5f 00 00 )
        control callback (bluetooth) 7
        Control callback (bluetooth): 7 : 1 c 8 ff ff ff ff ff 5f 0 0 
    0E 04 01 01 0C 00 
    BT rx_data(6): e 4 1 1 c 0 
        Command Completed! 
    HCI_INQUIRY called (01 04 05 33 8b 9e 30 0a )
        control callback (bluetooth) 8
        Control callback (bluetooth): 8 : 1 4 5 33 8b 9e 30 a 
    0F 04 00 01 01 04 
    BT rx_data(6): f 4 0 1 1 4 
        Command 401 Status 0
    *** Device Bluet a5c:21e8 - connected ***
      manufacturer: Broadcom Corp
      product: BCM20702A0
      Serial: 5CF3707A13B9
      BDADDR: b9:13:7a:70:f3:5c
    2F FF 01 4E 13 00 00 7A C0 01 00 04 04 24 17 50 
    BT rx_data(16): 2f ff 1 4e 13 0 0 7a c0 1 0 4 4 24 17 50 
    A2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): a2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 
    BT rx_data(1): 0 
        Extended Inquiry Result - Count: 1
          BD:4e:13:0:0:7a:c0, PS:1, class: 240404
    2F FF 01 4E 13 00 00 7A C0 01 00 04 04 24 18 50 
    BT rx_data(16): 2f ff 1 4e 13 0 0 7a c0 1 0 4 4 24 18 50 
    A8 05 09 4A 4D 47 4F 02 0A 04 09 02 0D 11 0B 11 
    BT rx_data(16): a8 5 9 4a 4d 47 4f 2 a 4 9 2 d 11 b 11 
    0E 11 0F 11 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): e 11 f 11 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    BT rx_data(16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
    00 
    BT rx_data(1): 0 
        Extended Inquiry Result - Count: 1
          BD:4e:13:0:0:7a:c0, PS:1, class: 240404
          Local Name: JMGO
    EDIT: Tried Keyboard and that worked no problem

  8. #683
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,891
    Hi @mjs513 - I remember there were/are some issues with pairing with PS4... I assume you added the Pair version of the Bluetooth constructor...

    Also I sort of was running into something like that, was not sure if the pairing happened... Then I used the non-pairing constructor and it connected... Again not sure... Will have to continue and try more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •