From 15c84e7c6afe7e7fcd9ccbaa95e1e95250e61370 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 21 Oct 2024 11:06:48 +0200 Subject: [PATCH] pybricks/util_mp: Use args None test. Since this is done in quite a few functions, this should make the build size smaller and the code easier to follow. --- pybricks/common/pb_type_control.c | 9 ++++----- pybricks/common/pb_type_imu.c | 6 +----- pybricks/robotics/pb_type_drivebase.c | 6 +----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/pybricks/common/pb_type_control.c b/pybricks/common/pb_type_control.c index 662e0b12a..29de973c6 100644 --- a/pybricks/common/pb_type_control.c +++ b/pybricks/common/pb_type_control.c @@ -95,7 +95,7 @@ static mp_obj_t pb_type_Control_limits(size_t n_args, const mp_obj_t *pos_args, torque = pbio_control_settings_get_actuation_limit(&self->control->settings); // If all given values are none, return current values - if (speed_in == mp_const_none && acceleration_in == mp_const_none && torque_in == mp_const_none) { + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { mp_obj_t ret[] = { mp_obj_new_int(speed), make_acceleration_return_value(acceleration, deceleration), @@ -134,8 +134,7 @@ static mp_obj_t pb_type_Control_pid(size_t n_args, const mp_obj_t *pos_args, mp_ pbio_control_settings_get_pid(&self->control->settings, &kp, &ki, &kd, &integral_deadzone, &integral_change_max); // If all given values are none, return current values - if (kp_in == mp_const_none && ki_in == mp_const_none && kd_in == mp_const_none && - integral_rate_in == mp_const_none) { + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { mp_obj_t ret[5]; ret[0] = mp_obj_new_int(kp); ret[1] = mp_obj_new_int(ki); @@ -171,7 +170,7 @@ static mp_obj_t pb_type_Control_target_tolerances(size_t n_args, const mp_obj_t pbio_control_settings_get_target_tolerances(&self->control->settings, &speed, &position); // If all given values are none, return current values - if (speed_in == mp_const_none && position_in == mp_const_none) { + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { mp_obj_t ret[2]; ret[0] = mp_obj_new_int(speed); ret[1] = mp_obj_new_int(position); @@ -202,7 +201,7 @@ static mp_obj_t pb_type_Control_stall_tolerances(size_t n_args, const mp_obj_t * pbio_control_settings_get_stall_tolerances(&self->control->settings, &speed, &time); // If all given values are none, return current values - if (speed_in == mp_const_none && time_in == mp_const_none) { + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { mp_obj_t ret[2]; ret[0] = mp_obj_new_int(speed); ret[1] = mp_obj_new_int_from_uint(time); diff --git a/pybricks/common/pb_type_imu.c b/pybricks/common/pb_type_imu.c index 4b06aa12d..43d7d1269 100644 --- a/pybricks/common/pb_type_imu.c +++ b/pybricks/common/pb_type_imu.c @@ -183,11 +183,7 @@ static mp_obj_t pb_type_imu_settings(size_t n_args, const mp_obj_t *pos_args, mp (void)self; // Return current values if no arguments are given. - if (angular_velocity_threshold_in == mp_const_none && - acceleration_threshold_in == mp_const_none && - heading_correction_in == mp_const_none && - acceleration_correction_in == mp_const_none) { - + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { // Raises if not set, so can safely dereference. pbio_imu_persistent_settings_t *get_settings; pb_assert(pbio_imu_get_settings(&get_settings)); diff --git a/pybricks/robotics/pb_type_drivebase.c b/pybricks/robotics/pb_type_drivebase.c index e89a61290..f1050f376 100644 --- a/pybricks/robotics/pb_type_drivebase.c +++ b/pybricks/robotics/pb_type_drivebase.c @@ -346,11 +346,7 @@ static mp_obj_t pb_type_DriveBase_settings(size_t n_args, const mp_obj_t *pos_ar &turn_rate, &turn_acceleration, &turn_deceleration); // If all given values are none, return current values - if (straight_speed_in == mp_const_none && - straight_acceleration_in == mp_const_none && - turn_rate_in == mp_const_none && - turn_acceleration_in == mp_const_none - ) { + if (PB_PARSE_ARGS_METHOD_ALL_NONE()) { mp_obj_t ret[] = { mp_obj_new_int(straight_speed), make_acceleration_return_value(straight_acceleration, straight_deceleration),