avrcp_controller: rename event

This commit is contained in:
Milanka Ringwald 2021-10-26 16:58:00 +02:00
parent 79464f8d52
commit b2e02b8d16
6 changed files with 40 additions and 26 deletions

View File

@ -147,7 +147,7 @@ static int volume_percentage = 0;
static avrcp_battery_status_t battery_status = AVRCP_BATTERY_STATUS_WARNING;
#ifdef SUPPORT_VOLUME_CHANGE_NOTIFICATION
static uint8_t events_num = 4;
static uint8_t events[] = {
AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED,
AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED,
@ -744,7 +744,7 @@ static void avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel, u
case AVRCP_SUBEVENT_EVENT_IDS_QUERY:
#ifdef SUPPORT_VOLUME_CHANGE_NOTIFICATION
avrcp_target_supported_events(avrcp_cid, events_num, events, sizeof(events));
avrcp_target_supported_events(avrcp_cid, sizeof(events)/sizeof(uint8_t), events, sizeof(events));
#else
avrcp_target_supported_events(avrcp_cid, 0, NULL, 0);
#endif

View File

@ -849,14 +849,10 @@ static void avrcp_controller_packet_handler(uint8_t packet_type, uint16_t channe
// see avrcp_battery_status_t
printf("AVRCP Controller: Notification Battery Status %d\n", avrcp_subevent_notification_event_batt_status_changed_get_battery_status(packet));
break;
case AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE:
printf("AVRCP Controller: Notification %s ", avrcp_event2str(avrcp_subevent_enable_notification_complete_get_event_id(packet)));
if (avrcp_subevent_enable_notification_complete_get_status(packet) == ERROR_CODE_SUCCESS){
printf("enabled\n");
} else {
printf("disabled\n");
}
case AVRCP_SUBEVENT_NOTIFICATION_STATE:
printf("AVRCP Controller: Notification %s - %s\n",
avrcp_event2str(avrcp_subevent_notification_state_get_event_id(packet)),
avrcp_subevent_notification_state_get_enabled(packet) != 0 ? "enabled" : "disabled");
break;
default:
break;

View File

@ -2690,13 +2690,14 @@ typedef uint8_t sm_key_t[16];
#define AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE 0x10
/**
* @format 1211
* @format 12111
* @param subevent_code
* @param avrcp_cid
* @param status
* @param enabled // 1 enabled, 0 disabled
* @param event_id
*/
#define AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE 0x11
#define AVRCP_SUBEVENT_NOTIFICATION_STATE 0x11
/**
* @format 112B2

View File

@ -8180,31 +8180,40 @@ static inline uint8_t avrcp_subevent_set_absolute_volume_response_get_absolute_v
}
/**
* @brief Get field avrcp_cid from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @brief Get field avrcp_cid from event AVRCP_SUBEVENT_NOTIFICATION_STATE
* @param event packet
* @return avrcp_cid
* @note: btstack_type 2
*/
static inline uint16_t avrcp_subevent_enable_notification_complete_get_avrcp_cid(const uint8_t * event){
static inline uint16_t avrcp_subevent_notification_state_get_avrcp_cid(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field status from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @brief Get field status from event AVRCP_SUBEVENT_NOTIFICATION_STATE
* @param event packet
* @return status
* @note: btstack_type 1
*/
static inline uint8_t avrcp_subevent_enable_notification_complete_get_status(const uint8_t * event){
static inline uint8_t avrcp_subevent_notification_state_get_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field event_id from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @brief Get field enabled from event AVRCP_SUBEVENT_NOTIFICATION_STATE
* @param event packet
* @return enabled
* @note: btstack_type 1
*/
static inline uint8_t avrcp_subevent_notification_state_get_enabled(const uint8_t * event){
return event[6];
}
/**
* @brief Get field event_id from event AVRCP_SUBEVENT_NOTIFICATION_STATE
* @param event packet
* @return event_id
* @note: btstack_type 1
*/
static inline uint8_t avrcp_subevent_enable_notification_complete_get_event_id(const uint8_t * event){
return event[6];
static inline uint8_t avrcp_subevent_notification_state_get_event_id(const uint8_t * event){
return event[7];
}
/**

View File

@ -92,15 +92,16 @@ static int avrcp_controller_supports_browsing(uint16_t controller_supported_feat
return controller_supported_features & AVRCP_FEATURE_MASK_BROWSING;
}
static void avrcp_controller_emit_notification_complete(avrcp_connection_t * connection, uint8_t status, uint8_t event_id){
uint8_t event[7];
static void avrcp_controller_emit_notification_complete(avrcp_connection_t * connection, uint8_t status, uint8_t event_id, bool enabled){
uint8_t event[8];
uint8_t pos = 0;
event[pos++] = HCI_EVENT_AVRCP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE;
event[pos++] = AVRCP_SUBEVENT_NOTIFICATION_STATE;
little_endian_store_16(event, pos, connection->avrcp_cid);
pos += 2;
event[pos++] = status;
event[pos++] = enabled ? 1 : 0;
event[pos++] = event_id;
UNUSED(pos);
(*avrcp_controller_context.avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
@ -755,7 +756,7 @@ static void avrcp_controller_handle_notification(avrcp_connection_t *connection,
return;
}
// emit event only once, initially
avrcp_controller_emit_notification_complete(connection, ERROR_CODE_SUCCESS, event_id);
avrcp_controller_emit_notification_complete(connection, ERROR_CODE_SUCCESS, event_id, true);
connection->initial_status_reported |= event_mask;
break;
case AVRCP_CTYPE_RESPONSE_CHANGED_STABLE:
@ -767,6 +768,9 @@ static void avrcp_controller_handle_notification(avrcp_connection_t *connection,
avrcp_controller_register_notification(connection, event_id);
} else {
connection->notifications_to_deregister &= reset_event_mask;
connection->notifications_to_register &= reset_event_mask;
connection->initial_status_reported &= reset_event_mask;
avrcp_controller_emit_notification_complete(connection, ERROR_CODE_SUCCESS, event_id, false);
}
break;
default:
@ -1033,7 +1037,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
for (i = (uint8_t)AVRCP_NOTIFICATION_EVENT_FIRST_INDEX; i < (uint8_t) AVRCP_NOTIFICATION_EVENT_LAST_INDEX; i++){
if ((connection->notifications_to_register & (1<<i)) != 0){
if ((connection->remote_supported_notifications & (1<<i)) == 0){
avrcp_controller_emit_notification_complete(connection, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE, i);
avrcp_controller_emit_notification_complete(connection, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE, i, false);
connection->notifications_to_register &= ~(1 << i);
}
}
@ -1382,6 +1386,10 @@ uint8_t avrcp_controller_disable_notification(uint16_t avrcp_cid, avrcp_notifica
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
}
if (connection->notifications_enabled & (1 << event_id) == 0){
return ERROR_CODE_SUCCESS;
}
connection->notifications_to_deregister |= (1 << event_id);
return ERROR_CODE_SUCCESS;
}

View File

@ -226,7 +226,7 @@ uint8_t avrcp_controller_press_and_hold_mute(uint16_t avrcp_cid);
uint8_t avrcp_controller_get_play_status(uint16_t avrcp_cid);
/**
* @brief Enable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE.
* @brief Enable notification. Response via AVRCP_SUBEVENT_NOTIFICATION_STATE.
* @param avrcp_cid
* @param event_id
* @returns status
@ -234,7 +234,7 @@ uint8_t avrcp_controller_get_play_status(uint16_t avrcp_cid);
uint8_t avrcp_controller_enable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id);
/**
* @brief Disable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE.
* @brief Disable notification. Response via AVRCP_SUBEVENT_NOTIFICATION_STATE.
* @param avrcp_cid
* @param event_id
* @returns status