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 
9 #pragma once
10 
23 #include <stdbool.h>
24 
25 #include "periph/gpio.h"
26 #include "periph/uart.h"
27 #include "mutex.h"
28 #include "sds011_internal.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #define SDS011_DEVID_WILDCARD (0xFFFF)
38 
42 enum {
47 };
48 
52 typedef enum sds011_reporting_mode {
56 
60 typedef enum sds011_working_mode {
64 
68 typedef struct {
70  gpio_t pwr_pin;
71  uint16_t dev_id;
72  bool pwr_ah;
74 
78 typedef struct {
79  uint16_t pm_2_5;
80  uint16_t pm_10;
82 
86 typedef void (*sds011_callback_t)(sds011_data_t *data, void *ctx);
87 
91 typedef struct {
96  void *cbctx;
97  uint16_t checksum;
98  uint8_t rx_mem[SDS011_FRAME_RECV_LEN];
99  uint8_t pos;
100 } sds011_t;
101 
114 int sds011_init(sds011_t *dev, const sds011_params_t *params);
115 
123 void sds011_power_on(const sds011_t *dev);
124 
132 void sds011_power_off(const sds011_t *dev);
133 
149 
168 
184 
203 
219 
235 
249 int sds011_get_working_period(sds011_t *dev, uint8_t *minutes);
250 
270 int sds011_set_working_period(sds011_t *dev, uint8_t minutes);
271 
290 int sds011_get_fw_version(sds011_t *dev, uint8_t *year, uint8_t *mon, uint8_t *day);
291 
309 int sds011_set_dev_id(sds011_t *dev, uint16_t sens_dev_id);
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t uart_t
Define default UART type identifier.
Definition: uart.h:84
sds011_working_mode
Work/sleep mode of the SDS011 sensor.
Definition: sds011.h:60
enum sds011_reporting_mode sds011_reporting_mode_t
Report mode of the SDS011 sensor.
void sds011_power_on(const sds011_t *dev)
Enable power supply of SDS011 laser dust sensor.
int sds011_get_fw_version(sds011_t *dev, uint8_t *year, uint8_t *mon, uint8_t *day)
Get firmware version of the sensor.
sds011_reporting_mode
Report mode of the SDS011 sensor.
Definition: sds011.h:52
int sds011_get_working_period(sds011_t *dev, uint8_t *minutes)
Get current working period of the sensor.
int sds011_get_reporting_mode(sds011_t *dev, sds011_reporting_mode_t *mode)
Get the current reporting mode of the sensor.
int sds011_init(sds011_t *dev, const sds011_params_t *params)
Initialize SDS011 Laser Dust Sensor.
int sds011_read(sds011_t *dev, sds011_data_t *data)
Read measurement values from SDS011 laser dust sensor.
int sds011_set_working_period(sds011_t *dev, uint8_t minutes)
Set working period of the sensor.
int sds011_set_working_mode(sds011_t *dev, sds011_working_mode_t mode)
Set working mode of the sensor.
int sds011_set_reporting_mode(sds011_t *dev, sds011_reporting_mode_t mode)
Set the reporting mode of the sensor.
void(* sds011_callback_t)(sds011_data_t *data, void *ctx)
callback for measurements actively reported by the SDS011 sensor
Definition: sds011.h:86
int sds011_set_dev_id(sds011_t *dev, uint16_t sens_dev_id)
Set device ID of the sensor.
enum sds011_working_mode sds011_working_mode_t
Work/sleep mode of the SDS011 sensor.
void sds011_power_off(const sds011_t *dev)
Disable power supply of SDS011 laser dust sensor.
int sds011_register_callback(sds011_t *dev, sds011_callback_t cb, void *ctx)
Register measurement callback.
int sds011_get_working_mode(sds011_t *dev, sds011_working_mode_t *mode)
Get current working mode of the sensor.
@ SDS011_WMODE_SLEEP
laser & fan are disabled
Definition: sds011.h:61
@ SDS011_WMODE_WORK
laser & fan are enabled
Definition: sds011.h:62
@ SDS011_RMODE_ACTIVE
continuously reporting values
Definition: sds011.h:53
@ SDS011_RMODE_QUERY
sensor needs to be queried
Definition: sds011.h:54
@ SDS011_INVALID_RESPONSE
invalid response
Definition: sds011.h:44
@ SDS011_OK
all good
Definition: sds011.h:43
@ SDS011_INVALID_CHKSUM
invalid checksum
Definition: sds011.h:45
@ SDS011_ERROR
internal error
Definition: sds011.h:46
Mutex for thread synchronization.
Internal constants etc.
Mutex structure.
Definition: mutex.h:39
Data type for storing SDS011 sensor readings.
Definition: sds011.h:78
uint16_t pm_2_5
Particulate Matter 2.5 concentration [0.1µg/m^3].
Definition: sds011.h:79
uint16_t pm_10
Particulate Matter 10 concentration [0.1µg/m^3].
Definition: sds011.h:80
Configuration parameters for SDS011 Laser Dust Sensor.
Definition: sds011.h:68
uart_t uart
UART device the sensor is connected to.
Definition: sds011.h:69
gpio_t pwr_pin
GPIO pin for disabling supply voltage for the sensor.
Definition: sds011.h:70
uint16_t dev_id
Unique sensor device ID.
Definition: sds011.h:71
bool pwr_ah
Logic level of the power pin (true for active high)
Definition: sds011.h:72
Device descriptor definition for SDS011 Laser Dust Sensor.
Definition: sds011.h:91
mutex_t cb_lock
mutex to synchronize callbacks
Definition: sds011.h:94
mutex_t dev_lock
mutex to synchronize device access
Definition: sds011.h:93
sds011_params_t params
parameters for SDS011 device
Definition: sds011.h:92
uint16_t checksum
iteratively calculated checksum
Definition: sds011.h:97
void * cbctx
user context for the callback
Definition: sds011.h:96
uint8_t pos
receive buffer position counter
Definition: sds011.h:99
sds011_callback_t cb
callback deliver values async
Definition: sds011.h:95
Low-level UART peripheral driver interface definition.