Skip to content

Commit 316f124

Browse files
committed
pybricks.common.Speaker: fix negative duration in beep()
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
1 parent 3b5326a commit 316f124

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
- Fixed `DriveBase.angle()` getting an incorrectly rounded gyro value, which
3636
could cause `turn(360)` to be off by a degree ([support#1844]).
3737
- Fixed `hub` silently ignoring non-orthogonal base axis when it should raise.
38+
- Fixed not handling negative duration in `Speaker.beep()` ([support#1996]).
3839

3940
[pybricks-micropython#274]: https://github.com/pybricks/pybricks-micropython/pull/274
4041
[support#943]: https://github.com/pybricks/support/issues/943
4142
[support#1886]: https://github.com/pybricks/support/issues/1886
4243
[support#1844]: https://github.com/pybricks/support/issues/1844
43-
[support#1875]: https://github.com/pybricks/support/issues/1975
44+
[support#1975]: https://github.com/pybricks/support/issues/1975
45+
[support#1996]: https://github.com/pybricks/support/issues/1996
4446

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

pybricks/common/pb_type_speaker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static mp_obj_t pb_type_Speaker_beep(size_t n_args, const mp_obj_t *pos_args, mp
152152
pb_type_Speaker_start_beep(frequency, self->sample_attenuator);
153153

154154
if (duration < 0) {
155-
duration = 0;
155+
return mp_const_none;
156156
}
157157

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

0 commit comments

Comments
 (0)