Skip to content

Commit

Permalink
pybricks.iodevices.XboxController: Add rumble defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Mar 20, 2024
1 parent 5dfd49f commit c38c6c0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pybricks/iodevices/pb_type_iodevices_xbox_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ typedef struct {
STATIC mp_obj_t pb_xbox_rumble(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
PB_PARSE_ARGS_METHOD(n_args, pos_args, kw_args,
pb_type_xbox_obj_t, self,
PB_ARG_REQUIRED(power),
PB_ARG_REQUIRED(duration),
PB_ARG_REQUIRED(delay),
PB_ARG_REQUIRED(count)
PB_ARG_DEFAULT_INT(power, 100),
PB_ARG_DEFAULT_INT(duration, 200),
PB_ARG_DEFAULT_INT(delay, 100),
PB_ARG_DEFAULT_INT(count, 1)
);

(void)self;
Expand All @@ -488,6 +488,11 @@ STATIC mp_obj_t pb_xbox_rumble(size_t n_args, const mp_obj_t *pos_args, mp_map_t
// Number of rumbles, capped at 100.
mp_int_t count = pb_obj_get_pct(count_in);

// Don't prefix delay if there is only one rumble.
if (count == 1) {
delay = 0;
}

// User order is left, right, left trigger, right trigger.
int8_t intensity[4];
pb_obj_get_pct_or_array(power_in, 4, intensity);
Expand Down

0 comments on commit c38c6c0

Please sign in to comment.