sds011.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 HAW-Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef SDS011_H
22 #define SDS011_H
23 
24 #include <stdbool.h>
25 
26 #include "periph/gpio.h"
27 #include "periph/uart.h"
28 #include "mutex.h"
29 #include "sds011_internal.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 #define SDS011_DEVID_WILDCARD (0xFFFF)
39 
43 enum {
48 };
49 
53 typedef enum sds011_reporting_mode {
57 
61 typedef enum sds011_working_mode {
65 
69 typedef struct {
71  gpio_t pwr_pin;
72  uint16_t dev_id;
73  bool pwr_ah;
75 
79 typedef struct {
80  uint16_t pm_2_5;
81  uint16_t pm_10;
83 
87 typedef void (*sds011_callback_t)(sds011_data_t *data, void *ctx);
88 
92 typedef struct {
97  void *cbctx;
98  uint16_t checksum;
99  uint8_t rx_mem[SDS011_FRAME_RECV_LEN];
100  uint8_t pos;
101 } sds011_t;
102 
115 int sds011_init(sds011_t *dev, const sds011_params_t *params);
116 
124 void sds011_power_on(const sds011_t *dev);
125 
133 void sds011_power_off(const sds011_t *dev);
134 
149 int sds011_read(sds011_t *dev, sds011_data_t *data);
150 
168 int sds011_register_callback(sds011_t *dev, sds011_callback_t cb, void *ctx);
169 
185 
204 
220 
236 
250 int sds011_get_working_period(sds011_t *dev, uint8_t *minutes);
251 
271 int sds011_set_working_period(sds011_t *dev, uint8_t minutes);
272 
291 int sds011_get_fw_version(sds011_t *dev, uint8_t *year, uint8_t *mon, uint8_t *day);
292 
310 int sds011_set_dev_id(sds011_t *dev, uint16_t sens_dev_id);
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 
316 #endif /* SDS011_H */
317 
sds011_t::cbctx
void * cbctx
user context for the callback
Definition: sds011.h:97
SDS011_RMODE_ACTIVE
@ SDS011_RMODE_ACTIVE
continuously reporting values
Definition: sds011.h:54
sds011_t::dev_lock
mutex_t dev_lock
mutex to synchronize device access
Definition: sds011.h:94
sds011_t
Device descriptor definition for SDS011 Laser Dust Sensor.
Definition: sds011.h:92
SDS011_ERROR
@ SDS011_ERROR
internal error
Definition: sds011.h:47
sds011_set_reporting_mode
int sds011_set_reporting_mode(sds011_t *dev, sds011_reporting_mode_t mode)
Set the reporting mode of the sensor.
SDS011_WMODE_WORK
@ SDS011_WMODE_WORK
laser & fan are enabled
Definition: sds011.h:63
sds011_t::params
sds011_params_t params
parameters for SDS011 device
Definition: sds011.h:93
sds011_read
int sds011_read(sds011_t *dev, sds011_data_t *data)
Read measurement values from SDS011 laser dust sensor.
sds011_set_working_period
int sds011_set_working_period(sds011_t *dev, uint8_t minutes)
Set working period of the sensor.
SDS011_INVALID_RESPONSE
@ SDS011_INVALID_RESPONSE
invalid response
Definition: sds011.h:45
sds011_data_t
Data type for storing SDS011 sensor readings.
Definition: sds011.h:79
SDS011_WMODE_SLEEP
@ SDS011_WMODE_SLEEP
laser & fan are disabled
Definition: sds011.h:62
sds011_t::checksum
uint16_t checksum
iteratively calculated checksum
Definition: sds011.h:98
sds011_reporting_mode
sds011_reporting_mode
Report mode of the SDS011 sensor.
Definition: sds011.h:53
SDS011_RMODE_QUERY
@ SDS011_RMODE_QUERY
sensor needs to be queried
Definition: sds011.h:55
SDS011_INVALID_CHKSUM
@ SDS011_INVALID_CHKSUM
invalid checksum
Definition: sds011.h:46
sds011_params_t
Configuration parameters for SDS011 Laser Dust Sensor.
Definition: sds011.h:69
uart_t
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:76
sds011_t::pos
uint8_t pos
receive buffer position counter
Definition: sds011.h:100
sds011_get_fw_version
int sds011_get_fw_version(sds011_t *dev, uint8_t *year, uint8_t *mon, uint8_t *day)
Get firmware version of the sensor.
uart.h
Low-level UART peripheral driver interface definition.
sds011_register_callback
int sds011_register_callback(sds011_t *dev, sds011_callback_t cb, void *ctx)
Register measurement callback.
sds011_reporting_mode_t
enum sds011_reporting_mode sds011_reporting_mode_t
Report mode of the SDS011 sensor.
sds011_internal.h
Internal constants etc. for the SDS011 laser dust sensor.
sds011_power_on
void sds011_power_on(const sds011_t *dev)
Enable power supply of SDS011 laser dust sensor.
sds011_init
int sds011_init(sds011_t *dev, const sds011_params_t *params)
Initialize SDS011 Laser Dust Sensor.
sds011_callback_t
void(* sds011_callback_t)(sds011_data_t *data, void *ctx)
callback for measurements actively reported by the SDS011 sensor
Definition: sds011.h:87
sds011_data_t::pm_2_5
uint16_t pm_2_5
Particulate Matter 2.5 concentration [0.1µg/m^3].
Definition: sds011.h:80
sds011_params_t::dev_id
uint16_t dev_id
Unique sensor device ID.
Definition: sds011.h:72
sds011_working_mode
sds011_working_mode
Work/sleep mode of the SDS011 sensor.
Definition: sds011.h:61
sds011_params_t::pwr_pin
gpio_t pwr_pin
GPIO pin for disabling supply voltage for the sensor.
Definition: sds011.h:71
sds011_working_mode_t
enum sds011_working_mode sds011_working_mode_t
Work/sleep mode of the SDS011 sensor.
sds011_params_t::uart
uart_t uart
UART device the sensor is connected to.
Definition: sds011.h:70
SDS011_OK
@ SDS011_OK
all good
Definition: sds011.h:44
sds011_get_working_period
int sds011_get_working_period(sds011_t *dev, uint8_t *minutes)
Get current working period of the sensor.
sds011_params_t::pwr_ah
bool pwr_ah
Logic level of the power pin (true for active high)
Definition: sds011.h:73
sds011_get_working_mode
int sds011_get_working_mode(sds011_t *dev, sds011_working_mode_t *mode)
Get current working mode of the sensor.
mutex.h
Mutex for thread synchronization.
sds011_power_off
void sds011_power_off(const sds011_t *dev)
Disable power supply of SDS011 laser dust sensor.
sds011_t::cb_lock
mutex_t cb_lock
mutex to synchronize callbacks
Definition: sds011.h:95
gpio.h
Low-level GPIO peripheral driver interface definitions.
sds011_get_reporting_mode
int sds011_get_reporting_mode(sds011_t *dev, sds011_reporting_mode_t *mode)
Get the current reporting mode of the sensor.
sds011_data_t::pm_10
uint16_t pm_10
Particulate Matter 10 concentration [0.1µg/m^3].
Definition: sds011.h:81
sds011_set_dev_id
int sds011_set_dev_id(sds011_t *dev, uint16_t sens_dev_id)
Set device ID of the sensor.
sds011_t::cb
sds011_callback_t cb
callback deliver values async
Definition: sds011.h:96
sds011_set_working_mode
int sds011_set_working_mode(sds011_t *dev, sds011_working_mode_t mode)
Set working mode of the sensor.
mutex_t
Mutex structure.
Definition: mutex.h:120