From 6307fd765a8d7d0db2f5b781eb4b8ac1ab072303 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Sat, 12 Dec 2020 14:14:07 +0100 Subject: [PATCH] pbio/iodev: add power requirement capability flag --- lib/lego/lego_uart.h | 3 +++ lib/pbio/include/pbio/iodev.h | 14 +++++++++++++- lib/pbio/src/uartdev.c | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/lego/lego_uart.h b/lib/lego/lego_uart.h index f3f3c4130..fe37b021c 100644 --- a/lib/lego/lego_uart.h +++ b/lib/lego/lego_uart.h @@ -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; /** diff --git a/lib/pbio/include/pbio/iodev.h b/lib/pbio/include/pbio/iodev.h index d93c9d68c..6a35bb35d 100644 --- a/lib/pbio/include/pbio/iodev.h +++ b/lib/pbio/include/pbio/iodev.h @@ -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; /** @@ -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. diff --git a/lib/pbio/src/uartdev.c b/lib/pbio/src/uartdev.c index c57c6f7c5..b820a8ea2 100644 --- a/lib/pbio/src/uartdev.c +++ b/lib/pbio/src/uartdev.c @@ -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);