Skip to content

Commit

Permalink
s35770 driver fix, nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Aug 3, 2024
1 parent 925d7e3 commit 9d3f265
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/drivers/rpm/s35770/s35770.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/rpm/s35770/s35770.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ class S35770 : public device::I2C, public ModuleParams, public I2CSPIDriver<S357

private:

int probe() override;
int probe() override;

uint32_t getCounter();
uint8_t getCounter(uint32_t* count);

uint8_t hiWord(uint8_t in) { return (in & 0x0fu); }
uint8_t loWord(uint8_t in) { return ((in & 0xf0u) >> 4); }


uint32_t _count{0};
uint16_t _overflow_count{0};
hrt_abstime _last_measurement_time{0};
Expand Down

0 comments on commit 9d3f265

Please sign in to comment.