From 956215eac59b398f78bda5a2bf129dae63c32791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 21 Dec 2017 17:10:20 +0100 Subject: [PATCH] Default slot method in BaseSensor class --- code/espurna/sensors/AnalogSensor.h | 5 ----- code/espurna/sensors/BMX280Sensor.h | 5 ----- code/espurna/sensors/BaseSensor.h | 6 +++--- code/espurna/sensors/DHTSensor.h | 5 ----- code/espurna/sensors/DigitalSensor.h | 5 ----- code/espurna/sensors/EmonAnalogSensor.h | 5 ----- code/espurna/sensors/EventSensor.h | 6 ------ code/espurna/sensors/MHZ19Sensor.h | 5 ----- code/espurna/sensors/PMSX003Sensor.h | 14 ++++++++------ code/espurna/sensors/SHT3XI2CSensor.h | 5 ----- code/espurna/sensors/SI7021Sensor.h | 5 ----- 11 files changed, 11 insertions(+), 55 deletions(-) diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index 37e4f683..126fb3f9 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -35,11 +35,6 @@ class AnalogSensor : public BaseSensor { return String("ANALOG @ GPIO0"); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/BMX280Sensor.h b/code/espurna/sensors/BMX280Sensor.h index 298c164f..32d59890 100644 --- a/code/espurna/sensors/BMX280Sensor.h +++ b/code/espurna/sensors/BMX280Sensor.h @@ -66,11 +66,6 @@ class BMX280Sensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { if (index < _count) { diff --git a/code/espurna/sensors/BaseSensor.h b/code/espurna/sensors/BaseSensor.h index 0608d4aa..9433de0b 100644 --- a/code/espurna/sensors/BaseSensor.h +++ b/code/espurna/sensors/BaseSensor.h @@ -74,9 +74,6 @@ class BaseSensor { // Descriptive name of the sensor virtual String description() {} - // Descriptive name of the slot # index - virtual String slot(unsigned char index) {} - // Type for slot # index virtual magnitude_t type(unsigned char index) {} @@ -92,6 +89,9 @@ class BaseSensor { // Load the configuration manifest static void manifest(JsonArray& root) {}; + // Descriptive name of the slot # index + String slot(unsigned char index) { return description(); } + // Sensor ID unsigned char getID() { return _sensor_id; }; diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index fadbb116..ad61fe7c 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -66,11 +66,6 @@ class DHTSensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/DigitalSensor.h b/code/espurna/sensors/DigitalSensor.h index 4a065338..0d9487c9 100644 --- a/code/espurna/sensors/DigitalSensor.h +++ b/code/espurna/sensors/DigitalSensor.h @@ -65,11 +65,6 @@ class DigitalSensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/EmonAnalogSensor.h b/code/espurna/sensors/EmonAnalogSensor.h index 19d2b259..e781648f 100644 --- a/code/espurna/sensors/EmonAnalogSensor.h +++ b/code/espurna/sensors/EmonAnalogSensor.h @@ -58,11 +58,6 @@ class EmonAnalogSensor : public EmonSensor { return String("EMON @ ANALOG @ GPIO0"); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/EventSensor.h b/code/espurna/sensors/EventSensor.h index 8bb7987f..8d9282ee 100644 --- a/code/espurna/sensors/EventSensor.h +++ b/code/espurna/sensors/EventSensor.h @@ -80,12 +80,6 @@ class EventSensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - (void) index; - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/MHZ19Sensor.h b/code/espurna/sensors/MHZ19Sensor.h index b767ead5..947b8f70 100644 --- a/code/espurna/sensors/MHZ19Sensor.h +++ b/code/espurna/sensors/MHZ19Sensor.h @@ -81,11 +81,6 @@ class MHZ19Sensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { _error = SENSOR_ERROR_OK; diff --git a/code/espurna/sensors/PMSX003Sensor.h b/code/espurna/sensors/PMSX003Sensor.h index cc6d0d49..955de28e 100644 --- a/code/espurna/sensors/PMSX003Sensor.h +++ b/code/espurna/sensors/PMSX003Sensor.h @@ -103,20 +103,22 @@ class PMSX003Sensor : public BaseSensor { } void pre() { - if(millis() - _startTime > 30000) { - _error = SENSOR_ERROR_OK; - } else { + + if (millis() - _startTime < 30000) { _error = SENSOR_ERROR_WARM_UP; + return; } - _pms->requestRead(); - } - void tick() { + _error = SENSOR_ERROR_OK; + if(_pms->read(_data)) { _pm1dot0 = _data.PM_AE_UG_1_0; _pm2dot5 = _data.PM_AE_UG_2_5; _pm10 = _data.PM_AE_UG_10_0; } + + _pms->requestRead(); + } // Current value for slot # index diff --git a/code/espurna/sensors/SHT3XI2CSensor.h b/code/espurna/sensors/SHT3XI2CSensor.h index 4d2efefa..ce93fb41 100644 --- a/code/espurna/sensors/SHT3XI2CSensor.h +++ b/code/espurna/sensors/SHT3XI2CSensor.h @@ -63,11 +63,6 @@ class SHT3XI2CSensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { if (index < _count) { diff --git a/code/espurna/sensors/SI7021Sensor.h b/code/espurna/sensors/SI7021Sensor.h index 6cef7612..f95009a7 100644 --- a/code/espurna/sensors/SI7021Sensor.h +++ b/code/espurna/sensors/SI7021Sensor.h @@ -96,11 +96,6 @@ class SI7021Sensor : public BaseSensor { return String(buffer); } - // Descriptive name of the slot # index - String slot(unsigned char index) { - return description(); - } - // Type for slot # index magnitude_t type(unsigned char index) { if (index < _count) {