@@ -23,7 +23,7 @@ client_info_t client;
2323extern bool is_connected ; // Need this here in the case of disconnection
2424
2525// Characteristic Values
26- static const uint8_t val_batt_level = 0 ;
26+ static uint8_t val_batt_level = 0 ;
2727// 0% battery level (assume battery not present, for user to modify if need)
2828static uint8_t val_bat_cccd [] = {0x01 , 0x00 };
2929// CCCD allows the Central Device to enable/disable notifications/indications
@@ -479,6 +479,7 @@ esp_err_t copy_attribute_handles(int instance_id, uint16_t *handles, int num_han
479479 switch (instance_id ) {
480480 case INST_ID_BAT_SVC :
481481 memcpy (handle_table .handles_bat_svc , handles , num_handle * sizeof (uint16_t ));
482+ client .bat_attr_handle = handles [IDX_BAT_LVL_VAL ];
482483 return ESP_OK ;
483484 case INST_ID_HID :
484485 memcpy (handle_table .handles_hid_svc , handles , num_handle * sizeof (uint16_t ));
@@ -558,3 +559,21 @@ esp_err_t send_user_input(void)
558559 false // need_confirm
559560 );
560561}
562+
563+ esp_err_t set_hid_battery_level (uint8_t value )
564+ {
565+ if (value > 100 ) {
566+ value = 100 ;
567+ }
568+
569+ val_batt_level = value ;
570+
571+ return esp_ble_gatts_send_indicate (
572+ client .gatt_if , // gatts_if
573+ client .connection_id , // conn_id
574+ client .bat_attr_handle , // attr_handle
575+ 1 , // value_len
576+ & val_batt_level , // value
577+ false // need_confirm
578+ );
579+ }
0 commit comments