From d3a0ca15163257c2f9e776241d650d36e56171c5 Mon Sep 17 00:00:00 2001 From: Roman Dvorak Date: Sat, 3 Aug 2024 20:49:39 +0200 Subject: [PATCH] s35770 driver fix, nullptr --- src/drivers/rpm/s35770/s35770.cpp | 22 +++++++++++++++------- src/drivers/rpm/s35770/s35770.hpp | 5 +++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/drivers/rpm/s35770/s35770.cpp b/src/drivers/rpm/s35770/s35770.cpp index 8ec6f2edcd17..834e2e8d07c7 100644 --- a/src/drivers/rpm/s35770/s35770.cpp +++ b/src/drivers/rpm/s35770/s35770.cpp @@ -66,26 +66,34 @@ int S35770::init() int S35770::probe() { - - return PX4_OK; + uint32_t raw; + return getCounter(&raw); } -uint32_t S35770::getCounter() +uint8_t S35770::getCounter(uint32_t* count) { - uint8_t raw[3]; - transfer(nullptr, 0, &raw[0], 3); - return uint32_t(hiWord(raw[0]) << 16 | loWord(raw[1]) << 8 | raw[2]); + uint8_t err = transfer(nullptr, 0, &raw[0], 3); + *count = uint32_t(hiWord(raw[0]) << 16 | loWord(raw[1]) << 8 | raw[2]); + + return err; } + void S35770::RunImpl() { // read sensor and compute frequency uint32_t oldcount = _count; int32_t diffTime = hrt_elapsed_time(&_last_measurement_time); - _count = getCounter(); + uint8_t err = getCounter(&_count); + + if (err != PX4_OK) { + PX4_ERR("Error reading counter"); + return; + } + _last_measurement_time = hrt_absolute_time(); uint32_t diffCount = 0; diff --git a/src/drivers/rpm/s35770/s35770.hpp b/src/drivers/rpm/s35770/s35770.hpp index d6bf09ba99bd..d5d5f5e7d880 100644 --- a/src/drivers/rpm/s35770/s35770.hpp +++ b/src/drivers/rpm/s35770/s35770.hpp @@ -68,13 +68,14 @@ class S35770 : public device::I2C, public ModuleParams, public I2CSPIDriver> 4); } + uint32_t _count{0}; uint16_t _overflow_count{0}; hrt_abstime _last_measurement_time{0};