Skip to content

Commit 15c84e7

Browse files
committed
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.
1 parent 4fa2174 commit 15c84e7

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

pybricks/common/pb_type_control.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static mp_obj_t pb_type_Control_limits(size_t n_args, const mp_obj_t *pos_args,
9595
torque = pbio_control_settings_get_actuation_limit(&self->control->settings);
9696

9797
// If all given values are none, return current values
98-
if (speed_in == mp_const_none && acceleration_in == mp_const_none && torque_in == mp_const_none) {
98+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
9999
mp_obj_t ret[] = {
100100
mp_obj_new_int(speed),
101101
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_
134134
pbio_control_settings_get_pid(&self->control->settings, &kp, &ki, &kd, &integral_deadzone, &integral_change_max);
135135

136136
// If all given values are none, return current values
137-
if (kp_in == mp_const_none && ki_in == mp_const_none && kd_in == mp_const_none &&
138-
integral_rate_in == mp_const_none) {
137+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
139138
mp_obj_t ret[5];
140139
ret[0] = mp_obj_new_int(kp);
141140
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
171170
pbio_control_settings_get_target_tolerances(&self->control->settings, &speed, &position);
172171

173172
// If all given values are none, return current values
174-
if (speed_in == mp_const_none && position_in == mp_const_none) {
173+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
175174
mp_obj_t ret[2];
176175
ret[0] = mp_obj_new_int(speed);
177176
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 *
202201
pbio_control_settings_get_stall_tolerances(&self->control->settings, &speed, &time);
203202

204203
// If all given values are none, return current values
205-
if (speed_in == mp_const_none && time_in == mp_const_none) {
204+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
206205
mp_obj_t ret[2];
207206
ret[0] = mp_obj_new_int(speed);
208207
ret[1] = mp_obj_new_int_from_uint(time);

pybricks/common/pb_type_imu.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ static mp_obj_t pb_type_imu_settings(size_t n_args, const mp_obj_t *pos_args, mp
183183
(void)self;
184184

185185
// Return current values if no arguments are given.
186-
if (angular_velocity_threshold_in == mp_const_none &&
187-
acceleration_threshold_in == mp_const_none &&
188-
heading_correction_in == mp_const_none &&
189-
acceleration_correction_in == mp_const_none) {
190-
186+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
191187
// Raises if not set, so can safely dereference.
192188
pbio_imu_persistent_settings_t *get_settings;
193189
pb_assert(pbio_imu_get_settings(&get_settings));

pybricks/robotics/pb_type_drivebase.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,7 @@ static mp_obj_t pb_type_DriveBase_settings(size_t n_args, const mp_obj_t *pos_ar
346346
&turn_rate, &turn_acceleration, &turn_deceleration);
347347

348348
// If all given values are none, return current values
349-
if (straight_speed_in == mp_const_none &&
350-
straight_acceleration_in == mp_const_none &&
351-
turn_rate_in == mp_const_none &&
352-
turn_acceleration_in == mp_const_none
353-
) {
349+
if (PB_PARSE_ARGS_METHOD_ALL_NONE()) {
354350
mp_obj_t ret[] = {
355351
mp_obj_new_int(straight_speed),
356352
make_acceleration_return_value(straight_acceleration, straight_deceleration),

0 commit comments

Comments
 (0)