|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "sps30.h"#include "i2c.h"#include "utils/mydefs.h"#include "utils/utils.h"#include "mymems.h"#include <stdio.h>Go to the source code of this file.
Macros | |
| #define | SPS30_I2C_ADDR (0x69 << 1) |
| #define | SPS30_CMD_START_MEAS 0x0010 |
| #define | SPS30_CMD_STOP_MEAS 0x0104 |
| #define | SPS30_CMD_READ_DRDY 0x0202 |
| #define | SPS30_CMD_READ_MEAS 0x0300 |
| #define | SPS30_CMD_SOFT_RESET 0xD304 |
| #define | SPS30_CMD_START_CLEAN 0x5607 |
| #define | SPS30_CMD_SLEEP 0x1001 |
| #define | SPS30_CMD_WAKEUP 0x1103 |
| #define | SPS30_CMD_CLEAN_INTERVAL 0x8004 |
Enumerations | |
| enum | clearing_t { CLR_NONE , CLR_START , CLR_PROCESS , CLR_STOP } |
Functions | |
| AQI_Level_t | sps30_ClassifyPM25 (char **label) |
| Classify the current PM2.5 mass concentration according to the AQI scale. | |
| int8_t | sps30_Is (I2C_HandleTypeDef *hi2c, int8_t tryInit) |
| |
| HAL_StatusTypeDef | sps30_Init (I2C_HandleTypeDef *hi2c) |
| initialization of sensor sps30 | |
| HAL_StatusTypeDef | sps30_On (I2C_HandleTypeDef *hi2c) |
| Turn on laser and fan to allow measurements. | |
| HAL_StatusTypeDef | sps30_Off (I2C_HandleTypeDef *hi2c) |
| Turn off laser and fan to stop measurements. | |
| HAL_StatusTypeDef | sps30_IsDataReady (I2C_HandleTypeDef *hi2c) |
| Check if data is available. | |
| HAL_StatusTypeDef | sps30_Read (I2C_HandleTypeDef *hi2c) |
| Read data if data is available. | |
| HAL_StatusTypeDef | sps30_IsOnOff (I2C_HandleTypeDef *hi2c, uint8_t *onOff) |
| |
| HAL_StatusTypeDef | sps30_StartCleaning (I2C_HandleTypeDef *hi2c) |
| manually start fan for cleaning, runs for about 10s Note: The sensor will be busy cleaning for 10 seconds. Data read during this time might be inconsistent due to high airflow. | |
| HAL_StatusTypeDef | sps30_GetAutoCleanInterval (I2C_HandleTypeDef *hi2c, uint32_t *interval_sec) |
| interval for auto cleaning | |
| HAL_StatusTypeDef | sps30_SetAutoCleanInterval (I2C_HandleTypeDef *hi2c, uint32_t interval_sec) |
| set interval for auto cleaning | |
| void | sps30_LogData (char *buf) |
| log data to buffer | |
| int8_t | sps30_Service (I2C_HandleTypeDef *hi2c) |
| the sensor need to be cleaning | |
Variables | |
| sps30_t | _sps30Data = {} |
| Live measurement data from the SPS30 sensor; updated by sps30_Read(). | |
| sps30_t | _bck_sps30Data = {} |
| Snapshot copy of the last completed SPS30 measurement; used for LoRaWAN transmission. | |
| static uint8_t | _isSps30 = 0 |
| static const uint8_t | _cleaningInterval = 100 |
| static clearing_t | _isClearing = CLR_NONE |
| static sleeper_t | _clearingTime = {} |
| #define SPS30_CMD_CLEAN_INTERVAL 0x8004 |
Definition at line 28 of file sps30.c.
Referenced by sps30_GetAutoCleanInterval(), and sps30_SetAutoCleanInterval().
| #define SPS30_CMD_READ_DRDY 0x0202 |
Definition at line 22 of file sps30.c.
Referenced by sps30_IsDataReady().
| #define SPS30_CMD_READ_MEAS 0x0300 |
Definition at line 23 of file sps30.c.
Referenced by sps30_Read().
| #define SPS30_CMD_SLEEP 0x1001 |
Definition at line 26 of file sps30.c.
Referenced by sps30_Init(), and sps30_Off().
| #define SPS30_CMD_SOFT_RESET 0xD304 |
Definition at line 24 of file sps30.c.
Referenced by sps30_Init().
| #define SPS30_CMD_START_CLEAN 0x5607 |
Definition at line 25 of file sps30.c.
Referenced by sps30_StartCleaning().
| #define SPS30_CMD_START_MEAS 0x0010 |
Definition at line 20 of file sps30.c.
Referenced by sps30_On().
| #define SPS30_CMD_STOP_MEAS 0x0104 |
Definition at line 21 of file sps30.c.
Referenced by sps30_Off().
| #define SPS30_CMD_WAKEUP 0x1103 |
Definition at line 27 of file sps30.c.
Referenced by sps30_Init(), and sps30_On().
| #define SPS30_I2C_ADDR (0x69 << 1) |
Definition at line 17 of file sps30.c.
Referenced by sps30_GetAutoCleanInterval(), sps30_Init(), sps30_IsDataReady(), sps30_Off(), sps30_On(), sps30_Read(), sps30_SetAutoCleanInterval(), and sps30_StartCleaning().
| enum clearing_t |
| AQI_Level_t sps30_ClassifyPM25 | ( | char ** | label | ) |
Classify the current PM2.5 mass concentration according to the AQI scale.
| label | Optional output pointer; if non-NULL, *label is set to a static human-readable string (e.g. "Good", "Moderate", "Hazardous"). |
Definition at line 47 of file sps30.c.
References _sps30Data, AQI_GOOD, AQI_HAZARDOUS, AQI_MODERATE, AQI_UNHEALTHY, AQI_UNHEALTHY_SENSITIVE, and AQI_VERY_UNHEALTHY.
Referenced by sps30_LogData().
| HAL_StatusTypeDef sps30_GetAutoCleanInterval | ( | I2C_HandleTypeDef * | hi2c, |
| uint32_t * | interval_sec ) |
interval for auto cleaning
Definition at line 300 of file sps30.c.
References _isSps30, SPS30_CMD_CLEAN_INTERVAL, SPS30_I2C_ADDR, and systemParams_CalculateCrc().
| HAL_StatusTypeDef sps30_Init | ( | I2C_HandleTypeDef * | hi2c | ) |
initialization of sensor sps30
| HAL_OK | - sensor is present, HAL_ERROR - error |
Definition at line 90 of file sps30.c.
References _isClearing, _isSps30, CLR_NONE, HAL_Delay(), I2C_IsDeviceReadyMT(), SPS30_CMD_SLEEP, SPS30_CMD_SOFT_RESET, SPS30_CMD_WAKEUP, and SPS30_I2C_ADDR.
Referenced by sps30_Is().
| int8_t sps30_Is | ( | I2C_HandleTypeDef * | hi2c, |
| int8_t | tryInit ) |
| tryInit | - in case sensor is not yet initialized, 1 - attempt to initialize again, 0 - no |
| 1 | - is present, 0 - is not |
Definition at line 83 of file sps30.c.
References _isSps30, and sps30_Init().
| HAL_StatusTypeDef sps30_IsDataReady | ( | I2C_HandleTypeDef * | hi2c | ) |
Check if data is available.
| HAL_OK,HAL_ERROR,HAL_BUSY |
Definition at line 201 of file sps30.c.
References _isSps30, SPS30_CMD_READ_DRDY, and SPS30_I2C_ADDR.
Referenced by sps30_IsOnOff(), and sps30_Read().
| HAL_StatusTypeDef sps30_IsOnOff | ( | I2C_HandleTypeDef * | hi2c, |
| uint8_t * | onOff ) |
Definition at line 271 of file sps30.c.
References sps30_IsDataReady().
| void sps30_LogData | ( | char * | buf | ) |
log data to buffer
Definition at line 356 of file sps30.c.
References _sps30Data, PRIf_02, PRIf_02D, and sps30_ClassifyPM25().
| HAL_StatusTypeDef sps30_Off | ( | I2C_HandleTypeDef * | hi2c | ) |
Turn off laser and fan to stop measurements.
| HAL_OK,HAL_ERROR |
Definition at line 175 of file sps30.c.
References _isSps30, HAL_Delay(), SPS30_CMD_SLEEP, SPS30_CMD_STOP_MEAS, and SPS30_I2C_ADDR.
Referenced by sps30_Service().
| HAL_StatusTypeDef sps30_On | ( | I2C_HandleTypeDef * | hi2c | ) |
Turn on laser and fan to allow measurements.
| HAL_OK,HAL_ERROR |
Definition at line 128 of file sps30.c.
References _cleaningInterval, _isClearing, _isSps30, _memsMainBlock, _sps30Data, CLR_NONE, CLR_START, HAL_Delay(), mems_WriteMainBlock(), SPS30_CMD_START_MEAS, SPS30_CMD_WAKEUP, SPS30_I2C_ADDR, and systemParams_CalculateCrc().
Referenced by sps30_Service().
| HAL_StatusTypeDef sps30_Read | ( | I2C_HandleTypeDef * | hi2c | ) |
Read data if data is available.
Definition at line 224 of file sps30.c.
References _sps30Data, SPS30_CMD_READ_MEAS, SPS30_I2C_ADDR, sps30_IsDataReady(), and systemParams_CalculateCrc().
| int8_t sps30_Service | ( | I2C_HandleTypeDef * | hi2c | ) |
the sensor need to be cleaning
| 0 | - no need, 1 - sensor is clearing |
Definition at line 367 of file sps30.c.
References _clearingTime, _isClearing, CLR_NONE, CLR_PROCESS, CLR_START, CLR_STOP, sleeper_Init(), sleeper_IsElapsed(), sps30_Off(), sps30_On(), sps30_StartCleaning(), and writeLog().
| HAL_StatusTypeDef sps30_SetAutoCleanInterval | ( | I2C_HandleTypeDef * | hi2c, |
| uint32_t | interval_sec ) |
set interval for auto cleaning
Definition at line 329 of file sps30.c.
References _isSps30, SPS30_CMD_CLEAN_INTERVAL, SPS30_I2C_ADDR, and systemParams_CalculateCrc().
| HAL_StatusTypeDef sps30_StartCleaning | ( | I2C_HandleTypeDef * | hi2c | ) |
manually start fan for cleaning, runs for about 10s Note: The sensor will be busy cleaning for 10 seconds. Data read during this time might be inconsistent due to high airflow.
Definition at line 288 of file sps30.c.
References _isSps30, SPS30_CMD_START_CLEAN, and SPS30_I2C_ADDR.
Referenced by sps30_Service().
| sps30_t _bck_sps30Data = {} |
Snapshot copy of the last completed SPS30 measurement; used for LoRaWAN transmission.
Definition at line 39 of file sps30.c.
Referenced by sensors_CayennelFromBckData(), sensors_CopyToBck(), sensors_ReadToBckFromDataBlock(), and sensors_WriteFromBckToDataBlock().
|
static |
Definition at line 42 of file sps30.c.
Referenced by sps30_On().
|
static |
Definition at line 45 of file sps30.c.
Referenced by sps30_Service().
|
static |
Definition at line 44 of file sps30.c.
Referenced by sps30_Init(), sps30_On(), and sps30_Service().
|
static |
Definition at line 41 of file sps30.c.
Referenced by sps30_GetAutoCleanInterval(), sps30_Init(), sps30_Is(), sps30_IsDataReady(), sps30_Off(), sps30_On(), sps30_SetAutoCleanInterval(), and sps30_StartCleaning().
| sps30_t _sps30Data = {} |
Live measurement data from the SPS30 sensor; updated by sps30_Read().
Definition at line 38 of file sps30.c.
Referenced by sensors_CopyToBck(), sps30_ClassifyPM25(), sps30_LogData(), sps30_On(), and sps30_Read().