Skip to content

Commit

Permalink
pybricks.common.Speaker: Fix negative duration in beep().
Browse files Browse the repository at this point in the history
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.

Fixes: pybricks/support#1996
  • Loading branch information
dlech authored Jan 1, 2025
1 parent 3b5326a commit 4898777
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
- Fixed `DriveBase.angle()` getting an incorrectly rounded gyro value, which
could cause `turn(360)` to be off by a degree ([support#1844]).
- Fixed `hub` silently ignoring non-orthogonal base axis when it should raise.
- Fixed not handling negative duration in `Speaker.beep()` ([support#1996]).

[pybricks-micropython#274]: https://github.com/pybricks/pybricks-micropython/pull/274
[support#943]: https://github.com/pybricks/support/issues/943
[support#1886]: https://github.com/pybricks/support/issues/1886
[support#1844]: https://github.com/pybricks/support/issues/1844
[support#1875]: https://github.com/pybricks/support/issues/1975
[support#1975]: https://github.com/pybricks/support/issues/1975
[support#1996]: https://github.com/pybricks/support/issues/1996

## [3.6.0b2] - 2024-10-15

Expand Down
2 changes: 1 addition & 1 deletion pybricks/common/pb_type_speaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static mp_obj_t pb_type_Speaker_beep(size_t n_args, const mp_obj_t *pos_args, mp
pb_type_Speaker_start_beep(frequency, self->sample_attenuator);

if (duration < 0) {
duration = 0;
return mp_const_none;
}

self->beep_end_time = mp_hal_ticks_ms() + (uint32_t)duration;
Expand Down

0 comments on commit 4898777

Please sign in to comment.