Skip to content

Commit

Permalink
pybricks.pupdevices.Light: Fix dcmotor setup.
Browse files Browse the repository at this point in the history
While setting the direction does not matter for the light, running the setup is still required to make sure settings like max_voltage are configured at least once.

Also use user call for setting the voltage instead of the system call in case we ever have more advanced light processes. Like passive motor calls, this will stop the associated process.

Partially fixes pybricks/support#1131.
  • Loading branch information
laurensvalk committed Jul 3, 2023
1 parent c087f98 commit ef4ae70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [Unreleased]

- Fixed Technic (Extra) Large motors not working ([support#1131]) on all hubs.
- Fixed Powered Up Light not working ([support#1131]) on all hubs.

[support#1064]: https://github.com/pybricks/support/issues/1131

Expand Down
5 changes: 3 additions & 2 deletions pybricks/pupdevices/pb_type_pupdevices_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ STATIC mp_obj_t pupdevices_Light_make_new(const mp_obj_type_t *type, size_t n_ar

// Get and initialize DC Motor
pb_assert(pbio_dcmotor_get_dcmotor(legodev, &self->dcmotor));
pb_assert(pbio_dcmotor_setup(self->dcmotor, PBDRV_LEGODEV_TYPE_ID_LPF2_LIGHT, PBIO_DIRECTION_CLOCKWISE));

return MP_OBJ_FROM_PTR(self);
}
Expand All @@ -49,7 +50,7 @@ STATIC mp_obj_t pupdevices_Light_on(size_t n_args, const mp_obj_t *pos_args, mp_

// Set the brightness
int32_t voltage = pbio_battery_get_voltage_from_duty_pct(pb_obj_get_pct(brightness_in));
pb_assert(pbio_dcmotor_set_voltage(self->dcmotor, voltage));
pb_assert(pbio_dcmotor_user_command(self->dcmotor, false, -voltage));

return mp_const_none;
}
Expand All @@ -58,7 +59,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pupdevices_Light_on_obj, 1, pupdevices_Light_on);
// pybricks.pupdevices.Light.off
STATIC mp_obj_t pupdevices_Light_off(mp_obj_t self_in) {
pupdevices_Light_obj_t *self = MP_OBJ_TO_PTR(self_in);
pb_assert(pbio_dcmotor_set_voltage(self->dcmotor, 0));
pb_assert(pbio_dcmotor_user_command(self->dcmotor, true, 0));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pupdevices_Light_off_obj, pupdevices_Light_off);
Expand Down

0 comments on commit ef4ae70

Please sign in to comment.