sds011 cleanups after moving to new lib

This commit is contained in:
cyberman54 2022-02-16 00:07:41 +01:00
parent 641b0ad7a2
commit 9dc3f03b62

View File

@ -11,8 +11,7 @@ static const char TAG[] = __FILE__;
#error cannot use IF482 together with SDS011 (both use UART#2) #error cannot use IF482 together with SDS011 (both use UART#2)
#endif #endif
// sds011 connected to UART(2) SdsDustSensor sds(Serial2);
static SdsDustSensor sdsSensor(Serial2);
// the results of the sensor: // the results of the sensor:
static float pm10, pm25; static float pm10, pm25;
@ -21,11 +20,12 @@ bool isSDS011Active = false;
// init // init
bool sds011_init() { bool sds011_init() {
pm25 = pm10 = 0.0; pm25 = pm10 = 0.0;
sdsSensor.begin();
String version = sdsSensor.queryFirmwareVersion().toString(); sds.begin(9600, SERIAL_8N1, 12, 35);
String version = sds.queryFirmwareVersion().toString();
ESP_LOGI(TAG, "SDS011 firmware version %s", version); ESP_LOGI(TAG, "SDS011 firmware version %s", version);
sdsSensor.setQueryReportingMode(); sds.setQueryReportingMode();
sds011_sleep(); // we do sleep/wakup by ourselves sds011_sleep(); // we do sleep/wakup by ourselves
return true; return true;
@ -34,7 +34,7 @@ bool sds011_init() {
// reading data: // reading data:
void sds011_loop() { void sds011_loop() {
if (isSDS011Active) { if (isSDS011Active) {
PmResult pm = sdsSensor.queryPm(); PmResult pm = sds.queryPm();
if (!pm.isOk()) { if (!pm.isOk()) {
pm25 = pm10 = 0.0; pm25 = pm10 = 0.0;
ESP_LOGE(TAG, "SDS011 query error"); ESP_LOGE(TAG, "SDS011 query error");
@ -55,14 +55,14 @@ void sds011_store(sdsStatus_t *sds_store) {
// putting the SDS-sensor to sleep // putting the SDS-sensor to sleep
void sds011_sleep(void) { void sds011_sleep(void) {
WorkingStateResult state = sdsSensor.sleep(); WorkingStateResult state = sds.sleep();
isSDS011Active = state.isWorking(); isSDS011Active = state.isWorking();
} }
// start the SDS-sensor // start the SDS-sensor
// needs 30 seconds for warming up // needs 30 seconds for warming up
void sds011_wakeup() { void sds011_wakeup() {
WorkingStateResult state = sdsSensor.wakeup(); WorkingStateResult state = sds.wakeup();
isSDS011Active = state.isWorking(); isSDS011Active = state.isWorking();
} }