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

BLE HID Keyboard: sending multiple char's does not work

I'm referring to the HID keyboard example (BLE peripherals)

The example itself is more or less working and since my goal is to send a whole character string via BLE and HID keyboard to a smartphone or PC, I started with this example and modified it.

The code itself is IMHO a bit confusing because keys_send() seems to accept a string of up to 6 characters - but its not clear that this means the BLE device produces first 6 x key press input reports and then 6 x key release input reports, which is not what we want. So I started to write my own routine, like this one:

void send_HID_keys(uint8_t nLen, uint8_t* pKeys)
{
   uint8_t  i = 0;
   uint8_t  nKey;
   ret_code_t err_code;
   
   uint8_t  keyRep[INPUT_REPORT_KEYS_MAX_LEN];
   memset(keyRep, 0, INPUT_REPORT_KEYS_MAX_LEN);

   for (i=0; i<nLen; i++)
   {
      nKey = pKeys[i];

      keyRep[0] = 0;       // no modifiers Ctrl,Shift,Alt,GUI
      keyRep[1] = 0;       // reserved
      keyRep[2] = nKey;    // scancode of key (press)
         
      err_code = ble_hids_inp_rep_send(&m_hids,
                                  INPUT_REPORT_KEYS_INDEX,
                                  INPUT_REPORT_KEYS_MAX_LEN,
                                  keyRep,
                                  m_conn_handle);
      app_sched_execute();
      nrf_delay_ms(10);

      keyRep[2] = 0;       // release key
         
      err_code = ble_hids_inp_rep_send(&m_hids,
                                  INPUT_REPORT_KEYS_INDEX,
                                  INPUT_REPORT_KEYS_MAX_LEN,
                                  keyRep,
                                  m_conn_handle);
      app_sched_execute();
      nrf_delay_ms(10);

   }
}

The device based on nRF52832 is successfully paired and bonded to my Android Smartphone, I'm using the Jota text editor to check the HID input.

Each and every string I'm trying to send with this routine is not properly transmitted: something will always come through, but most common some characters are lost.

For example, I'm trying to send the string "103.23" (just numbers and a dot) and see "1.23" or "1109.23" etc...

I played aroung with the nrf_delay_ms() and the app_sched_execute() call is also seomthing I tried.
Without the app_sched_execute() the behaviour is much worse, usually leadint to an NO MEMORY exception after 2-3 tries.

The Nordic SDK documentation does not clearly explain how to use the ble_hids_inp_rep_send - at least I cant find a deeper explantion, such as is there any backgroiund thing needed, event handler after each input report or whatever.

It should be easy to reproduce this behaviour and I'm looking forward to any helpful input

thanks, Matthias

Parents Reply Children
No Data
Related