30
30
*/
31
31
32
32
#include "sensirion_gas_index_algorithm.h"
33
- #include <stdio.h> // printf
34
33
#include <math.h>
34
+ #include <stdio.h> // printf
35
35
36
36
#include "sensirion_common.h"
37
37
#include "sensirion_i2c_hal.h"
41
41
uint16_t DEFAULT_COMPENSATION_RH = 0x8000 ; // in ticks as defined by SGP40
42
42
uint16_t DEFAULT_COMPENSATION_T = 0x6666 ; // in ticks as defined by SGP40
43
43
44
-
45
44
void read_compensation_values (uint16_t * compensation_rh ,
46
45
uint16_t * compensation_t );
47
46
@@ -52,30 +51,33 @@ int main(void) {
52
51
uint16_t sraw_voc = 0 ;
53
52
int32_t voc_index_value = 0 ;
54
53
// Sampling interval in seconds
55
- // This code uses a fixed heating pulse of ca. 200 ms for the measurement and thus,
56
- // the sampling interval defines the duty cycle
54
+ // This code uses a fixed heating pulse of ca. 200 ms for the measurement
55
+ // and thus, the sampling interval defines the duty cycle
57
56
float sampling_interval = 1.f ;
58
57
59
58
// initialize gas index parameters
60
59
GasIndexAlgorithmParams voc_params ;
61
- GasIndexAlgorithm_init_with_sampling_interval (& voc_params , GasIndexAlgorithm_ALGORITHM_TYPE_VOC , sampling_interval );
60
+ GasIndexAlgorithm_init_with_sampling_interval (
61
+ & voc_params , GasIndexAlgorithm_ALGORITHM_TYPE_VOC , sampling_interval );
62
62
63
63
// initialize i2c communication used for SHT4x and SGP40
64
64
sensirion_i2c_hal_init ();
65
65
66
66
for (int i = 0 ; i < 100 ; i += 1 ) {
67
67
68
68
// 1. Sleep: Total loop time should match the chosen sampling interval
69
- // Therefore we take into account the heater delay and the measurement delays.
70
- sensirion_i2c_hal_sleep_usec (((uint32_t )(sampling_interval * 1000 )- 240 )* 1000 );
69
+ // Therefore we take into account the heater delay and the measurement
70
+ // delays.
71
+ sensirion_i2c_hal_sleep_usec (
72
+ ((uint32_t )(sampling_interval * 1000 ) - 240 ) * 1000 );
71
73
72
74
// 2. Measure SHT4x RH and T signals and convert to SGP40 ticks
73
75
read_compensation_values (& compensation_rh , & compensation_t );
74
76
75
77
// 3. Measure SGP40 signal with low power mode
76
78
// 3.1 Request a first measurement to turn the heater on
77
79
error = sgp40_measure_raw_signal (compensation_rh , compensation_t ,
78
- & sraw_voc );
80
+ & sraw_voc );
79
81
if (error ) {
80
82
printf ("Error executing sgp40_measure_raw_signals(): %i\n" , error );
81
83
continue ;
@@ -86,7 +88,7 @@ int main(void) {
86
88
87
89
// 3.3 Request the actual measurement
88
90
error = sgp40_measure_raw_signal (compensation_rh , compensation_t ,
89
- & sraw_voc );
91
+ & sraw_voc );
90
92
91
93
if (error ) {
92
94
printf ("Error executing sgp40_measure_raw_signals(): %i\n" , error );
@@ -105,7 +107,6 @@ int main(void) {
105
107
// index values
106
108
GasIndexAlgorithm_process (& voc_params , sraw_voc , & voc_index_value );
107
109
printf ("VOC Raw: %i\tVOC Index: %i\n" , sraw_voc , voc_index_value );
108
-
109
110
}
110
111
111
112
return 0 ;
@@ -122,8 +123,8 @@ int main(void) {
122
123
void read_compensation_values (uint16_t * compensation_rh ,
123
124
uint16_t * compensation_t ) {
124
125
int16_t error = 0 ;
125
- float s_rh = 0 ; // %RH
126
- float s_temperature = 0 ; // degC
126
+ float s_rh = 0 ; // %RH
127
+ float s_temperature = 0 ; // degC
127
128
error = sht4x_measure_high_precision (& s_temperature , & s_rh );
128
129
if (error ) {
129
130
printf ("Error executing sht4x_measure_high_precision(): %i\n" , error );
@@ -134,7 +135,7 @@ void read_compensation_values(uint16_t* compensation_rh,
134
135
printf ("T: %.2f\tRH: %.2f\n" , s_temperature , s_rh );
135
136
136
137
// convert temperature and humidity to ticks as defined by SGP40
137
- // interface
138
+ // interface
138
139
// NOTE: in case you read RH and T raw signals check out the
139
140
// ticks specification in the datasheet, as they can be different for
140
141
// different sensors
0 commit comments