52832 MDK Code Analysis LEDs and keys

Source: Internet
Author: User

ON_BLE_EVT--Ble_evt_dispatch---Ble_stack_init


Ble_lbs_on_button_change

static void On_write (ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)//contains data sent from the phone
{
ble_gatts_evt_write_t * P_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

if ((P_evt_write->handle = = P_lbs->led_char_handles.value_handle) &&
(P_evt_write->len = = 1) &&
(P_lbs->led_write_handler! = NULL))
{
P_lbs->led_write_handler (p_lbs, p_evt_write->data[0]);
}
}

P_evt_write->data[0] There is a private agreement in the bread

Here are the code differences between the two functions:
static void On_write (ble_evt_t * p_ble_evt)
On_write-BLE_CONN_PARAMS_ON_BLE_EVT (ble_evt_t * p_ble_evt)-Ble_evt_dispatch (ble_evt_t * p_ble_evt)- Ble_stack_init--
static void On_write (ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
On_write--BLE_LBS_ON_BLE_EVT (ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)--Ble_evt_dispatch (ble_evt_t * P_ble_ev T)--Ble_stack_init


function Analysis of keys
Analysis of the Button_event_handler function

Button_event_handler-Buttons_init

#define BUTTON_1 13
#define BUTTON_2 14
#define BUTTON_3 15
#define BUTTON_4 16

static void Buttons_init (void)
{
uint32_t Err_code;

   //the array must is static because a pointer to it would be saved in the button handler module.
    static app_button_cfg_t buttons[] =
    {
         {Ledbutton_button_pin, False, Button_pull, Button_event_handler},
         {, False, Button_pull, button_event_handler},//the key value added according to the routine
         {button_pull, False, Button_event_handler},
        {16, False, Button_pull, Button_event_handler}
       
   };

    Err_code = app_button_init (buttons, sizeof (buttons)/sizeof (Buttons[0]),
                                 button_detection_delay);
    App_error_check (Err_code);
}

typedef struct
{
uint8_t Pin_no; /**< Pin to is used as a button. */
uint8_t active_state; /**< App_button_active_high or App_button_active_low. */
nrf_gpio_pin_pull_t pull_cfg; /**< pull-up or-down configuration. */
app_button_handler_t Button_handler; /**< Handler to being called when button is pushed. */
} app_button_cfg_t;

SD_BLE_GATTS_HVX (P_lbs->conn_handle, &params);
--uint32_t Ble_lbs_on_button_change (ble_lbs_t * p_lbs, uint8_t button_state)
--static void Button_event_handler (uint8_t pin_no, uint8_t button_action)


Analysis of LED lights:
static void Led_write_handler (ble_lbs_t * p_lbs, uint8_t led_state)


static void Led_write_handler (ble_lbs_t * p_lbs, uint8_t led_state)
{
if (led_state)
{
LEDS_ON (bsp_led_2_mask);//bsp_led_2_mask Ledbutton_led_pin
LEDS_ON (Bsp_led_3_mask);
Nrf_log_info ("Received LED on!\r\n");
}
Else
{
Leds_off (Bsp_led_2_mask);
Leds_off (Bsp_led_3_mask);
Nrf_log_info ("Received LED off!\r\n");
}
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.