Skip to content

DEV-1102: sign-extend the BMP581 temperature - #310

Merged
MAzalya merged 1 commit into
masterfrom
DEV-1102_bmp581_signed_temperature
Oct 2, 2026
Merged

MAzalya merged 1 commit into
masterfrom
DEV-1102_bmp581_signed_temperature

Conversation

@marknolan

@marknolan marknolan commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Fixes DEV-1102: BMP581 temperatures below 0 °C decode as about 255 °C.

Symptom

In a fridge test on two Shimmer3Rs (CE2F and D8A6, both fitted with a BMP581), the Consensys SD exports show 254.33–256.00 °C for every sample below freezing. That's 8.1% of CE2F's samples and 1.8% of D8A6's. Read as signed, the traces are continuous and bottom out at −1.67 °C and −0.37 °C.

Cause

The BMP581's compensated temperature is a signed 24-bit value in units of 1/65536 °C; pressure is unsigned, in units of 1/64 Pa (Bosch bmp5.c). Both driver paths receive the temperature as UINT24 and used it unsigned:

  • ShimmerObject, the path Consensys uses: it reads signal 0x1A on Shimmer3R as "u24", then CalibDetailsBmp581.calibratePressureSensorData computes UT / 65536.0.
  • SensorBMP581: channelBmp581Temp is UINT24, and processData computes raw / 65536.0.

Fix

  • New CalibDetailsBmp581.signExtend24() reads the field as two's complement. It's idempotent, so an already-signed value passes through unchanged.
  • Both paths use it.
  • Pressure stays unsigned, and UNCAL keeps the raw register value, as for BMP390.

Testing

  • New API_00013_Bmp581TemperatureSignTest (5 tests) covers:
    • positive values;
    • sub-zero values, including CE2F's coldest fridge reading, 0xFE5556 → −1.667 °C (previously 254.33 °C);
    • the range limits, 0x800000 → −128 °C and 0x7FFFFF → about 128 °C;
    • a sweep across the upper half of the unsigned range;
    • idempotence;
    • pressure staying unsigned.
  • With the old formula restored, 2 of the 5 fail.
  • cd ShimmerDriver && ./gradlew test: 108 tests, 0 failures.
  • ShimmerDriverPC: ./gradlew build passes. It was run through a junction named Shimmer-Java-Android-API, because the module's settings.gradle resolves siblings by that folder name.
  • The test is deliberately not added to API_00005_Suite_ShimmerDriver. ./gradlew test runs it regardless, and DEV-1095: anchor each SD file on its first packet's own counter time #309 edits the same suite lines.

Effect on output

Re-exporting affected recordings from their SD files gives correct negative temperatures. Exports made before the fix keep the wrong values.

Related

🤖 Generated with Claude Code

The BMP581's compensated temperature is a signed 24-bit value over 65536,
but both driver paths receive it as UINT24 and used it unsigned, so a
reading below 0 degC came out as ~255 degC. Danny's fridge test exported
254.33-256.00 degC for every sub-zero sample.

CalibDetailsBmp581.signExtend24 now reads the field as two's complement,
in calibratePressureSensorData (the ShimmerObject / Consensys path) and in
SensorBMP581's own decode. Pressure stays unsigned; UNCAL keeps the raw
register value, as for BMP390.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@MAzalya MAzalya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok tested looks good

@MAzalya
MAzalya merged commit 58bf57c into master Oct 2, 2026
2 checks passed
@marknolan
marknolan deleted the DEV-1102_bmp581_signed_temperature branch October 2, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants