mhz19.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Koen Zandberg <koen@bergzand.net>
3  * Copyright (C) 2018 Beduino Master Projekt - University of Bremen
4  * Copyright (C) 2020 Bas Stottelaar <basstottelaar@gmail.com>
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
38 #ifndef MHZ19_H
39 #define MHZ19_H
40 
41 #include <stdbool.h>
42 
43 #include "saul.h"
44 
45 #ifdef MODULE_MHZ19_UART
46 #include "periph/uart.h"
47 #include "mhz19_internals.h"
48 #include "mutex.h"
49 #endif /* MODULE_MHZ19_UART */
50 
51 #ifdef MODULE_MHZ19_PWM
52 #include "periph/gpio.h"
53 #endif /* MODULE_MHZ19_PWM */
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
62 enum {
63  MHZ19_OK = 0,
67 };
68 
69 #ifdef MODULE_MHZ19_UART
70 
73 typedef struct {
74  uart_t uart;
75  bool auto_calibration;
76 } mhz19_params_t;
77 
81 typedef struct {
82  const mhz19_params_t *params;
83  mutex_t mutex;
84  mutex_t sync;
85  uint8_t idx;
86  uint8_t rxmem[MHZ19_BUF_SIZE];
87 } mhz19_t;
88 #endif /* MODULE_MHZ19_UART */
89 
90 #ifdef MODULE_MHZ19_PWM
91 
94 typedef struct {
95  gpio_t pin;
96 } mhz19_params_t;
97 
101 typedef struct {
102  gpio_t pin;
103 } mhz19_t;
104 #endif /* MODULE_MHZ19_PWM */
105 
110 
120 int mhz19_init(mhz19_t *dev, const mhz19_params_t *params);
121 
133 int mhz19_get_ppm(mhz19_t *dev, int16_t *ppm);
134 
135 #ifdef MODULE_MHZ19_UART
136 
142 void mhz19_set_auto_calibration(mhz19_t *dev, bool enable);
143 
149 void mhz19_calibrate_zero_point(mhz19_t *dev);
150 #endif
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif /* MHZ19_H */
157 
mhz19_internals.h
Internal addresses, registers, constants for the MH-Z19 CO2 sensor.
mhz19_get_ppm
int mhz19_get_ppm(mhz19_t *dev, int16_t *ppm)
Get measured CO2 ppm value.
MHZ19_ERR_INIT
@ MHZ19_ERR_INIT
error initializing the device
Definition: mhz19.h:64
mhz19_ppm_saul_driver
const saul_driver_t mhz19_ppm_saul_driver
Export SAUL endpoint.
uart_t
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:76
uart.h
Low-level UART peripheral driver interface definition.
saul_driver_t
Definition of the RIOT actuator/sensor interface.
Definition: saul.h:279
mutex.h
Mutex for thread synchronization.
MHZ19_ERR_CHECKSUM
@ MHZ19_ERR_CHECKSUM
checksum failure on received data
Definition: mhz19.h:66
gpio.h
Low-level GPIO peripheral driver interface definitions.
MHZ19_ERR_TIMEOUT
@ MHZ19_ERR_TIMEOUT
timeout on retrieving sensor data
Definition: mhz19.h:65
mhz19_init
int mhz19_init(mhz19_t *dev, const mhz19_params_t *params)
Initialize a MH-Z19 device.
saul.h
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
mutex_t
Mutex structure.
Definition: mutex.h:120
MHZ19_OK
@ MHZ19_OK
everything was fine
Definition: mhz19.h:63