Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BMI270] Fix bug in data frame size calculation #366

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/sensors/softfusion/drivers/bmi270.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,11 @@ struct BMI270 {
}
getFromFifo<uint8_t>(i, read_buffer); // skip 1 byte
} else if ((header & Fifo::ModeMask) == Fifo::DataFrame) {
const uint8_t required_length
= (((header & Fifo::GyrDataBit) >> Fifo::GyrDataBit)
+ ((header & Fifo::AccelDataBit) >> Fifo::AccelDataBit))
* 6;
uint8_t gyro_data_length
= (header & Fifo::GyrDataBit) == Fifo::GyrDataBit ? 6 : 0;
Copy link
Contributor

@l0ud l0ud Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's enough to (header & Fifo::GyrDataBit ? 6 : 0) afaik (should be even less operations)

similar for accel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

uint8_t accel_data_length
= (header & Fifo::AccelDataBit) == Fifo::AccelDataBit ? 6 : 0;
uint8_t required_length = gyro_data_length + accel_data_length;
if (i + required_length > bytes_to_read) {
// incomplete frame, will be re-read next time
break;
Expand Down Expand Up @@ -444,4 +445,4 @@ struct BMI270 {
}
};

} // namespace SlimeVR::Sensors::SoftFusion::Drivers
} // namespace SlimeVR::Sensors::SoftFusion::Drivers