/
forced_mode.c
108 lines (90 loc) · 3.44 KB
/
forced_mode.c
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
105
106
107
108
/**
* Copyright (C) 2023 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <stdio.h>
#include "bme68x.h"
#include "common.h"
#include "coines.h"
/***********************************************************************/
/* Macros */
/***********************************************************************/
/* Macro for count of samples to be displayed */
#define SAMPLE_COUNT UINT16_C(300)
/***********************************************************************/
/* Test code */
/***********************************************************************/
int main(void)
{
struct bme68x_dev bme;
int8_t rslt;
struct bme68x_conf conf;
struct bme68x_heatr_conf heatr_conf;
struct bme68x_data data;
uint32_t del_period;
uint32_t time_ms = 0;
uint8_t n_fields;
uint16_t sample_count = 1;
/* Interface preference is updated as a parameter
* For I2C : BME68X_I2C_INTF
* For SPI : BME68X_SPI_INTF
*/
rslt = bme68x_interface_init(&bme, BME68X_SPI_INTF);
bme68x_check_rslt("bme68x_interface_init", rslt);
rslt = bme68x_init(&bme);
bme68x_check_rslt("bme68x_init", rslt);
/* Check if rslt == BME68X_OK, report or handle if otherwise */
conf.filter = BME68X_FILTER_OFF;
conf.odr = BME68X_ODR_NONE;
conf.os_hum = BME68X_OS_16X;
conf.os_pres = BME68X_OS_1X;
conf.os_temp = BME68X_OS_2X;
rslt = bme68x_set_conf(&conf, &bme);
bme68x_check_rslt("bme68x_set_conf", rslt);
/* Check if rslt == BME68X_OK, report or handle if otherwise */
heatr_conf.enable = BME68X_ENABLE;
heatr_conf.heatr_temp = 300;
heatr_conf.heatr_dur = 100;
rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &bme);
bme68x_check_rslt("bme68x_set_heatr_conf", rslt);
printf("Sample, TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%%), Gas resistance(ohm), Status\n");
while (sample_count <= SAMPLE_COUNT)
{
rslt = bme68x_set_op_mode(BME68X_FORCED_MODE, &bme);
bme68x_check_rslt("bme68x_set_op_mode", rslt);
/* Calculate delay period in microseconds */
del_period = bme68x_get_meas_dur(BME68X_FORCED_MODE, &conf, &bme) + (heatr_conf.heatr_dur * 1000);
bme.delay_us(del_period, bme.intf_ptr);
time_ms = coines_get_millis();
/* Check if rslt == BME68X_OK, report or handle if otherwise */
rslt = bme68x_get_data(BME68X_FORCED_MODE, &data, &n_fields, &bme);
bme68x_check_rslt("bme68x_get_data", rslt);
if (n_fields)
{
#ifdef BME68X_USE_FPU
printf("%u, %lu, %.2f, %.2f, %.2f, %.2f, 0x%x\n",
sample_count,
(long unsigned int)time_ms,
data.temperature,
data.pressure,
data.humidity,
data.gas_resistance,
data.status);
#else
printf("%u, %lu, %d, %lu, %lu, %lu, 0x%x\n",
sample_count,
(long unsigned int)time_ms,
(data.temperature / 100),
(long unsigned int)data.pressure,
(long unsigned int)(data.humidity / 1000),
(long unsigned int)data.gas_resistance,
data.status);
#endif
sample_count++;
}
}
bme68x_coines_deinit();
return rslt;
}