LibDriver STCC4
Loading...
Searching...
No Matches
driver_stcc4_shot.c
Go to the documentation of this file.
1
36
37#include "driver_stcc4_shot.h"
38
39static stcc4_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
61
62 /* set address pin */
63 res = stcc4_set_address_pin(&gs_handle, address);
64 if (res != 0)
65 {
66 stcc4_interface_debug_print("stcc4: set address pin failed.\n");
67
68 return 1;
69 }
70
71 /* stcc4 init */
72 res = stcc4_init(&gs_handle);
73 if (res != 0)
74 {
75 stcc4_interface_debug_print("stcc4: init failed.\n");
76
77 return 1;
78 }
79
80 return 0;
81}
82
94uint8_t stcc4_shot_read(int16_t *co2_ppm, float *temperature, float *humidity)
95{
96 uint8_t res;
97 int16_t co2_raw;
98 uint16_t temperature_raw;
99 uint16_t humidity_raw;
100 uint16_t sensor_status;
101
102 /* measure single shot */
103 res = stcc4_measure_single_shot(&gs_handle);
104 if (res != 0)
105 {
106 return 1;
107 }
108
109 /* read data */
110 res = stcc4_read(&gs_handle, &co2_raw, co2_ppm,
111 &temperature_raw, temperature,
112 &humidity_raw, humidity, &sensor_status);
113 if (res != 0)
114 {
115 return 1;
116 }
117
118 return 0;
119}
120
128uint8_t stcc4_shot_deinit(void)
129{
130 /* close stcc4 */
131 if (stcc4_deinit(&gs_handle) != 0)
132 {
133 return 1;
134 }
135
136 return 0;
137}
138
148uint8_t stcc4_shot_get_product_id(uint32_t *product_id, uint8_t unique_serial_number[8])
149{
150 /* get product id */
151 if (stcc4_get_product_id(&gs_handle, product_id, unique_serial_number) != 0)
152 {
153 return 1;
154 }
155
156 return 0;
157}
158
167{
168 /* wake up */
169 if (stcc4_exit_sleep_mode(&gs_handle) != 0)
170 {
171 return 1;
172 }
173
174 return 0;
175}
176
185{
186 /* power down */
187 if (stcc4_enter_sleep_mode(&gs_handle) != 0)
188 {
189 return 1;
190 }
191
192 return 0;
193}
driver stcc4 shot header file
uint8_t stcc4_exit_sleep_mode(stcc4_handle_t *handle)
exit sleep mode
uint8_t stcc4_deinit(stcc4_handle_t *handle)
close the chip
struct stcc4_handle_s stcc4_handle_t
stcc4 handle structure definition
stcc4_address_t
stcc4 address enumeration definition
uint8_t stcc4_enter_sleep_mode(stcc4_handle_t *handle)
enter sleep mode
uint8_t stcc4_measure_single_shot(stcc4_handle_t *handle)
measure single shot
uint8_t stcc4_init(stcc4_handle_t *handle)
initialize the chip
uint8_t stcc4_set_address_pin(stcc4_handle_t *handle, stcc4_address_t address)
set address pin
uint8_t stcc4_read(stcc4_handle_t *handle, int16_t *co2_raw, int16_t *co2_ppm, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s, uint16_t *sensor_status)
read data
uint8_t stcc4_get_product_id(stcc4_handle_t *handle, uint32_t *product_id, uint8_t unique_serial_number[8])
get product id
uint8_t stcc4_shot_wake_up(void)
shot wake up
uint8_t stcc4_shot_power_down(void)
shot power down
uint8_t stcc4_shot_deinit(void)
shot example deinit
uint8_t stcc4_shot_read(int16_t *co2_ppm, float *temperature, float *humidity)
shot example read
uint8_t stcc4_shot_init(stcc4_address_t address)
shot example init
uint8_t stcc4_shot_get_product_id(uint32_t *product_id, uint8_t unique_serial_number[8])
shot example get product id
uint8_t stcc4_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
void stcc4_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t stcc4_interface_iic_init(void)
interface iic bus init
uint8_t stcc4_interface_iic_deinit(void)
interface iic bus deinit
uint8_t stcc4_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void stcc4_interface_debug_print(const char *const fmt,...)
interface print format data