Skip to content

Commit

Permalink
pbio/iodev: add power requirement capability flag
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Dec 23, 2020
1 parent be2ab77 commit 6307fd7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/lego/lego_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ typedef enum {

/** This mode is a motor mode. */
LUMP_MODE_FLAGS0_MOTOR = 1 << 5,

/** This sensor mode requires battery voltage, not just logic voltage. */
LUMP_MODE_FLAGS0_REQUIRES_POWER = 1 << 6,
} lump_mode_flags0_t;

/**
Expand Down
14 changes: 13 additions & 1 deletion lib/pbio/include/pbio/iodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ typedef enum {
* Indicates that the motor provides absolute position feedback.
*/
PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS = 1 << 3,
/**
* Indicates that a sensor requires permanent battery voltage, not just logic voltage.
*/
PBIO_IODEV_CAPABILITY_FLAG_REQUIRES_POWER = 1 << 4,
} pbio_iodev_capability_flags_t;

/**
Expand All @@ -218,7 +222,15 @@ typedef enum {
*
* @param [in] d Pointer to pbio_iodev_t.
*/
#define PBIO_IODEV_IS_FEEDBACK_MOTOR(d) ((d)->capability_flags > PBIO_IODEV_CAPABILITY_FLAG_IS_MOTOR)
#define PBIO_IODEV_IS_FEEDBACK_MOTOR(d) ((d)->capability_flags & PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_REL_POS)

/**
* Macro for testing if I/O device requires battery power.
*
* @param [in] d Pointer to pbio_iodev_t.
*/
#define PBIO_IODEV_REQUIRES_POWER(d) ((d)->capability_flags & PBIO_IODEV_CAPABILITY_FLAG_REQUIRES_POWER)


/**
* Mapping flags that describe the input and output values of an I/O device.
Expand Down
3 changes: 3 additions & 0 deletions lib/pbio/src/uartdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ static void pbio_uartdev_parse_msg(uartdev_port_data_t *data) {
if (flags->flags0 & LUMP_MODE_FLAGS0_MOTOR_ABS_POS) {
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_HAS_MOTOR_ABS_POS;
}
if (flags->flags0 & LUMP_MODE_FLAGS0_REQUIRES_POWER) {
data->iodev.capability_flags |= PBIO_IODEV_CAPABILITY_FLAG_REQUIRES_POWER;
}

debug_pr("new_mode: %d\n", data->new_mode);
debug_pr("name: %s\n", data->info->mode_info[mode].name);
Expand Down

0 comments on commit 6307fd7

Please sign in to comment.