LibDriver SCD4X
Loading...
Searching...
No Matches
driver_scd4x_shot.c
Go to the documentation of this file.
1
36
37#include "driver_scd4x_shot.h"
38
39static scd4x_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
61
62 /* set chip type */
63 res = scd4x_set_type(&gs_handle, type);
64 if (res != 0)
65 {
66 scd4x_interface_debug_print("scd4x: set type failed.\n");
67
68 return 1;
69 }
70
71 /* scd4x init */
72 res = scd4x_init(&gs_handle);
73 if (res != 0)
74 {
75 scd4x_interface_debug_print("scd4x: init failed.\n");
76
77 return 1;
78 }
79
80 return 0;
81}
82
94uint8_t scd4x_shot_read(uint16_t *co2_ppm, float *temperature, float *humidity)
95{
96 uint8_t res;
97 uint32_t timeout;
98 scd4x_bool_t enable;
99
100 /* measure single shot */
101 res = scd4x_measure_single_shot(&gs_handle);
102 if (res != 0)
103 {
104 return 1;
105 }
106
107 /* set 30s */
108 timeout = 30;
109
110 /* check timeout */
111 while (timeout != 0)
112 {
113 /* delay 1000ms */
115
116 /* timeout-- */
117 timeout--;
118
119 /* read data */
120 res = scd4x_get_data_ready_status(&gs_handle, &enable);
121 if (res != 0)
122 {
123 return 1;
124 }
125 if (enable == SCD4X_BOOL_TRUE)
126 {
127 uint16_t co2_raw;
128 uint16_t temperature_raw;
129 uint16_t humidity_raw;
130
131 /* read data */
132 res = scd4x_read(&gs_handle, &co2_raw, co2_ppm,
133 &temperature_raw, temperature,
134 &humidity_raw, humidity);
135 if (res != 0)
136 {
137 return 1;
138 }
139
140 break;
141 }
142 }
143 if (timeout == 0)
144 {
145 return 2;
146 }
147
148 return 0;
149}
150
158uint8_t scd4x_shot_deinit(void)
159{
160 /* close scd4x */
161 if (scd4x_deinit(&gs_handle) != 0)
162 {
163 return 1;
164 }
165
166 return 0;
167}
168
177uint8_t scd4x_shot_get_serial_number(uint16_t num[3])
178{
179 /* get serial number */
180 if (scd4x_get_serial_number(&gs_handle, num) != 0)
181 {
182 return 1;
183 }
184
185 return 0;
186}
187
196{
197 /* wake up */
198 if (scd4x_wake_up(&gs_handle) != 0)
199 {
200 return 1;
201 }
202
203 return 0;
204}
205
214{
215 /* power down */
216 if (scd4x_power_down(&gs_handle) != 0)
217 {
218 return 1;
219 }
220
221 return 0;
222}
driver scd4x shot header file
uint8_t scd4x_wake_up(scd4x_handle_t *handle)
wake up
uint8_t scd4x_power_down(scd4x_handle_t *handle)
power down
uint8_t scd4x_measure_single_shot(scd4x_handle_t *handle)
measure single shot
uint8_t scd4x_get_data_ready_status(scd4x_handle_t *handle, scd4x_bool_t *enable)
get data ready status
uint8_t scd4x_get_serial_number(scd4x_handle_t *handle, uint16_t number[3])
get serial number
uint8_t scd4x_deinit(scd4x_handle_t *handle)
close the chip
uint8_t scd4x_read(scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data
uint8_t scd4x_set_type(scd4x_handle_t *handle, scd4x_t type)
set type
uint8_t scd4x_init(scd4x_handle_t *handle)
initialize the chip
struct scd4x_handle_s scd4x_handle_t
scd4x handle structure definition
scd4x_t
scd4x type enumeration definition
scd4x_bool_t
scd4x bool enumeration definition
@ SCD4X_BOOL_TRUE
uint8_t scd4x_shot_get_serial_number(uint16_t num[3])
shot example get serial number
uint8_t scd4x_shot_deinit(void)
shot example deinit
uint8_t scd4x_shot_wake_up(void)
shot wake up
uint8_t scd4x_shot_power_down(void)
shot power down
uint8_t scd4x_shot_init(scd4x_t type)
shot example init
uint8_t scd4x_shot_read(uint16_t *co2_ppm, float *temperature, float *humidity)
shot example read
uint8_t scd4x_interface_iic_init(void)
interface iic bus init
void scd4x_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t scd4x_interface_iic_deinit(void)
interface iic bus deinit
uint8_t scd4x_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void scd4x_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t scd4x_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command