Skip to content

Commit

Permalink
pybricks.tools.StopWatch: Add running check.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Mar 4, 2024
1 parent 6eb4c96 commit 286c8d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
### Added
- Added `joystick_deadzone` keyword argument to suppress controller drift in
the `XboxController` ([support#1473]).
- Added `pybricks.tools.running` to return if a stopwatch is currently running
([support#1490]).

### Changed
- Use `Button` parameter for `XboxController` ([support#1488]), not strings.
Expand All @@ -26,6 +28,7 @@
[support#1453]: https://github.com/pybricks/support/issues/1453
[support#1473]: https://github.com/pybricks/support/issues/1473
[support#1488]: https://github.com/pybricks/support/issues/1488
[support#1490]: https://github.com/pybricks/support/issues/1490
[support#1499]: https://github.com/pybricks/support/issues/1499
[support#1502]: https://github.com/pybricks/support/issues/1502

Expand Down
8 changes: 8 additions & 0 deletions pybricks/tools/pb_type_stopwatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ STATIC mp_obj_t tools_StopWatch_pause(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(tools_StopWatch_pause_obj, tools_StopWatch_pause);

STATIC mp_obj_t tools_StopWatch_running(mp_obj_t self_in) {
tools_StopWatch_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(self->running);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(tools_StopWatch_running_obj, tools_StopWatch_running);

STATIC mp_obj_t tools_StopWatch_resume(mp_obj_t self_in) {
tools_StopWatch_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (!self->running) {
Expand All @@ -62,6 +68,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(tools_StopWatch_resume_obj, tools_StopWatch_res
STATIC mp_obj_t tools_StopWatch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
tools_StopWatch_obj_t *self = m_new_obj(tools_StopWatch_obj_t);
self->base.type = type;
self->running = false;
tools_StopWatch_reset(MP_OBJ_FROM_PTR(self));
tools_StopWatch_resume(MP_OBJ_FROM_PTR(self));
return MP_OBJ_FROM_PTR(self);
Expand All @@ -72,6 +79,7 @@ STATIC const mp_rom_map_elem_t tools_StopWatch_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&tools_StopWatch_time_obj) },
{ MP_ROM_QSTR(MP_QSTR_pause), MP_ROM_PTR(&tools_StopWatch_pause_obj) },
{ MP_ROM_QSTR(MP_QSTR_resume), MP_ROM_PTR(&tools_StopWatch_resume_obj) },
{ MP_ROM_QSTR(MP_QSTR_running), MP_ROM_PTR(&tools_StopWatch_running_obj) },
};
STATIC MP_DEFINE_CONST_DICT(tools_StopWatch_locals_dict, tools_StopWatch_locals_dict_table);

Expand Down

0 comments on commit 286c8d8

Please sign in to comment.