Note_N52832_BLE_Client_从控制LED灯改为写入buffer数据

TOC

参考工程: ble_app_blinky_pac1040_s132

修改lbs led控制函数声明

typedef void (*ble_lbs_led_write_handler_t) (uint16_t conn_handle, uint16_t len, uint8_t *data);

修改lbs 中write函数

/**@brief Function for handling the Write event.
 *
 * @param[in] p_lbs      LED Button Service structure.
 * @param[in] p_ble_evt  Event received from the BLE stack.
 */
static void on_write(ble_lbs_t * p_lbs, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t const * 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_ble_evt->evt.gap_evt.conn_handle, p_evt_write->len, (uint8_t *)p_evt_write->data);
    }
}

主程序

static void services_init(void)
{
    ......
    // Initialize LBS.
    init.led_write_handler = led_write_handler;
    ......
}

static void led_write_handler(uint16_t conn_handle, uint16_t len, uint8_t *data)
{
    /* user code */
}




posted @ 2020-12-29 21:35  JerryZheng2020  阅读(153)  评论(0编辑  收藏  举报