sds011: change device driver library (initial)
This commit is contained in:
parent
45f531ccfb
commit
eeed8b7bfe
@ -1,11 +1,13 @@
|
||||
#ifndef _SDS011READ_H
|
||||
#define _SDS011READ_H
|
||||
|
||||
#include <SDS011.h>
|
||||
#include <SdsDustSensor.h>
|
||||
#include "globals.h"
|
||||
|
||||
#define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25"
|
||||
|
||||
extern bool isSDS011Active;
|
||||
|
||||
bool sds011_init();
|
||||
void sds011_loop();
|
||||
void sds011_sleep(void);
|
||||
|
@ -77,7 +77,7 @@ lib_deps_sensors =
|
||||
adafruit/Adafruit BME280 Library @ ^2.2.1
|
||||
adafruit/Adafruit BMP085 Library @ ^1.2.0
|
||||
boschsensortec/BSEC Software Library @ 1.6.1480
|
||||
https://github.com/ricki-z/SDS011.git
|
||||
https://github.com/cyberman54/sds-dust-sensors-arduino-library.git
|
||||
lib_deps_basic =
|
||||
https://github.com/dbSuS/libpax.git @ ^1.0.0
|
||||
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
|
||||
|
@ -9,10 +9,6 @@ static const char TAG[] = __FILE__;
|
||||
|
||||
Ticker cyclicTimer;
|
||||
|
||||
#if (HAS_SDS011)
|
||||
extern boolean isSDS011Active;
|
||||
#endif
|
||||
|
||||
void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
|
||||
|
||||
// do all housekeeping
|
||||
|
@ -10,35 +10,41 @@ static const char TAG[] = __FILE__;
|
||||
#if (HAS_IF482)
|
||||
#error cannot use IF482 together with SDS011 (both use UART#2)
|
||||
#endif
|
||||
// UART(2) is unused in this project
|
||||
static HardwareSerial sdsSerial(2); // so we use it here
|
||||
static SDS011 sdsSensor; // fine dust sensor
|
||||
|
||||
// sds011 connected to UART(2)
|
||||
static SdsDustSensor sdsSensor(Serial2);
|
||||
|
||||
// the results of the sensor:
|
||||
static float pm10, pm25;
|
||||
boolean isSDS011Active;
|
||||
bool isSDS011Active = false;
|
||||
|
||||
// init
|
||||
bool sds011_init() {
|
||||
pm25 = pm10 = 0.0;
|
||||
sdsSensor.begin(&sdsSerial, SDS_RX, SDS_TX);
|
||||
sdsSensor.begin();
|
||||
|
||||
String version = sdsSensor.queryFirmwareVersion().toString();
|
||||
ESP_LOGI(TAG, "SDS011 firmware version %s", version);
|
||||
sdsSensor.setQueryReportingMode();
|
||||
sds011_sleep(); // we do sleep/wakup by ourselves
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// reading data:
|
||||
void sds011_loop() {
|
||||
if (isSDS011Active) {
|
||||
int sdsErrorCode = sdsSensor.read(&pm25, &pm10);
|
||||
if (sdsErrorCode) {
|
||||
PmResult pm = sdsSensor.queryPm();
|
||||
if (!pm.isOk()) {
|
||||
pm25 = pm10 = 0.0;
|
||||
ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode);
|
||||
ESP_LOGE(TAG, "SDS011 query error");
|
||||
} else {
|
||||
pm25 = pm.pm25;
|
||||
pm10 = pm.pm10;
|
||||
ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
|
||||
}
|
||||
sds011_sleep();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// retrieving stored data:
|
||||
@ -49,17 +55,15 @@ void sds011_store(sdsStatus_t *sds_store) {
|
||||
|
||||
// putting the SDS-sensor to sleep
|
||||
void sds011_sleep(void) {
|
||||
sdsSensor.sleep();
|
||||
isSDS011Active = false;
|
||||
WorkingStateResult state = sdsSensor.sleep();
|
||||
isSDS011Active = state.isWorking();
|
||||
}
|
||||
|
||||
// start the SDS-sensor
|
||||
// needs 30 seconds for warming up
|
||||
void sds011_wakeup() {
|
||||
if (!isSDS011Active) {
|
||||
sdsSensor.wakeup();
|
||||
isSDS011Active = true;
|
||||
}
|
||||
WorkingStateResult state = sdsSensor.wakeup();
|
||||
isSDS011Active = state.isWorking();
|
||||
}
|
||||
|
||||
#endif // HAS_SDS011
|
||||
|
Loading…
Reference in New Issue
Block a user