gatt-service/bas_server: update API

This commit is contained in:
Milanka Ringwald 2024-09-25 09:09:27 +02:00 committed by Matthias Ringwald
parent 3d715e85d3
commit ac8c27c43a
2 changed files with 17 additions and 9 deletions

View File

@ -480,14 +480,15 @@ static void battery_service_set_callback(battery_service_v1_server_connection_t
}
}
void battery_service_v1_server_set_battery_value(battery_service_v1_t * service, uint8_t value){
uint8_t battery_service_v1_server_set_battery_value(battery_service_v1_t * service, uint8_t battery_value){
btstack_assert(service != NULL);
if (service->battery_value == value){
return;
if (service->battery_value == battery_value){
return ERROR_CODE_REPEATED_ATTEMPTS;
}
service->battery_value = value;
if (battery_value > 100){
return ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE;
}
service->battery_value = battery_value;
uint8_t i;
for (i = 0; i < service->connections_max_num; i++){
@ -496,6 +497,7 @@ void battery_service_v1_server_set_battery_value(battery_service_v1_t * service,
battery_service_set_callback(connection, BAS_NOTIFICATION_TASK_BATTERY_VALUE_CHANGED);
}
}
return ERROR_CODE_SUCCESS;
}
void battery_service_v1_server_deregister(battery_service_v1_t *service){

View File

@ -286,15 +286,21 @@ typedef struct battery_service_v1 {
*/
void battery_service_v1_server_init(void);
void battery_service_v1_server_register(battery_service_v1_t *service, battery_service_v1_server_connection_t *connections, uint8_t connection_max_num);
void battery_service_v1_server_register(battery_service_v1_t * service, battery_service_v1_server_connection_t * connections, uint8_t connection_max_num);
void battery_service_v1_server_deregister(battery_service_v1_t * service);
void battery_service_v1_server_deregister(battery_service_v1_t *service);
/**
* @brief Update battery value
* @note triggers notifications if subscribed
* @param service
* @param battery_value in range 0-100
* @return ERROR_CODE_SUCCESS if value differs from old one, otherwise:
* - ERROR_CODE_REPEATED_ATTEMPTS, or
* - ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
*/
void battery_service_v1_server_set_battery_value(battery_service_v1_t * service, uint8_t value);
uint8_t battery_service_v1_server_set_battery_value(battery_service_v1_t * service, uint8_t battery_value);
void battery_service_v1_server_deinit(void);