Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Volume Offset Control Service #585

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Add Volume Offset Control Service #585

merged 1 commit into from
Nov 29, 2024

Conversation

wpiet
Copy link
Contributor

@wpiet wpiet commented Nov 8, 2024

Adds initial support for VOCS.

bumble/profiles/vocs.py Outdated Show resolved Hide resolved
attribute=self.audio_channel_location,
value=self.audio_location_bytes,
)
self.emit('audio_location', self.audio_location)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, it is preferable to not repeat in the event the changed state if that state already exists as a property of the emitter.
Here, for instance (the same idea applies to the other placed in this PR where events are emitted), a listener can access audio_location from the emitter, so there's no need to include that in the event.
a listener would do:
service.on('audio_location_change', ...)
and in the event handler, retrieve that actual values as service.audio_location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation. I removed these unnecessary properties from the events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current version of the service I was not sure how to handle events, so I removed them completely. If they are necessary, could you please give me some example?

bumble/profiles/vocs.py Outdated Show resolved Hide resolved
bumble/profiles/vocs.py Outdated Show resolved Hide resolved
'<hB',
)

self.audio_location = gatt.PackedCharacteristicAdapter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audio_location values are enums. We have an enum type for is already, in bap.AudioLocation. This could use a DelegatedCharacteristicAdapter to encode/decode to/from that type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I used these adapters in conjunction with from_bytes method which handles the enum type conversion. Is such usage correct?

bumble/profiles/vocs.py Outdated Show resolved Hide resolved
super().__init__(characteristics=characteristics, primary=False)

@property
def volume_offset_state_bytes(self) -> bytes:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this comment also applies to the other characteristics in this service)
Instead of having customized bytes serialization methods here, you should have shared adapters, used both for the service and service proxy.
Look at the heart_rate_service.py for an example of how this may be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the service implementation and added standalone classes for each characteristic with shared methods as you suggested.

MAX_VOLUME_OFFSET = 255
CHANGE_COUNTER_MAX_VALUE = 0xFF

SET_VOLUME_OFFSET_OPCODE = 0x01
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it might never extend, an enum opcode is more extendable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I changed that to an enum.

Adds initial support for VOCS.
@barbibulle barbibulle merged commit 0a12b2b into google:main Nov 29, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants