Skip to content

Commit

Permalink
pbio/uartdev: motor_flags becomes capability_flags
Browse files Browse the repository at this point in the history
Sensors seem to return useful flags also. For example, there seems to be
a bit that says whether the sensor requires to be powered via pins 1/2.

This commit only changes names, there's no changes to the code.
  • Loading branch information
laurensvalk committed Dec 23, 2020
1 parent 0f65f4b commit be2ab77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ PROCESS_THREAD(pbdrv_ioport_lpf2_process, ev, data) {
iodev->info = info;

const lump_mode_flags_t *flags = &info->mode_info[0].flags;
iodev->motor_flags = PBIO_IODEV_MOTOR_FLAG_NONE;
iodev->capability_flags = PBIO_IODEV_CAPABILITY_FLAG_NONE;
if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_POWER) {
iodev->motor_flags |= PBIO_IODEV_MOTOR_FLAG_IS_MOTOR;
iodev->capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR;
}
ioport->iodev = iodev;
}
Expand Down
22 changes: 11 additions & 11 deletions lib/pbio/include/pbio/iodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,38 +187,38 @@ typedef enum {
/**
* Convience value for no flags set.
*/
PBIO_IODEV_MOTOR_FLAG_NONE = 0,
PBIO_IODEV_CAPABILITY_FLAG_NONE = 0,
/**
* Indicates that this device is motor.
* Indicates that this device is a motor.
*/
PBIO_IODEV_MOTOR_FLAG_IS_MOTOR = 1 << 0,
PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR = 1 << 0,
/**
* Indicates that the motor provides speed feedback.
*/
PBIO_IODEV_MOTOR_FLAG_HAS_SPEED = 1 << 1,
PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_SPEED = 1 << 1,
/**
* Indicates that the motor provides relative position feedback.
*/
PBIO_IODEV_MOTOR_FLAG_HAS_REL_POS = 1 << 2,
PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS = 1 << 2,
/**
* Indicates that the motor provides absolute position feedback.
*/
PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS = 1 << 3,
} pbio_iodev_motor_flags_t;
PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS = 1 << 3,
} pbio_iodev_capability_flags_t;

/**
* Macro for testing if I/O device is a motor.
*
* @param [in] d Pointer to pbio_iodev_t.
*/
#define PBIO_IODEV_IS_MOTOR(d) ((d)->motor_flags & PBIO_IODEV_MOTOR_FLAG_IS_MOTOR)
#define PBIO_IODEV_IS_MOTOR(d) ((d)->capability_flags & PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR)

/**
* Macro for testing if I/O device is a motor with speed/position feedback.
*
* @param [in] d Pointer to pbio_iodev_t.
*/
#define PBIO_IODEV_IS_FEEDBACK_MOTOR(d) ((d)->motor_flags > PBIO_IODEV_MOTOR_FLAG_IS_MOTOR)
#define PBIO_IODEV_IS_FEEDBACK_MOTOR(d) ((d)->capability_flags > PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR)

