/**@brief Battery level Collector Handler. **************************************** */ static void bas_c_evt_handler(ble_bas_c_t * p_bas_c, ble_bas_c_evt_t * p_bas_c_evt) { uint32_t err_code; switch (p_bas_c_evt->evt_type) { case BLE_BAS_C_EVT_DISCOVERY_COMPLETE: // Battery service discovered. Enable notification of Battery Level. APPL_LOG("[APPL]: Battery Service discovered. \r\n"); APPL_LOG("[APPL]: Reading battery level. \r\n"); err_code = ble_bas_c_bl_read(p_bas_c); APP_ERROR_CHECK(err_code); APPL_LOG("[APPL]: Enabling Battery Level Notification. \r\n"); err_code = ble_bas_c_bl_notif_enable(p_bas_c); APP_ERROR_CHECK(err_code); printf("Battery service discovered \r\n"); break; case BLE_BAS_C_EVT_BATT_NOTIFICATION: { APPL_LOG("[APPL]: Battery Level received %d %%\r\n", p_bas_c_evt->params.battery_level); uint8_t batteryLevel = p_bas_c_evt->params.battery_level; // Normalize the battery level //if(batteryLevel > 100) batteryLevel = 100; batteryLevel = batteryLevel < 100 ? batteryLevel : 100; printf("batteryLevel = %d %%\r\n", batteryLevel); while(app_pwm_channel_duty_set(&PWM1, 0, batteryLevel) == NRF_ERROR_BUSY) printf("Battery = %d %%\r\n", batteryLevel); break; } case BLE_BAS_C_EVT_BATT_READ_RESP: { APPL_LOG("[APPL]: Battery Level Read as %d %%\r\n", p_bas_c_evt->params.battery_level); //printf("Battery Read As = %d %%\r\n", p_bas_c_evt->params.battery_level); break; } default: break; } }
/**@brief Battery levelCollector Handler. */ static void bas_c_evt_handler(ble_bas_c_t * p_bas_c, ble_bas_c_evt_t * p_bas_c_evt) { uint32_t err_code; switch (p_bas_c_evt->evt_type) { case BLE_BAS_C_EVT_DISCOVERY_COMPLETE: // Batttery service discovered. Enable notification of Battery Level. APPL_LOG("[APPL]: Battery Service discovered. \r\n"); APPL_LOG("[APPL]: Reading battery level. \r\n"); err_code = ble_bas_c_bl_read(p_bas_c); APP_ERROR_CHECK(err_code); APPL_LOG("[APPL]: Enabling Battery Level Notification. \r\n"); err_code = ble_bas_c_bl_notif_enable(p_bas_c); APP_ERROR_CHECK(err_code); break; case BLE_BAS_C_EVT_BATT_NOTIFICATION: { APPL_LOG("[APPL]: Battery Level received %d %%\r\n", p_bas_c_evt->params.battery_level); printf("Battery = %d %%\r\n", p_bas_c_evt->params.battery_level); break; } case BLE_BAS_C_EVT_BATT_READ_RESP: { APPL_LOG("[APPL]: Battery Level Read as %d %%\r\n", p_bas_c_evt->params.battery_level); printf("Battery = %d %%\r\n", p_bas_c_evt->params.battery_level); break; } default: break; } }