Browse Source

Support for Teckin SP22 v1.4+

alexa
Xose Pérez 6 years ago
parent
commit
d2101a90fb
3 changed files with 26 additions and 22 deletions
  1. +5
    -4
      code/espurna/config/hardware.h
  2. +2
    -2
      code/espurna/config/sensors.h
  3. +19
    -16
      code/espurna/sensors/HLW8012Sensor.h

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

@ -2658,10 +2658,11 @@
#define HLW8012_POWER_RATIO 2533110 #define HLW8012_POWER_RATIO 2533110
#define HLW8012_INTERRUPT_ON FALLING #define HLW8012_INTERRUPT_ON FALLING
#define ALEXA_SUPPORT 0
#define DOMOTICZ_SUPPORT 0
#define HOMEASSISTANT_SUPPORT 0
#define THINGSPEAK_SUPPORT 0
//#define HLW8012_WAIT_FOR_WIFI 1
//#define ALEXA_SUPPORT 0
//#define DOMOTICZ_SUPPORT 0
//#define HOMEASSISTANT_SUPPORT 0
//#define THINGSPEAK_SUPPORT 0
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Homecube 16A is similar but some pins differ and it also has RGB LEDs // Homecube 16A is similar but some pins differ and it also has RGB LEDs


+ 2
- 2
code/espurna/config/sensors.h View File

@ -441,8 +441,8 @@
#endif #endif
#ifndef HLW8012_WAIT_FOR_WIFI #ifndef HLW8012_WAIT_FOR_WIFI
#define HLW8012_WAIT_FOR_WIFI 1 // Enable interrupts only after wifi connection
// has been established
#define HLW8012_WAIT_FOR_WIFI 0 // Weather to enable interrupts only after
// wifi connection has been stablished
#endif #endif
#ifndef HLW8012_INTERRUPT_ON #ifndef HLW8012_INTERRUPT_ON


+ 19
- 16
code/espurna/sensors/HLW8012Sensor.h View File

@ -9,8 +9,6 @@
#include "Arduino.h" #include "Arduino.h"
#include "BaseSensor.h" #include "BaseSensor.h"
#include <ESP8266WiFi.h>
#include <HLW8012.h> #include <HLW8012.h>
class HLW8012Sensor : public BaseSensor { class HLW8012Sensor : public BaseSensor {
@ -233,29 +231,34 @@ class HLW8012Sensor : public BaseSensor {
void _enableInterrupts(bool value) { void _enableInterrupts(bool value) {
static bool state = false;
static unsigned char _interrupt_cf = GPIO_NONE; static unsigned char _interrupt_cf = GPIO_NONE;
static unsigned char _interrupt_cf1 = GPIO_NONE; static unsigned char _interrupt_cf1 = GPIO_NONE;
if (value == state) return;
state = value;
if (value) { if (value) {
if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf);
_attach(this, _cf, HLW8012_INTERRUPT_ON);
_interrupt_cf = _cf;
if (_interrupt_cf != _cf) {
if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf);
_attach(this, _cf, HLW8012_INTERRUPT_ON);
_interrupt_cf = _cf;
}
if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1);
_attach(this, _cf1, HLW8012_INTERRUPT_ON);
_interrupt_cf1 = _cf1;
if (_interrupt_cf1 != _cf1) {
if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1);
_attach(this, _cf1, HLW8012_INTERRUPT_ON);
_interrupt_cf1 = _cf1;
}
} else { } else {
_detach(_cf);
_detach(_cf1);
_interrupt_cf = GPIO_NONE;
_interrupt_cf1 = GPIO_NONE;
if (GPIO_NONE != _interrupt_cf) {
_detach(_interrupt_cf);
_interrupt_cf = GPIO_NONE;
}
if (GPIO_NONE != _interrupt_cf1) {
_detach(_interrupt_cf1);
_interrupt_cf1 = GPIO_NONE;
}
} }


Loading…
Cancel
Save