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

pybricks.common.Speaker: fix negative duration in beep() #279

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

dlech
Copy link
Member

@dlech dlech commented Dec 28, 2024

Return immediately if duration is negative as per documentation.

This works the same as with motor methods, with wait=False in that the method is not awaitable when duration is negative.

Issue: pybricks/support#1996

Return immediately if duration is negative as per documentation.

This works the same as with motor methods, with `wait=False` in that
the method is not awaitable when duration is negative.

Issue: pybricks/support#1996
@dlech
Copy link
Member Author

dlech commented Dec 28, 2024

Tested with:

from pybricks.hubs import PrimeHub
from pybricks.tools import wait

hub = PrimeHub()

while True:
    hub.speaker.beep(100, -1)
    wait(100)
    hub.speaker.beep(0, -1)
    wait(100)

@coveralls
Copy link

Coverage Status

coverage: 56.36%. remained the same
when pulling 316f124 on dlech:sound-negative-duration
into 3b5326a on pybricks:master.

@laurensvalk
Copy link
Member

Thank you! This looks good.

Can you also test it with an async program?

@dlech
Copy link
Member Author

dlech commented Jan 1, 2025

Works with async like this:

from pybricks.hubs import PrimeHub
from pybricks.tools import wait, run_task

hub = PrimeHub()

async def main():
    while True:
        hub.speaker.beep(100, -1)
        await wait(100)
        hub.speaker.beep(0, -1)
        await wait(100)

run_task(main())

@laurensvalk laurensvalk merged commit 4898777 into pybricks:master Jan 1, 2025
20 checks passed
@laurensvalk
Copy link
Member

Thank you!

@czuryk
Copy link

czuryk commented Jan 1, 2025

Thanks for quick resolving the issue!

@dlech dlech deleted the sound-negative-duration branch January 2, 2025 01:39
@laurensvalk
Copy link
Member

@czuryk If you want to try the fix, you can do so with these instructions.

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.

4 participants