-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
104 lines (86 loc) · 3.33 KB
/
Copy pathexample.c
File metadata and controls
104 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
******************************************************************************
* file : example.c
* brief : example program body
******************************************************************************
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "example.h"
#include "hts221.h"
#include "stdio.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private variables */
hts221_object_t *pHts2210; /* HTS221 object instance */
float gTempData; /* This variable store the temperature measurement (unit: deg C) */
float gHumData; /* This variable store the humidity measurement (unit: %) */
/** ########## Step 1 ##########
* The init of HTS221 is triggered by the applicative code
*/
app_status_t app_init(void)
{
app_status_t return_status = EXEC_STATUS_ERROR;
/* Retrieve and store the HTS221 object pointer */
pHts2210 = MX_HTS221_getobject();
/* Initialize the HTS221 device 0 */
if (hts221_drv_init(pHts2210, MX_HTS221) != 0)
{
PRINTF("[ERROR] Step 1: HTS221 sensor init error\n");
goto _app_init_exit;
}
PRINTF("[INFO] Step 1: HTS221 sensor init completed\n");
/* HTS221 device 0: enable the temperature and humidity features */
if (hts221_drv_enable(pHts2210) != 0)
{
PRINTF("[ERROR] Step 1: Enabling TEMP and HUM features error\n");
goto _app_init_exit;
}
PRINTF("[INFO] Step 1: Enabling TEMP and HUM features completed\n");
return_status = EXEC_STATUS_INIT_OK;
_app_init_exit:
return return_status;
}
/** ########## Step 2 ##########
* Gets the values of the temperature in Celsius and of the humidity in %.
* The values are displayed on the terminal.
* output: EXEC_STATUS_OK if OK, EXEC_STATUS_ERROR in case of error
*/
app_status_t app_process(void)
{
app_status_t return_status = EXEC_STATUS_ERROR;
/* HTS221 device 0: get the temperature value and print it */
if (hts221_drv_get_temperature(pHts2210, &gTempData) != 0)
{
PRINTF("[ERROR] Step 2: Reading temperature error\n");
goto _app_process_exit;
}
PRINTF("[INFO] Step 2: TEMP %" PRIi32 " degC\n", (int32_t)gTempData);
/* HTS221 device 0: get the humidity value and print it */
if (hts221_drv_get_humidity(pHts2210, &gHumData) != 0)
{
PRINTF("[ERROR] Step 2: Reading humidity error\n");
goto _app_process_exit;
}
PRINTF("[INFO] Step 2: HUM %" PRIu32 " %%\n", (uint32_t)gHumData);
return_status = EXEC_STATUS_OK;
_app_process_exit:
return return_status;
}
/** Deinitializes the HTS221 instance.
* In this example, app_deinit is never called and is provided as a reference only.
*/
app_status_t app_deinit(void)
{
hts221_drv_deinit(pHts2210);
return EXEC_STATUS_OK;
}