This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

HID Finger Swipe Functionality (iPhone)

I’m very familiar with the HID keyboard and mouse profile and have built products using it but need direction on how to replicate the functionality of a up/down/left/right finger swipe on a iPhone. Any guidance will be valuable.  Thanks 

  • Hi Ovrebekk,

    I'm still having issues with not all packets are being sent.  Like I mentioned before I think it's a timing issue and I'm guessing there is a required delay or acknowledgement that is required before sending another.  Still no solution for this.  Also,  been working on building a packet structure from the report descriptor.  Have taken my best guess since it's the first time ever doing it.  I'm unable to get the correct values sent to the phone with the current packet structure that I tried creating from the report.  Your expert advice will be helpful thanks.

    byte[0] = Tip Switch, Range, Contact Id
    bit 0 = Tip Switch
    bit 1 = In Range
    bit 2 = Not Used
    bit 3 = Not Used
    bit 4 = Contact Id
    bit 5 = Contact Id
    bit 6 = Contact Id
    bit 7 = Contact Id
    byte[1] = X Coordinate LSB
    byte[2] = X and Y Axis Combined
    bit 0 = X Coordinate
    bit 1 = X Coordinate
    bit 2 = X Coordinate
    bit 3 = X Coordinate MSB
    bit 4 = Y Coordinate LSB
    bit 5 = Y Coordinate
    bit 6 = Y Coordinate
    bit 7 = Y Coordinate
    byte[3] = Y Coordinate MSB

    typedef PACKED_STRUCT { uint8_t tip_switch : 1; uint8_t range : 1; uint8_t contact_id : 4; uint16_t x : 12; uint16_t y : 12; } stylus_report_t;

    ## UP Packet 1 Decode ##
    0x03 0xF4 0x01 0x32
    00000011 11110100 00000001 00110010

    tip_switch = 1
    range = 1
    contact_id = 0
    x = 111101000000 = 801 ??
    y = 000100110010 = 306 ??

    Logged Packet Value: 43C8 C804
    
    typedef PACKED_STRUCT
    {
        uint8_t  tip_switch : 1;
        uint8_t  range      : 1;
        uint8_t  contact_id : 4;
        uint16_t x          : 12;
        uint16_t y          : 12;
    } stylus_report_t;
    
    static void digitizer_send_test() {
      stylus_report_t report = {0};
      report.tip_switch = 1;
      report.range = 1;
      report.contact_id = 0;
      report.x = 801;
      report.y = 306;
    
      uint32_t err_code;
      err_code = ble_hids_inp_rep_send(&m_hids, 
                                       INPUT_REPORT_DIG_INDEX,
                                       INPUT_REPORT_DIG_MAX_LEN,
                                       (uint8_t *)&report,
                                       m_conn_handle);
      APP_ERROR_CHECK(err_code);
    }
  • Check for errors by not commenting out this line:

    //APP_ERROR_CHECK(err_code);

    I am never able to send 8 notifications back-to-back in my own applications using the default configuration.  I will get the NRF_ERROR_RESOURCES error and then I wait for BLE_GATTS_EVT_HVN_TX_COMPLETE to send the next notification.  I think you can also increase the queue size:

    https://devzone.nordicsemi.com/f/nordic-q-a/53941/nrf_error_resources

  • Hi Jefferson,

    Thanks for the feedback.  You might be right about the queue size.  I tried changing a few settings but with no luck.  I noticed that the keyboard example has a key buffer that it uses. Not sure how it all works and what is unloading the buffer.  Not sure that is the same way I want to do it. I would think not.

    app_error_fault_handler (id=0x00004001, info=0x2000fe10, pc=0x00028553)
  • I think the correct way is to wait for the event BLE_GATTS_EVT_HVN_TX_COMPLETE before sending the next packet if you get the error NRF_ERROR_RESOURCES.  If you just want to see something working quickly, maybe just put a delay after each packet or when you get NRF_ERROR_RESOURCES:

    err_code = ble_hids_inp_rep_send(&m_hids, INPUT_REPORT_DIG_INDEX, INPUT_REPORT_DIG_MAX_LEN, packet_1_data, m_conn_handle);

    nrf_delay_ms(50);

    err_code = ble_hids_inp_rep_send(&m_hids, INPUT_REPORT_DIG_INDEX, INPUT_REPORT_DIG_MAX_LEN, packet_1_data, m_conn_handle);

    nrf_delay_ms(50);

    ...

  • Hi

    I agree with Jefferson's comment. When the NRF_ERROR_RESOURCES error occurs you should wait for the next BLE_GATTS_EVT_HVN_TX_COMPLETE event, and then you can continue uploading packets until the error occurs again (and then rinse and repeat). 

    In order to try sending more packets pr connection event you can try increasing the NRF_SDH_BLE_GAP_EVENT_LENGTH define in sdk_config.h, but as the phone also has it's own limit there is no guarantee that increasing the GAP event length will increase the total number of packets. 

    Best regards
    Torbjørn

Related