Skip to content

Commit cc647ee

Browse files
authored
Merge pull request #17 from Sensirion/fix-comparison-tick-calc
fix comparision tick calculation in example
2 parents 31c1108 + 995ab32 commit cc647ee

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77

88
## [Unreleased]
9+
Fix casting issue for tick calculation for RH/T compensation in Raspberry-Pi example
910

1011
## [3.2.2] - 2022-12-05
1112

examples/raspberry-pi/algorithm_example_usage.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "sensirion_gas_index_algorithm.h"
3333
#include <stdio.h> // printf
34+
#include <math.h>
3435

3536
#include "sensirion_common.h"
3637
#include "sensirion_i2c_hal.h"
@@ -66,8 +67,8 @@ void read_compensation_values(uint16_t* compensation_rh,
6667
// interface NOTE: in case you read RH and T raw signals check out the
6768
// ticks specification in the datasheet, as they can be different for
6869
// different sensors
69-
*compensation_rh = (uint16_t)s_rh * 65535 / 100;
70-
*compensation_t = (uint16_t)(s_temperature + 45) * 65535 / 175;
70+
*compensation_rh = (uint16_t)lround(s_rh * 65535 / 100);
71+
*compensation_t = (uint16_t)lround((s_temperature + 45) * 65535 / 175);
7172
}
7273
}
7374

examples/raspberry-pi/low_power_example.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "sensirion_gas_index_algorithm.h"
3333
#include <stdio.h> // printf
34+
#include <math.h>
3435

3536
#include "sensirion_common.h"
3637
#include "sensirion_i2c_hal.h"
@@ -137,7 +138,7 @@ void read_compensation_values(uint16_t* compensation_rh,
137138
// NOTE: in case you read RH and T raw signals check out the
138139
// ticks specification in the datasheet, as they can be different for
139140
// different sensors
140-
*compensation_rh = (uint16_t)s_rh * 65535 / 100;
141-
*compensation_t = (uint16_t)(s_temperature + 45) * 65535 / 175;
141+
*compensation_rh = (uint16_t)lround(s_rh * 65535 / 100);
142+
*compensation_t = (uint16_t)lround((s_temperature + 45) * 65535 / 175);
142143
}
143144
}

0 commit comments

Comments
 (0)