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

Disable HID some of the time

We are developing a device that has different "modes", and in some modes it acts as a HID keyboard and mouse, but in other modes it does not. This device connects to iOS and android, and in HID modes causes the virtual keyboard to be hidden as it is a HID keyboard. So in none-HID modes we want to avoid iOS recognising the device as a HID keyboard.

We have an existing device on a different platform which already implements this. When switching between HID and non-HID modes, it will modify the HID report and send a services modified indication for the HID service, causing iOS to re-read the HID report. This works fine.

What would be the best way to do the same thing on Nordic nRF52832? I've read that the GATT database cannot be modified without disconnection, which we want to avoid. Is there any way to do the same as on the existing platform – modify the HID report and send a services changed indication?

Parents
  • Hi Nick

    Sorry, there doesn't seem to be a way to find this in the peripheral. However, while scouring the DevZone, I found this case, which describes how to use the sd_ble_gatts_service_changed. Please check out Pål's answers, as they are very descriptive.

    Best regards,

    Simon

  • There is a way to find this information, here is a function that will determine the end handle for a given service handle:

    ret_code_t get_service_end_handle(uint16_t service_handle, uint16_t *end_handle) {
        VERIFY_PARAM_NOT_NULL(end_handle);
        ret_code_t err_code = NRF_SUCCESS;
        for (uint16_t handle = service_handle + 1; handle < UINT16_MAX; handle++) {
            ble_uuid_t uuid;
            err_code = sd_ble_gatts_attr_get(handle, &uuid, NULL);
            if (err_code == NRF_ERROR_NOT_FOUND) {
                *end_handle = handle - 1;
                return NRF_SUCCESS;
            }
            VERIFY_SUCCESS(err_code);
            if (uuid.type != BLE_UUID_TYPE_BLE ||
                (uuid.uuid != BLE_UUID_SERVICE_PRIMARY && uuid.uuid != BLE_UUID_SERVICE_SECONDARY)) {
                continue;
            }
            *end_handle = handle - 1;
            return NRF_SUCCESS;
        }
        *end_handle = UINT16_MAX;
        return NRF_ERROR_NOT_FOUND;
    }

    This end handle can then be passed to sd_ble_gatts_service_changed:

    ret_code_t service_changed(uint16_t conn_handle, uint16_t service_handle) {
        uint16_t service_end;
        (void)get_service_end_handle(service_handle, &service_end);
        return sd_ble_gatts_service_changed(conn_handle, service_handle, service_end);
    }

Reply
  • There is a way to find this information, here is a function that will determine the end handle for a given service handle:

    ret_code_t get_service_end_handle(uint16_t service_handle, uint16_t *end_handle) {
        VERIFY_PARAM_NOT_NULL(end_handle);
        ret_code_t err_code = NRF_SUCCESS;
        for (uint16_t handle = service_handle + 1; handle < UINT16_MAX; handle++) {
            ble_uuid_t uuid;
            err_code = sd_ble_gatts_attr_get(handle, &uuid, NULL);
            if (err_code == NRF_ERROR_NOT_FOUND) {
                *end_handle = handle - 1;
                return NRF_SUCCESS;
            }
            VERIFY_SUCCESS(err_code);
            if (uuid.type != BLE_UUID_TYPE_BLE ||
                (uuid.uuid != BLE_UUID_SERVICE_PRIMARY && uuid.uuid != BLE_UUID_SERVICE_SECONDARY)) {
                continue;
            }
            *end_handle = handle - 1;
            return NRF_SUCCESS;
        }
        *end_handle = UINT16_MAX;
        return NRF_ERROR_NOT_FOUND;
    }

    This end handle can then be passed to sd_ble_gatts_service_changed:

    ret_code_t service_changed(uint16_t conn_handle, uint16_t service_handle) {
        uint16_t service_end;
        (void)get_service_end_handle(service_handle, &service_end);
        return sd_ble_gatts_service_changed(conn_handle, service_handle, service_end);
    }

Children
No Data
Related