/**
* Mapping flags that describe the input and output values of an I/O device.
Expand Down Expand Up @@ -377,9 +377,9 @@ struct _pbio_iodev_t {
*/
uint8_t mode;
/**
* Motor capability flags.
* Device capability flags.
*/
pbio_iodev_motor_flags_t motor_flags;
pbio_iodev_capability_flags_t capability_flags;
/**
* Most recent binary data read from the device. How to interpret this data
* is determined by the ::pbio_iodev_mode_t info associated with the current
Expand Down
14 changes: 7 additions & 7 deletions lib/pbio/src/uartdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ static void pbio_uartdev_parse_msg(uartdev_port_data_t *data) {
}

if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_POWER) {
data->iodev.motor_flags |= PBIO_IODEV_MOTOR_FLAG_IS_MOTOR;
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR;
}
if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_SPEED) {
data->iodev.motor_flags |= PBIO_IODEV_MOTOR_FLAG_HAS_SPEED;
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_SPEED;
}
if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_REL_POS) {
data->iodev.motor_flags |= PBIO_IODEV_MOTOR_FLAG_HAS_REL_POS;
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS;
}
if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_ABS_POS) {
data->iodev.motor_flags |= PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS;
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS;
}

debug_pr("new_mode: %d\n", data->new_mode);
Expand Down Expand Up @@ -680,7 +680,7 @@ static void pbio_uartdev_parse_msg(uartdev_port_data_t *data) {
// The counter driver must return the corrected count
data->tacho_count = tacho_count_msg - data->tacho_offset;

if (data->iodev.motor_flags & PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS) {
if (data->iodev.capability_flags & PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS) {
data->abs_pos = data->rx_msg[7] << 8 | data->rx_msg[6];
}
} else {
Expand Down Expand Up @@ -827,7 +827,7 @@ static PT_THREAD(pbio_uartdev_update(uartdev_port_data_t * data)) {

// reset state for new device
data->info->type_id = PBIO_IODEV_TYPE_ID_NONE;
data->iodev.motor_flags = PBIO_IODEV_MOTOR_FLAG_NONE;
data->iodev.capability_flags = PBIO_IODEV_CAPABILITY_FLAG_NONE;
data->ext_mode = 0;
data->status = PBIO_UARTDEV_STATUS_SYNCING;
// default max tacho rate for BOOST external motor since it is the only
Expand Down Expand Up @@ -1244,7 +1244,7 @@ static pbio_error_t pbio_uartdev_get_abs_count(pbdrv_counter_dev_t *dev, int32_t
return PBIO_ERROR_NO_DEV;
}

if (!(port_data->iodev.motor_flags & PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS)) {
if (!(port_data->iodev.capability_flags & PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS)) {
return PBIO_ERROR_NOT_SUPPORTED;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/pbio/test/src/uartdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ PT_THREAD(test_boost_color_distance_sensor(struct pt *pt)) {
tt_want_uint_op(iodev->info->num_view_modes, ==, 8);
// TODO: verify fw/hw versions
tt_want_uint_op(iodev->info->mode_combos, ==, 1 << 6 | 1 << 3 | 1 << 2 | 1 << 1 | 1 << 0);
tt_want_uint_op(iodev->motor_flags, ==, PBIO_IODEV_MOTOR_FLAG_NONE);
tt_want_uint_op(iodev->capability_flags, ==, PBIO_IODEV_CAPABILITY_FLAG_NONE);
tt_want_uint_op(iodev->mode, ==, 0);

tt_want_str_op(iodev->info->mode_info[0].name, ==, "COLOR");
Expand Down Expand Up @@ -777,8 +777,8 @@ PT_THREAD(test_boost_interactive_motor(struct pt *pt)) {
tt_want_uint_op(iodev->info->num_view_modes, ==, 3);
// TODO: verify fw/hw versions
tt_want_uint_op(iodev->info->mode_combos, ==, 1 << 2 | 1 << 1);
tt_want_uint_op(iodev->motor_flags, ==, PBIO_IODEV_MOTOR_FLAG_IS_MOTOR |
PBIO_IODEV_MOTOR_FLAG_HAS_SPEED | PBIO_IODEV_MOTOR_FLAG_HAS_REL_POS);
tt_want_uint_op(iodev->capability_flags, ==, PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR |
PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_SPEED | PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS);
tt_want_uint_op(iodev->mode, ==, 0);

tt_want_str_op(iodev->info->mode_info[0].name, ==, "POWER");
Expand Down Expand Up @@ -1048,8 +1048,8 @@ PT_THREAD(test_technic_large_motor(struct pt *pt)) {
tt_want_uint_op(iodev->info->num_view_modes, ==, 4);
// TODO: verify fw/hw versions
tt_want_uint_op(iodev->info->mode_combos, ==, 1 << 3 | 1 << 2 | 1 << 1);
tt_want_uint_op(iodev->motor_flags, ==, PBIO_IODEV_MOTOR_FLAG_IS_MOTOR | PBIO_IODEV_MOTOR_FLAG_HAS_SPEED
| PBIO_IODEV_MOTOR_FLAG_HAS_REL_POS | PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS);
tt_want_uint_op(iodev->capability_flags, ==, PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR | PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_SPEED
| PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS | PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS);
tt_want_uint_op(iodev->mode, ==, 0);

tt_want_str_op(iodev->info->mode_info[0].name, ==, "POWER");
Expand Down Expand Up @@ -1371,8 +1371,8 @@ PT_THREAD(test_technic_xl_motor(struct pt *pt)) {
tt_want_uint_op(iodev->info->num_view_modes, ==, 4);
// TODO: verify fw/hw versions
tt_want_uint_op(iodev->info->mode_combos, ==, 1 << 3 | 1 << 2 | 1 << 1);
tt_want_uint_op(iodev->motor_flags, ==, PBIO_IODEV_MOTOR_FLAG_IS_MOTOR | PBIO_IODEV_MOTOR_FLAG_HAS_SPEED
| PBIO_IODEV_MOTOR_FLAG_HAS_REL_POS | PBIO_IODEV_MOTOR_FLAG_HAS_ABS_POS);
tt_want_uint_op(iodev->capability_flags, ==, PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR | PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_SPEED
| PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS | PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS);
tt_want_uint_op(iodev->mode, ==, 0);

tt_want_str_op(iodev->info->mode_info[0].name, ==, "POWER");
Expand Down

0 comments on commit be2ab77

Please sign in to comment.