LibDriver SCD4X
Loading...
Searching...
No Matches
driver_scd4x_basic.c
Go to the documentation of this file.
1
36
37#include "driver_scd4x_basic.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 /* start */
81 res = scd4x_start_periodic_measurement(&gs_handle);
82 if (res != 0)
83 {
84 scd4x_interface_debug_print("scd4x: start periodic measurement failed.\n");
85 (void)scd4x_deinit(&gs_handle);
86
87 return 1;
88 }
89
90 return 0;
91}
92
103uint8_t scd4x_basic_read(uint16_t *co2_ppm, float *temperature, float *humidity)
104{
105 uint8_t res;
106 uint16_t co2_raw;
107 uint16_t temperature_raw;
108 uint16_t humidity_raw;
109
110 /* read data */
111 res = scd4x_read(&gs_handle, &co2_raw, co2_ppm,
112 &temperature_raw, temperature,
113 &humidity_raw, humidity);
114 if (res != 0)
115 {
116 return 1;
117 }
118
119 return 0;
120}
121
130{
131 /* stop */
132 if (scd4x_stop_periodic_measurement(&gs_handle) != 0)
133 {
134 return 1;
135 }
136
137 /* close scd4x */
138 if (scd4x_deinit(&gs_handle) != 0)
139 {
140 return 1;
141 }
142
143 return 0;
144}
145
154uint8_t scd4x_basic_get_serial_number(uint16_t num[3])
155{
156 /* get serial number */
157 if (scd4x_get_serial_number(&gs_handle, num) != 0)
158 {
159 return 1;
160 }
161
162 return 0;
163}
164
173{
174 /* wake up */
175 if (scd4x_wake_up(&gs_handle) != 0)
176 {
177 return 1;
178 }
179
180 return 0;
181}
182
191{
192 /* power down */
193 if (scd4x_power_down(&gs_handle) != 0)
194 {
195 return 1;
196 }
197
198 return 0;
199}
driver scd4x basic 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_stop_periodic_measurement(scd4x_handle_t *handle)
stop periodic measurement
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
uint8_t scd4x_start_periodic_measurement(scd4x_handle_t *handle)
start periodic measurement
struct scd4x_handle_s scd4x_handle_t
scd4x handle structure definition
scd4x_t
scd4x type enumeration definition
uint8_t scd4x_basic_get_serial_number(uint16_t num[3])
basic example get serial number
uint8_t scd4x_basic_wake_up(void)
basic wake up
uint8_t scd4x_basic_deinit(void)
basic example deinit
uint8_t scd4x_basic_power_down(void)
basic power down
uint8_t scd4x_basic_read(uint16_t *co2_ppm, float *temperature, float *humidity)
basic example read
uint8_t scd4x_basic_init(scd4x_t type)
basic example init
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