@@ -14,7 +14,7 @@ static int hdc2021_read_reg(hdc2021debr_t *hdc2021, uint8_t reg, uint8_t *data,
1414 return hdc2021 -> read_reg (data , reg , hdc2021 -> dev_address , length );
1515}
1616
17- int hdc2021_init (hdc2021debr_t * hdc2021 , Write_ptr write_reg , Read_ptr read_reg ,
17+ int hdc2021_init (hdc2021debr_t * hdc2021 , Write_ptr_hdc write_reg , Read_ptr_hdc read_reg ,
1818 uint8_t dev_address )
1919{
2020 hdc2021 -> write_reg = write_reg ;
@@ -32,40 +32,40 @@ int hdc2021_toggle_heater(hdc2021debr_t *hdc2021, bool enable)
3232 sizeof (device_config )))
3333 {
3434 return 1 ;
35- };
35+ }
3636
3737 // the 3rd bit toggles the heater
38- if (enable ) {
38+ if (enable )
39+ {
3940 device_config |= (1 << 3 );
40- } else {
41+ } else
42+ {
4143 device_config &= ~(1 << 3 );
42- };
44+ }
4345
4446 if (hdc2021_write_reg (hdc2021 , REG_DEVICE_CONFIG , device_config ))
4547 {
4648 return 1 ;
47- };
49+ }
4850
49- return 0 ;
51+ hdc2021 -> is_heater_enabled = enable ;
5052
53+ return 0 ;
5154}
52- /**
53- * @brief triggers oneshot measurement
54- *
55- * @param hdc2021 - hdc2021debr driver
56- * @return int - Status code
57- */
55+
5856int hdc2021_trigger_oneshot (hdc2021debr_t * hdc2021 )
5957{
6058 uint8_t config ;
6159
62- if (hdc2021_read_reg (hdc2021 , REG_MEASURE_CONFIG , & config , 1 )) {
60+ if (hdc2021_read_reg (hdc2021 , REG_MEASURE_CONFIG , & config , 1 ))
61+ {
6362 return 1 ;
6463 }
6564
6665 config |= 0x01 ;
6766
68- if (hdc2021_write_reg (hdc2021 , REG_MEASURE_CONFIG , config )) {
67+ if (hdc2021_write_reg (hdc2021 , REG_MEASURE_CONFIG , config ))
68+ {
6969 return 1 ;
7070 }
7171
@@ -76,18 +76,13 @@ int hdc2021_get_temp_humid(hdc2021debr_t *hdc2021)
7676{
7777 uint8_t buffer [4 ];
7878
79- if (hdc2021_trigger_oneshot (hdc2021 )) {
80- return 1 ;
81- }
82-
83-
8479 if (hdc2021_read_reg (hdc2021 , REG_TEMP_LOW , buffer , 4 ))
8580 {
8681 return 1 ;
87- };
82+ }
8883
89- uint16_t temp_bytes = (buffer [1 ] << 8 ) | buffer [0 ];
90- uint16_t humid_bytes = (buffer [3 ] << 8 ) | buffer [2 ];
84+ uint16_t temp_bytes = (( uint16_t )( buffer [1 ]) << 8 ) | buffer [0 ];
85+ uint16_t humid_bytes = (( uint16_t )( buffer [3 ]) << 8 ) | buffer [2 ];
9186
9287 float tempVal = (((float )temp_bytes /65536.0f ) * 165.0f ) - 40.0f ;
9388 hdc2021 -> temp = tempVal ;
0 commit comments