drivers: sensors: explorir_m: fix uart flush early termination

`explorir_m_uart_flush_until_end` terminates immediately if the read
variable is initially equal to `EXPLORIR_M_MAX_RESPONSE_DELAY` and
`uart_poll_in` does not read anything.

Fix this by only checking the read variable if `uart_poll_in` reads a char.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This commit is contained in:
Jeppe Odgaard 2024-09-03 14:36:19 +02:00 committed by Carles Cufí
parent ef30aa8626
commit 20fb6b6d24
1 changed files with 5 additions and 4 deletions

View File

@ -83,10 +83,11 @@ static void explorir_m_uart_flush_until_end(const struct device *uart_dev)
uint32_t uptime;
uptime = k_uptime_get_32();
do {
uart_poll_in(uart_dev, &tmp);
} while (tmp != EXPLORIR_M_END_CHAR &&
k_uptime_get_32() - uptime < EXPLORIR_M_MAX_RESPONSE_DELAY);
while (k_uptime_get_32() - uptime < EXPLORIR_M_MAX_RESPONSE_DELAY) {
if (uart_poll_in(uart_dev, &tmp) == 0 && tmp == EXPLORIR_M_END_CHAR) {
break;
}
}
}
static void explorir_m_buffer_reset(struct explorir_m_data *data)