Fixed negative temperature bug.
This commit is contained in:
@@ -57,3 +57,8 @@ First (more or less) working version.
|
||||
|
||||
### Fixed
|
||||
- One of the digital outputs was inverted.
|
||||
|
||||
## [1.1.2] - [2024-01-08]
|
||||
|
||||
### Fixed
|
||||
- Negative temperature where converted wrong: -1 became -32767. This was because of a weird format the sensor uses.
|
||||
|
Binary file not shown.
Binary file not shown.
56650
build/src/main.dis
56650
build/src/main.dis
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
9403
build/src/main.hex
9403
build/src/main.hex
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -758,6 +758,12 @@ int main() {
|
||||
if (!NO_I2C_AVAILABLE)
|
||||
ReadAM2315(&humidity, &temperature);
|
||||
|
||||
// Bit 15 of AM2315 temperature is sign (1 = negative). Bit 14-0 is absolute value of teperature
|
||||
if (temperature&0x8000) {
|
||||
temperature = temperature & 0x7FFF; // remove sign bit
|
||||
temperature = -temperature; // make proper signed integer of negative number
|
||||
}
|
||||
|
||||
// Format telemetry string
|
||||
sprintf(tmp_string, "%.1f,%.1f", (float)temperature/10, (float)humidity/10);
|
||||
// Copy string (including NULL terminator) to final destination (can not be done without temporary string due to char/uint8_t issues)
|
||||
|
Reference in New Issue
Block a user