Browse Source

Enable multiple Digital & Events sensors (#1832)

* enable multiple Digital, Events & PulseMeter

* delete SPI dependency

* back to only one PulseMeter

* deprecared pins
master
Pavel S 5 years ago
committed by Max Prokhorov
parent
commit
228fba5b3a
7 changed files with 513 additions and 36 deletions
  1. +58
    -0
      code/espurna/config/defaults.h
  2. +12
    -0
      code/espurna/config/deprecated.h
  3. +4
    -3
      code/espurna/config/hardware.h
  4. +248
    -16
      code/espurna/config/sensors.h
  5. +179
    -15
      code/espurna/sensor.ino
  6. +1
    -1
      code/espurna/sensors/EventSensor.h
  7. +11
    -1
      code/espurna/sensors/PulseMeterSensor.h

+ 58
- 0
code/espurna/config/defaults.h View File

@ -552,6 +552,64 @@
#define LED8_RELAY 8 #define LED8_RELAY 8
#endif #endif
// -----------------------------------------------------------------------------
// Digital Inputs
// -----------------------------------------------------------------------------
#ifndef DIGITAL1_PIN
#define DIGITAL1_PIN GPIO_NONE
#endif
#ifndef DIGITAL2_PIN
#define DIGITAL2_PIN GPIO_NONE
#endif
#ifndef DIGITAL3_PIN
#define DIGITAL3_PIN GPIO_NONE
#endif
#ifndef DIGITAL4_PIN
#define DIGITAL4_PIN GPIO_NONE
#endif
#ifndef DIGITAL5_PIN
#define DIGITAL5_PIN GPIO_NONE
#endif
#ifndef DIGITAL6_PIN
#define DIGITAL6_PIN GPIO_NONE
#endif
#ifndef DIGITAL7_PIN
#define DIGITAL7_PIN GPIO_NONE
#endif
#ifndef DIGITAL8_PIN
#define DIGITAL8_PIN GPIO_NONE
#endif
// -----------------------------------------------------------------------------
// Events
// -----------------------------------------------------------------------------
#ifndef EVENTS1_PIN
#define EVENTS1_PIN GPIO_NONE
#endif
#ifndef EVENTS2_PIN
#define EVENTS2_PIN GPIO_NONE
#endif
#ifndef EVENTS3_PIN
#define EVENTS3_PIN GPIO_NONE
#endif
#ifndef EVENTS4_PIN
#define EVENTS4_PIN GPIO_NONE
#endif
#ifndef EVENTS5_PIN
#define EVENTS5_PIN GPIO_NONE
#endif
#ifndef EVENTS6_PIN
#define EVENTS6_PIN GPIO_NONE
#endif
#ifndef EVENTS7_PIN
#define EVENTS7_PIN GPIO_NONE
#endif
#ifndef EVENTS8_PIN
#define EVENTS8_PIN GPIO_NONE
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// General // General
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 12
- 0
code/espurna/config/deprecated.h View File

@ -13,3 +13,15 @@
#warning RF_PIN is deprecated! Please use RFB_RX_PIN instead #warning RF_PIN is deprecated! Please use RFB_RX_PIN instead
#define RFB_RX_PIN RF_PIN #define RFB_RX_PIN RF_PIN
#endif #endif
// 1.13.6 allow multiple digitals
#ifdef DIGITAL_PIN
#warning DIGITAL_PIN is deprecated! Please use DIGITAL1_PIN instead
#define DIGITAL1_PIN DIGITAL_PIN
#endif
// 1.13.6 allow multiple events
#ifdef EVENTS_PIN
#warning EVENTS_PIN is deprecated! Please use EVENTS1_PIN instead
#define EVENTS1_PIN EVENTS_PIN
#endif

+ 4
- 3
code/espurna/config/hardware.h View File

@ -2521,8 +2521,9 @@
#ifndef DIGITAL_SUPPORT #ifndef DIGITAL_SUPPORT
#define DIGITAL_SUPPORT 1 #define DIGITAL_SUPPORT 1
#endif #endif
#define DIGITAL_PIN 16
#define DIGITAL_PIN_MODE INPUT
#define DIGITAL1_PIN 16
#define DIGITAL1_PIN_MODE INPUT
#define DIGITAL1_DEFAULT_STATE 0
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Heltec Touch Relay // Heltec Touch Relay
@ -3942,7 +3943,7 @@
// A bit of EVENTS - pin 10 // A bit of EVENTS - pin 10
#define EVENTS_SUPPORT 1 #define EVENTS_SUPPORT 1
#define EVENTS_PIN 6
#define EVENTS1_PIN 6
// Sonar // Sonar
#define SONAR_SUPPORT 1 #define SONAR_SUPPORT 1


+ 248
- 16
code/espurna/config/sensors.h View File

@ -260,16 +260,100 @@
#define DIGITAL_SUPPORT 0 #define DIGITAL_SUPPORT 0
#endif #endif
#ifndef DIGITAL_PIN
#define DIGITAL_PIN 2
#ifndef DIGITAL1_PIN
#define DIGITAL1_PIN 2
#endif #endif
#ifndef DIGITAL_PIN_MODE
#define DIGITAL_PIN_MODE INPUT_PULLUP
#ifndef DIGITAL1_PIN_MODE
#define DIGITAL1_PIN_MODE INPUT_PULLUP
#endif #endif
#ifndef DIGITAL_DEFAULT_STATE
#define DIGITAL_DEFAULT_STATE 1
#ifndef DIGITAL1_DEFAULT_STATE
#define DIGITAL1_DEFAULT_STATE 1
#endif
#ifndef DIGITAL2_PIN
#define DIGITAL2_PIN 2
#endif
#ifndef DIGITAL2_PIN_MODE
#define DIGITAL2_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL2_DEFAULT_STATE
#define DIGITAL2_DEFAULT_STATE 1
#endif
#ifndef DIGITAL3_PIN
#define DIGITAL3_PIN 2
#endif
#ifndef DIGITAL3_PIN_MODE
#define DIGITAL3_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL3_DEFAULT_STATE
#define DIGITAL3_DEFAULT_STATE 1
#endif
#ifndef DIGITAL4_PIN
#define DIGITAL4_PIN 2
#endif
#ifndef DIGITAL4_PIN_MODE
#define DIGITAL4_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL4_DEFAULT_STATE
#define DIGITAL4_DEFAULT_STATE 1
#endif
#ifndef DIGITAL5_PIN
#define DIGITAL5_PIN 2
#endif
#ifndef DIGITAL5_PIN_MODE
#define DIGITAL5_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL5_DEFAULT_STATE
#define DIGITAL5_DEFAULT_STATE 1
#endif
#ifndef DIGITAL6_PIN
#define DIGITAL6_PIN 2
#endif
#ifndef DIGITAL6_PIN_MODE
#define DIGITAL6_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL6_DEFAULT_STATE
#define DIGITAL6_DEFAULT_STATE 1
#endif
#ifndef DIGITAL7_PIN
#define DIGITAL7_PIN 2
#endif
#ifndef DIGITAL7_PIN_MODE
#define DIGITAL7_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL7_DEFAULT_STATE
#define DIGITAL7_DEFAULT_STATE 1
#endif
#ifndef DIGITAL8_PIN
#define DIGITAL8_PIN 2
#endif
#ifndef DIGITAL8_PIN_MODE
#define DIGITAL8_PIN_MODE INPUT_PULLUP
#endif
#ifndef DIGITAL8_DEFAULT_STATE
#define DIGITAL8_DEFAULT_STATE 1
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -366,24 +450,173 @@
#define EVENTS_SUPPORT 0 // Do not build with counter support by default #define EVENTS_SUPPORT 0 // Do not build with counter support by default
#endif #endif
#ifndef EVENTS_TRIGGER
#define EVENTS_TRIGGER 1 // 1 to trigger callback on events,
#ifndef EVENTS1_TRIGGER
#define EVENTS1_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS1_PIN
#define EVENTS1_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS1_PIN_MODE
#define EVENTS1_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS1_INTERRUPT_MODE
#define EVENTS1_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS1_DEBOUNCE
#define EVENTS1_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS2_TRIGGER
#define EVENTS2_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically // 0 to only count them and report periodically
#endif #endif
#ifndef EVENTS_PIN
#define EVENTS_PIN 2 // GPIO to monitor
#ifndef EVENTS2_PIN
#define EVENTS2_PIN 2 // GPIO to monitor
#endif #endif
#ifndef EVENTS_PIN_MODE
#define EVENTS_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#ifndef EVENTS2_PIN_MODE
#define EVENTS2_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif #endif
#ifndef EVENTS_INTERRUPT_MODE
#define EVENTS_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#ifndef EVENTS2_INTERRUPT_MODE
#define EVENTS2_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif #endif
#define EVENTS_DEBOUNCE 50 // Do not register events within less than 50 millis
#ifndef EVENTS2_DEBOUNCE
#define EVENTS2_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS3_TRIGGER
#define EVENTS3_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS3_PIN
#define EVENTS3_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS3_PIN_MODE
#define EVENTS3_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS3_INTERRUPT_MODE
#define EVENTS3_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS3_DEBOUNCE
#define EVENTS3_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS4_TRIGGER
#define EVENTS4_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS4_PIN
#define EVENTS4_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS4_PIN_MODE
#define EVENTS4_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS4_INTERRUPT_MODE
#define EVENTS4_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS4_DEBOUNCE
#define EVENTS4_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS5_TRIGGER
#define EVENTS5_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS5_PIN
#define EVENTS5_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS5_PIN_MODE
#define EVENTS5_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS5_INTERRUPT_MODE
#define EVENTS5_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS5_DEBOUNCE
#define EVENTS5_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS6_TRIGGER
#define EVENTS6_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS6_PIN
#define EVENTS6_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS6_PIN_MODE
#define EVENTS6_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS6_INTERRUPT_MODE
#define EVENTS6_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS6_DEBOUNCE
#define EVENTS6_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS7_TRIGGER
#define EVENTS7_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS7_PIN
#define EVENTS7_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS7_PIN_MODE
#define EVENTS7_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS7_INTERRUPT_MODE
#define EVENTS7_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS7_DEBOUNCE
#define EVENTS7_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
#ifndef EVENTS8_TRIGGER
#define EVENTS8_TRIGGER 1 // 1 to trigger callback on events,
// 0 to only count them and report periodically
#endif
#ifndef EVENTS8_PIN
#define EVENTS8_PIN 2 // GPIO to monitor
#endif
#ifndef EVENTS8_PIN_MODE
#define EVENTS8_PIN_MODE INPUT // INPUT, INPUT_PULLUP
#endif
#ifndef EVENTS8_INTERRUPT_MODE
#define EVENTS8_INTERRUPT_MODE RISING // RISING, FALLING, CHANGE
#endif
#ifndef EVENTS8_DEBOUNCE
#define EVENTS8_DEBOUNCE 50 // Do not register events within less than 50 millis
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Geiger sensor // Geiger sensor
@ -669,7 +902,6 @@
#ifndef PULSEMETER_SUPPORT #ifndef PULSEMETER_SUPPORT
#define PULSEMETER_SUPPORT 0 #define PULSEMETER_SUPPORT 0
#endif #endif
#ifndef PULSEMETER_PIN #ifndef PULSEMETER_PIN
#define PULSEMETER_PIN 5 #define PULSEMETER_PIN 5
#endif #endif


+ 179
- 15
code/espurna/sensor.ino View File

@ -574,11 +574,85 @@ void _sensorLoad() {
#if DIGITAL_SUPPORT #if DIGITAL_SUPPORT
{ {
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL_PIN);
sensor->setMode(DIGITAL_PIN_MODE);
sensor->setDefault(DIGITAL_DEFAULT_STATE);
_sensors.push_back(sensor);
#if (DIGITAL1_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL1_PIN);
sensor->setMode(DIGITAL1_PIN_MODE);
sensor->setDefault(DIGITAL1_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL2_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL2_PIN);
sensor->setMode(DIGITAL2_PIN_MODE);
sensor->setDefault(DIGITAL2_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL3_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL3_PIN);
sensor->setMode(DIGITAL3_PIN_MODE);
sensor->setDefault(DIGITAL3_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL4_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL4_PIN);
sensor->setMode(DIGITAL4_PIN_MODE);
sensor->setDefault(DIGITAL4_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL5_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL5_PIN);
sensor->setMode(DIGITAL5_PIN_MODE);
sensor->setDefault(DIGITAL5_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL6_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL6_PIN);
sensor->setMode(DIGITAL6_PIN_MODE);
sensor->setDefault(DIGITAL6_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL7_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL7_PIN);
sensor->setMode(DIGITAL7_PIN_MODE);
sensor->setDefault(DIGITAL7_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
#if (DIGITAL8_PIN != GPIO_NONE)
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL8_PIN);
sensor->setMode(DIGITAL8_PIN_MODE);
sensor->setDefault(DIGITAL8_DEFAULT_STATE);
_sensors.push_back(sensor);
}
#endif
} }
#endif #endif
@ -631,13 +705,101 @@ void _sensorLoad() {
#if EVENTS_SUPPORT #if EVENTS_SUPPORT
{ {
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS_PIN);
sensor->setTrigger(EVENTS_TRIGGER);
sensor->setPinMode(EVENTS_PIN_MODE);
sensor->setDebounceTime(EVENTS_DEBOUNCE);
sensor->setInterruptMode(EVENTS_INTERRUPT_MODE);
_sensors.push_back(sensor);
#if (EVENTS1_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS1_PIN);
sensor->setTrigger(EVENTS1_TRIGGER);
sensor->setPinMode(EVENTS1_PIN_MODE);
sensor->setDebounceTime(EVENTS1_DEBOUNCE);
sensor->setInterruptMode(EVENTS1_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS2_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS2_PIN);
sensor->setTrigger(EVENTS2_TRIGGER);
sensor->setPinMode(EVENTS2_PIN_MODE);
sensor->setDebounceTime(EVENTS2_DEBOUNCE);
sensor->setInterruptMode(EVENTS2_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS3_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS3_PIN);
sensor->setTrigger(EVENTS3_TRIGGER);
sensor->setPinMode(EVENTS3_PIN_MODE);
sensor->setDebounceTime(EVENTS3_DEBOUNCE);
sensor->setInterruptMode(EVENTS3_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS4_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS4_PIN);
sensor->setTrigger(EVENTS4_TRIGGER);
sensor->setPinMode(EVENTS4_PIN_MODE);
sensor->setDebounceTime(EVENTS4_DEBOUNCE);
sensor->setInterruptMode(EVENTS4_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS5_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS5_PIN);
sensor->setTrigger(EVENTS5_TRIGGER);
sensor->setPinMode(EVENTS5_PIN_MODE);
sensor->setDebounceTime(EVENTS5_DEBOUNCE);
sensor->setInterruptMode(EVENTS5_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS6_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS6_PIN);
sensor->setTrigger(EVENTS6_TRIGGER);
sensor->setPinMode(EVENTS6_PIN_MODE);
sensor->setDebounceTime(EVENTS6_DEBOUNCE);
sensor->setInterruptMode(EVENTS6_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS7_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS7_PIN);
sensor->setTrigger(EVENTS7_TRIGGER);
sensor->setPinMode(EVENTS7_PIN_MODE);
sensor->setDebounceTime(EVENTS7_DEBOUNCE);
sensor->setInterruptMode(EVENTS7_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
#if (EVENTS8_PIN != GPIO_NONE)
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS8_PIN);
sensor->setTrigger(EVENTS8_TRIGGER);
sensor->setPinMode(EVENTS8_PIN_MODE);
sensor->setDebounceTime(EVENTS8_DEBOUNCE);
sensor->setInterruptMode(EVENTS8_INTERRUPT_MODE);
_sensors.push_back(sensor);
}
#endif
} }
#endif #endif
@ -756,9 +918,11 @@ void _sensorLoad() {
#if PULSEMETER_SUPPORT #if PULSEMETER_SUPPORT
{ {
PulseMeterSensor * sensor = new PulseMeterSensor(); PulseMeterSensor * sensor = new PulseMeterSensor();
sensor->setGPIO(PULSEMETER_PIN); sensor->setGPIO(PULSEMETER_PIN);
sensor->setEnergyRatio(PULSEMETER_ENERGY_RATIO); sensor->setEnergyRatio(PULSEMETER_ENERGY_RATIO);
sensor->setInterruptMode(PULSEMETER_INTERRUPT_ON);
sensor->setDebounceTime(PULSEMETER_DEBOUNCE); sensor->setDebounceTime(PULSEMETER_DEBOUNCE);
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
@ -1043,10 +1207,10 @@ void _sensorInit() {
#endif // CSE7766_SUPPORT #endif // CSE7766_SUPPORT
#if PULSEMETER_SUPPORT
#if PULSEMETER_SUPPORT
if (_sensors[i]->getID() == SENSOR_PULSEMETER_ID) { if (_sensors[i]->getID() == SENSOR_PULSEMETER_ID) {
PulseMeterSensor * sensor = (PulseMeterSensor *) _sensors[i]; PulseMeterSensor * sensor = (PulseMeterSensor *) _sensors[i];
sensor->setEnergyRatio(getSetting("pwrRatioE", PULSEMETER_ENERGY_RATIO).toInt());
sensor->setEnergyRatio(getSetting("pwrRatioE", sensor->getEnergyRatio()).toInt());
} }
#endif // PULSEMETER_SUPPORT #endif // PULSEMETER_SUPPORT
@ -1235,7 +1399,7 @@ void _sensorConfigure() {
_sensorResetTS(); _sensorResetTS();
} }
sensor->setEnergyRatio(getSetting("pwrRatioE", PULSEMETER_ENERGY_RATIO).toInt());
sensor->setEnergyRatio(getSetting("pwrRatioE", sensor->getEnergyRatio()).toInt());
} }
#endif // PULSEMETER_SUPPORT #endif // PULSEMETER_SUPPORT


+ 1
- 1
code/espurna/sensors/EventSensor.h View File

@ -190,7 +190,7 @@ class EventSensor : public BaseSensor {
volatile unsigned long _counter = 0; volatile unsigned long _counter = 0;
unsigned char _value = 0; unsigned char _value = 0;
unsigned long _last = 0; unsigned long _last = 0;
unsigned long _debounce = microsecondsToClockCycles(EVENTS_DEBOUNCE * 1000);
unsigned long _debounce = microsecondsToClockCycles(EVENTS1_DEBOUNCE * 1000);
bool _trigger = false; bool _trigger = false;
bool _trigger_flag = false; bool _trigger_flag = false;


+ 11
- 1
code/espurna/sensors/PulseMeterSensor.h View File

@ -43,6 +43,10 @@ class PulseMeterSensor : public BaseSensor {
if (ratio > 0) _ratio = ratio; if (ratio > 0) _ratio = ratio;
} }
void setInterruptMode(unsigned char interrupt_mode) {
_interrupt_mode = interrupt_mode;
}
void setDebounceTime(unsigned long debounce) { void setDebounceTime(unsigned long debounce) {
_debounce = debounce; _debounce = debounce;
} }
@ -57,6 +61,10 @@ class PulseMeterSensor : public BaseSensor {
return _ratio; return _ratio;
} }
unsigned char getInterruptMode() {
return _interrupt_mode;
}
unsigned long getDebounceTime() { unsigned long getDebounceTime() {
return _debounce; return _debounce;
} }
@ -144,7 +152,7 @@ class PulseMeterSensor : public BaseSensor {
if (_gpio != _previous) { if (_gpio != _previous) {
if (_previous != GPIO_NONE) _detach(_previous); if (_previous != GPIO_NONE) _detach(_previous);
_attach(this, _gpio, PULSEMETER_INTERRUPT_ON);
_attach(this, _gpio, _interrupt_mode);
_previous = _gpio; _previous = _gpio;
} }
@ -171,6 +179,8 @@ class PulseMeterSensor : public BaseSensor {
unsigned long _previous_pulses = 0; unsigned long _previous_pulses = 0;
unsigned long _previous_time = 0; unsigned long _previous_time = 0;
unsigned char _interrupt_mode = FALLING;
}; };


Loading…
Cancel
Save