sds011 code sanitizations

This commit is contained in:
Verkehrsrot committed 2020-02-05 22:13:30 +01:00
1 parent bc198b722b
commit 867c5477df
24 files changed
+38 -5400

No files matched your search

+4
View File
@@ -10,6 +10,10 @@
// Hardware related definitions for generic ESP32 boards
// generic.h is kitchensink with all available options
// SDS011 dust sensor settings
#define HAS_SDS011 1 // use SDS011
#define SDS011_SERIAL 9600, SERIAL_8N1, GPIO_NUM_19, GPIO_NUM_23 // SDS011 RX, TX
#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
// pin definitions for SPI slave interface
+33 -35
View File
@@ -3,60 +3,58 @@
// Local logging tag
static const char TAG[] = __FILE__;
#include <sds011read.h>
#include "sds011read.h"
// UART(2) is unused in this project
#if (HAS_IF482)
#error cannot use IF482 together with SDS011 (both use UART#2)
#endif
static HardwareSerial sdsSerial(2); // so we use it here
static SDS011 sdsSensor; // fine dust sensor
#ifndef SDS011_SERIAL
#error serial settings for SDS011 connection missing
#endif
static HardwareSerial sdsSerial(2); // so we use it here
static SDS011 sdsSensor; // fine dust sensor
// the results of the sensor:
float pm25;
float pm25;
float pm10;
boolean isSDS011Active;
// init
bool sds011_init()
{
pm25 = pm10 = 0.0;
sdsSerial.begin(9600, SERIAL_8N1, ESP_PIN_RX, ESP_PIN_TX);
sdsSensor.begin (&sdsSerial);
sdsSensor.contmode(0); // for safety: no wakeup/sleep by the sensor
sds011_sleep(); // we do it by ourselves
return true;
bool sds011_init() {
pm25 = pm10 = 0.0;
sdsSerial.begin(SDS011_SERIAL);
sdsSensor.begin(&sdsSerial);
//sdsSensor.contmode(0); // for safety: no wakeup/sleep by the sensor
sds011_sleep(); // we do it by ourselves
return true;
}
// reading data:
void sds011_loop()
{
if ( isSDS011Active ) {
int sdsErrorCode = sdsSensor.read(&pm25, &pm10);
if (sdsErrorCode) {
pm25 = pm10 = 0.0;
ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode);
}
else {
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
}
sds011_sleep();
void sds011_loop() {
if (isSDS011Active) {
int sdsErrorCode = sdsSensor.read(&pm25, &pm10);
if (sdsErrorCode) {
pm25 = pm10 = 0.0;
ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode);
} else {
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
}
return;
sds011_sleep();
}
return;
}
// putting the SDS-sensor to sleep
void sds011_sleep(void)
{
sdsSensor.sleep();
isSDS011Active = false;
void sds011_sleep(void) {
sdsSensor.sleep();
isSDS011Active = false;
}
// start the SDS-sensor
// needs 30 seconds for warming up
void sds011_wakeup()
{
if ( !isSDS011Active ) {
sdsSensor.wakeup();
isSDS011Active = true;
}
void sds011_wakeup() {
if (!isSDS011Active) {
sdsSensor.wakeup();
isSDS011Active = true;
}
}
-4
View File
@@ -21,10 +21,6 @@ void SendPayload(uint8_t port, sendprio_t prio) {
MessageBuffer_t
SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[]
//#if (HAS_SDS011)
// sds011_loop();
//#endif
SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePrio = prio;