Browse Source

Flag sensor changes to avoid reinitializing them if unnecessary

fastled
Xose Pérez 7 years ago
parent
commit
42f5ee5376
10 changed files with 47 additions and 6 deletions
  1. +4
    -0
      code/espurna/sensors/BMX280Sensor.h
  2. +1
    -0
      code/espurna/sensors/BaseSensor.h
  3. +6
    -1
      code/espurna/sensors/DallasSensor.h
  4. +4
    -0
      code/espurna/sensors/EmonADC121Sensor.h
  5. +7
    -0
      code/espurna/sensors/EmonADS1X15Sensor.h
  6. +4
    -1
      code/espurna/sensors/EmonAnalogSensor.h
  7. +7
    -4
      code/espurna/sensors/EmonSensor.h
  8. +5
    -0
      code/espurna/sensors/MHZ19Sensor.h
  9. +5
    -0
      code/espurna/sensors/PMSX003Sensor.h
  10. +4
    -0
      code/espurna/sensors/SI7021Sensor.h

+ 4
- 0
code/espurna/sensors/BMX280Sensor.h View File

@ -22,6 +22,7 @@ class BMX280Sensor : public BaseSensor {
// ---------------------------------------------------------------------
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
_address = address;
}
@ -32,6 +33,9 @@ class BMX280Sensor : public BaseSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// Discover
if (_address == 0) {
unsigned char addresses[] = {0x76, 0x77};


+ 1
- 0
code/espurna/sensors/BaseSensor.h View File

@ -116,6 +116,7 @@ class BaseSensor {
void detach(unsigned char gpio);
int _error = 0;
bool _dirty = true;
unsigned char _count = 0;


+ 6
- 1
code/espurna/sensors/DallasSensor.h View File

@ -34,9 +34,11 @@ class DallasSensor : public BaseSensor {
// ---------------------------------------------------------------------
void setGPIO(unsigned char gpio, bool pullup = false) {
if (_gpio != gpio) _dirty = true;
if (_pullup != pullup) _dirty = true;
_gpio = gpio;
_interval = SENSOR_READ_INTERVAL / 2;
_pullup = pullup;
_interval = SENSOR_READ_INTERVAL / 2;
}
// ---------------------------------------------------------------------
@ -46,6 +48,9 @@ class DallasSensor : public BaseSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// OneWire
if (_wire) delete _wire;
_wire = new OneWire(_gpio);


+ 4
- 0
code/espurna/sensors/EmonADC121Sensor.h View File

@ -37,6 +37,7 @@ class EmonADC121Sensor : public EmonAnalogSensor {
// ---------------------------------------------------------------------
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
_address = address;
}
@ -47,6 +48,9 @@ class EmonADC121Sensor : public EmonAnalogSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// Discover
if (_address == 0) {
unsigned char addresses[] = {0x50, 0x51, 0x52, 0x54, 0x55, 0x56, 0x58, 0x59, 0x5A};


+ 7
- 0
code/espurna/sensors/EmonADS1X15Sensor.h View File

@ -106,18 +106,22 @@ class EmonADS1X15Sensor : public EmonSensor {
// ---------------------------------------------------------------------
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
_address = address;
}
void setType(unsigned char type) {
if (_type != type) _dirty = true;
_type = type;
}
void setMask(unsigned char mask) {
if (_mask != mask) _dirty = true;
_mask = mask;
}
void setGain(unsigned int gain) {
if (_gain != gain) _dirty = true;
_gain = gain;
}
@ -128,6 +132,9 @@ class EmonADS1X15Sensor : public EmonSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// Discover
if (_address == 0) {
unsigned char addresses[] = {0x48, 0x49, 0x4A, 0x4B};


+ 4
- 1
code/espurna/sensors/EmonAnalogSensor.h View File

@ -26,13 +26,16 @@ class EmonAnalogSensor : public EmonSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// Just one channel
_count = _magnitudes;
// Bit depth
_resolution = INTERNAL_ADC_RESOLUTION;
// Init analog PIN
// Init analog PIN)
pinMode(_gpio, INPUT);
// Call the parent class method


+ 7
- 4
code/espurna/sensors/EmonSensor.h View File

@ -29,15 +29,18 @@ class EmonSensor : public BaseSensor {
}
void setVoltage(double voltage) {
if (_voltage != voltage) _dirty = true;
_voltage = voltage;
}
void setReference(double ref) {
_reference = ref;
void setReference(double reference) {
if (_reference != reference) _dirty = true;
_reference = reference;
}
void setCurrentRatio(double ratio) {
_current_ratio = ratio;
void setCurrentRatio(double current_ratio) {
if (_current_ratio != current_ratio) _dirty = true;
_current_ratio = current_ratio;
}
// ---------------------------------------------------------------------


+ 5
- 0
code/espurna/sensors/MHZ19Sensor.h View File

@ -34,6 +34,8 @@ class MHZ19Sensor : public BaseSensor {
}
void setGPIO(unsigned char pin_rx, unsigned char pin_tx) {
if (_pin_rx != pin_rx) _dirty = true;
if (_pin_tx != pin_tx) _dirty = true;
_pin_rx = pin_rx;
_pin_tx = pin_tx;
}
@ -45,6 +47,9 @@ class MHZ19Sensor : public BaseSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
if (_serial) delete _serial;
_serial = new SoftwareSerial(_pin_rx, _pin_tx, false, 256);


+ 5
- 0
code/espurna/sensors/PMSX003Sensor.h View File

@ -25,6 +25,8 @@ class PMSX003Sensor : public BaseSensor {
}
void setGPIO(unsigned char pin_rx, unsigned char pin_tx) {
if (_pin_rx != pin_rx) _dirty = true;
if (_pin_tx != pin_tx) _dirty = true;
_pin_rx = pin_rx;
_pin_tx = pin_tx;
}
@ -36,6 +38,9 @@ class PMSX003Sensor : public BaseSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
if (_serial) delete _serial;
if (_pms) delete _pms;


+ 4
- 0
code/espurna/sensors/SI7021Sensor.h View File

@ -32,6 +32,7 @@ class SI7021Sensor : public BaseSensor {
// ---------------------------------------------------------------------
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
_address = address;
}
@ -42,6 +43,9 @@ class SI7021Sensor : public BaseSensor {
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
_dirty = false;
// Discover
if (_address == 0) {
unsigned char addresses[] = {0x40};


Loading…
Cancel
Save