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

HID demo restart cound't control any more

I programmed to nRF51 DK, the first time the device is connected to mobile phone.It works, but if i turn off the nRF51 DK and then turn it on.it is connected but it cound't control any more. This is my demo nRF51822_HID_KEYBOARD_MOUSE_C_20170926.rar.

#define DM_GATT_CCCD_COUNT 9

Ithink here have a question.

Parents
  • Also change the function on_hids_evt() in main.c so it looks like this:

    static void on_hids_evt(ble_hids_t *p_hids, ble_hids_evt_t *p_evt)
    {
        switch (p_evt->evt_type)
        {
            case BLE_HIDS_EVT_BOOT_MODE_ENTERED:
                m_in_boot_mode = true;
                break;
    
            case BLE_HIDS_EVT_REPORT_MODE_ENTERED:
                m_in_boot_mode = false;
                break;
            case BLE_HIDS_EVT_REP_CHAR_WRITE:
                on_hid_rep_char_write(p_evt);
                break;
    
            case BLE_HIDS_EVT_NOTIF_ENABLED:
            {
                dm_service_context_t service_context;
                service_context.service_type        = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;
                service_context.context_data.len    = 0;
                service_context.context_data.p_data = NULL;
                if (m_in_boot_mode)
                {
                    // Protocol mode is Boot Protocol mode.
                    if (
                        p_evt->params.notification.char_id.uuid == BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR || p_evt->params.notification.char_id.uuid == BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR)
                    {
                        // The notification of boot mouse input report has been enabled.
                        // Save the system attribute (CCCD) information into the flash.
                        uint32_t err_code;
    
                        err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                        if (err_code != NRF_ERROR_INVALID_STATE)
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                        else
                        {
                            // The system attributes could not be written to the flash because
                            // the connected central is not a new central. The system attributes
                            // will only be written to flash only when disconnected from this central.
                            // Do nothing now.
                        }
                    }
                    else
                    {
                        // Do nothing.
                    }
                }
                else if (
                    (p_evt->params.notification.char_id.rep_index == INPUT_REP_MOVEMENT_INDEX) &&
                    (p_evt->params.notification.char_id.rep_type == BLE_HIDS_REP_TYPE_INPUT))
                {
                    // The protocol mode is Report Protocol mode. And the CCCD for the report ID
                    // INPUT_REP_MOVEMENT_INDEX is changed. Since this application uses this report to
                    // send mouse movements, it is now time to store all the CCCD information (system
                    // attributes) into the flash.
                    uint32_t err_code;
    
                    err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                    else
                    {
                        // The system attributes could not be written to the flash because
                        // the connected central is not a new central. The system attributes
                        // will only be written to flash only when disconnected from this central.
                        // Do nothing now.
                    }
                }
                else
                {
                    uint32_t err_code;
    
                    err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
                break;
            }
    
            default:
                // No implementation needed.
                break;
        }
    }
    
Reply
  • Also change the function on_hids_evt() in main.c so it looks like this:

    static void on_hids_evt(ble_hids_t *p_hids, ble_hids_evt_t *p_evt)
    {
        switch (p_evt->evt_type)
        {
            case BLE_HIDS_EVT_BOOT_MODE_ENTERED:
                m_in_boot_mode = true;
                break;
    
            case BLE_HIDS_EVT_REPORT_MODE_ENTERED:
                m_in_boot_mode = false;
                break;
            case BLE_HIDS_EVT_REP_CHAR_WRITE:
                on_hid_rep_char_write(p_evt);
                break;
    
            case BLE_HIDS_EVT_NOTIF_ENABLED:
            {
                dm_service_context_t service_context;
                service_context.service_type        = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;
                service_context.context_data.len    = 0;
                service_context.context_data.p_data = NULL;
                if (m_in_boot_mode)
                {
                    // Protocol mode is Boot Protocol mode.
                    if (
                        p_evt->params.notification.char_id.uuid == BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR || p_evt->params.notification.char_id.uuid == BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR)
                    {
                        // The notification of boot mouse input report has been enabled.
                        // Save the system attribute (CCCD) information into the flash.
                        uint32_t err_code;
    
                        err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                        if (err_code != NRF_ERROR_INVALID_STATE)
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                        else
                        {
                            // The system attributes could not be written to the flash because
                            // the connected central is not a new central. The system attributes
                            // will only be written to flash only when disconnected from this central.
                            // Do nothing now.
                        }
                    }
                    else
                    {
                        // Do nothing.
                    }
                }
                else if (
                    (p_evt->params.notification.char_id.rep_index == INPUT_REP_MOVEMENT_INDEX) &&
                    (p_evt->params.notification.char_id.rep_type == BLE_HIDS_REP_TYPE_INPUT))
                {
                    // The protocol mode is Report Protocol mode. And the CCCD for the report ID
                    // INPUT_REP_MOVEMENT_INDEX is changed. Since this application uses this report to
                    // send mouse movements, it is now time to store all the CCCD information (system
                    // attributes) into the flash.
                    uint32_t err_code;
    
                    err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                    else
                    {
                        // The system attributes could not be written to the flash because
                        // the connected central is not a new central. The system attributes
                        // will only be written to flash only when disconnected from this central.
                        // Do nothing now.
                    }
                }
                else
                {
                    uint32_t err_code;
    
                    err_code = dm_service_context_set(&m_bonded_peer_handle, &service_context);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
                break;
            }
    
            default:
                // No implementation needed.
                break;
        }
    }
    
Children
No Data
Related