Hi in my original code when notifications is turned on for custom characteristic the characteristic value would increment every second. However after I add NRF_SDH_BLE_OBSERVERS() so I can add multiple custom services, I notice the characteristic value no longer increments every second when notifications is turned on.
If I switch back to NRF_SDH_BLE_OBSERVER() and turn on notifications the characteristic value increments every second again.
/*
#define BLE_CUS_DEF(_name) \
static ble_cus_t _name; \
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
BLE_HRS_BLE_OBSERVER_PRIO, \
ble_cus_on_ble_evt, &_name)
*/
#define BLE_CUS_DEF(_name) \
static ble_cus_t _name;
#define BLE_CUS_DEF2(_name2) \
static ble_cus_t _name2; //\
#define ble_cus_t* cus_array[] = {&_name, &_name2}; \
NRF_SDH_BLE_OBSERVERS(_name ## _obs, \
BLE_HRS_BLE_OBSERVER_PRIO, \
ble_cus_on_ble_evt, cus_array, 2)
In the code, 'notification_timeout_handler' is called when the repeated app timer 'm_notification_timer_id' expires. The 'notification_timeout_handler' increments the value of integer variable 'm_custom_value' each time the app_timer event handler is called.
APP_TIMER_DEF(m_notification_timer_id);
static uint8_t m_custom_value = 0;
static uint8_t notif_bool = 0;
static void notification_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code;
// Increment the value of m_custom_value before nortifing it.
m_custom_value++;
if(notif_bool == 1){
err_code = ble_cus_custom_value_update(&m_cus, m_custom_value);
//APP_ERROR_CHECK(err_code);
}
}
static void timers_init(void)
{
// Initialize timer module.
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
// Create timers.
err_code = app_timer_create(&m_notification_timer_id, APP_TIMER_MODE_REPEATED, notification_timeout_handler);
APP_ERROR_CHECK(err_code);
}
tatic void on_cus_evt(ble_cus_t * p_cus_service,
ble_cus_evt_t * p_evt)
{
ret_code_t err_code;
switch(p_evt->evt_type)
{
case BLE_CUS_EVT_NOTIFICATION_ENABLED:
notif_bool = 1;
break;
case BLE_CUS_EVT_NOTIFICATION_DISABLED:
break;
}
I also attached the project files below.
Why does calling NRF_SDH_BLE_OBSERVERS() to register multiple custom services cause the event handler call from the repeated app timer to not work? Is there a way to fix this if I want to have multiple custom services and the app_timer event handler?