From 988aa992bf5abc42f0d11ba6eec5422078ccb5b7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 21 Feb 2023 20:35:57 +1100 Subject: [PATCH] AP_OpticalFlow: add and use a "bool read(c)" method to AP_HAL this is much less likely to not work vs the int16_t equivalent --- libraries/AP_OpticalFlow/AP_OpticalFlow_CXOF.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_CXOF.cpp b/libraries/AP_OpticalFlow/AP_OpticalFlow_CXOF.cpp index ed2a099f46..af3180b95d 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_CXOF.cpp +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_CXOF.cpp @@ -116,11 +116,10 @@ void AP_OpticalFlow_CXOF::update(void) // read any available characters in the serial buffer int16_t nbytes = uart->available(); while (nbytes-- > 0) { - int16_t r = uart->read(); - if (r < 0) { + uint8_t c; + if (!uart->read(c)) { continue; } - uint8_t c = (uint8_t)r; // if buffer is empty and this byte is header, add to buffer if (buf_len == 0) { if (c == CXOF_HEADER) {