From 9ac06d0c7dcc6fd7a33d86d4d82e23f97754a4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 22 Nov 2018 21:30:51 +0100 Subject: [PATCH] Fix numbers checks --- code/debug.sh | 13 +++++--- code/espurna/config/arduino.h | 1 + code/espurna/config/hardware.h | 46 ++++++++++++++++++++++++++++ code/espurna/config/prototypes.h | 1 + code/espurna/config/sensors.h | 5 +++ code/espurna/sensors/HLW8012Sensor.h | 44 +++++++++++++------------- code/ota.py | 12 ++++---- code/platformio.ini | 26 ++++++++++++++++ 8 files changed, 115 insertions(+), 33 deletions(-) diff --git a/code/debug.sh b/code/debug.sh index 63e0fcc6..c9b28ed4 100755 --- a/code/debug.sh +++ b/code/debug.sh @@ -19,7 +19,7 @@ rm -rf $FILE function help { echo - echo "Syntax: $0 [-e ] [-d ]" + echo "Syntax: $0 [-e ] [-f ] [-d ]" echo } @@ -29,6 +29,10 @@ while [[ $# -gt 1 ]]; do key="$1" case $key in + -f) + ELF="$2" + shift + ;; -e) ENVIRONMENT="$2" shift @@ -44,12 +48,11 @@ while [[ $# -gt 1 ]]; do done # check environment folder +if [ ! -f $ELF ]; then if [ $ENVIRONMENT == "" ]; then - echo "No environment defined" - help - exit 1 + ELF=.pioenvs/$ENVIRONMENT/firmware.elf +fi fi -ELF=.pioenvs/$ENVIRONMENT/firmware.elf if [ ! -f $ELF ]; then echo "Could not find ELF file for the selected environment: $ELF" exit 2 diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 5625972a..83656b1b 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -101,6 +101,7 @@ //#define PHYX_ESP12_RGB //#define IWOOLE_LED_TABLE_LAMP //#define EXS_WIFI_RELAY_V50 +//#define TECKIN_SP22_V14 //-------------------------------------------------------------------------------- // Features (values below are non-default values) diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 9d40c0ef..f9a055d5 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -2617,6 +2617,52 @@ #define HLW8012_POWER_RATIO 3414290 #define HLW8012_INTERRUPT_ON FALLING +// ----------------------------------------------------------------------------- +// Teckin SP22 v1.4 - v1.6 +// ----------------------------------------------------------------------------- + +#elif defined(TECKIN_SP22_V14) + + // Info + #define MANUFACTURER "TECKIN" + #define DEVICE "SP22_V14" + + // Buttons + #define BUTTON1_PIN 1 + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + #define BUTTON1_RELAY 1 + + // Relays + #define RELAY1_PIN 14 + #define RELAY1_TYPE RELAY_TYPE_NORMAL + + // LEDs + #define LED1_PIN 3 + #define LED1_PIN_INVERSE 1 + #define LED2_PIN 13 + #define LED2_PIN_INVERSE 1 + #define LED2_MODE LED_MODE_FINDME + #define LED2_RELAY 1 + + // HJL01 / BL0937 + #ifndef HLW8012_SUPPORT + #define HLW8012_SUPPORT 1 + #endif + #define HLW8012_SEL_PIN 12 + #define HLW8012_CF1_PIN 5 + #define HLW8012_CF_PIN 4 + + #define HLW8012_SEL_CURRENT LOW + #define HLW8012_CURRENT_RATIO 20730 + #define HLW8012_VOLTAGE_RATIO 264935 + #define HLW8012_POWER_RATIO 2533110 + #define HLW8012_INTERRUPT_ON FALLING + + #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 // https://www.amazon.de/gp/product/B07D7RVF56/ref=oh_aui_detailpage_o00_s01?ie=UTF8&psc=1 diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 3e3d3579..ecc80efa 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -195,3 +195,4 @@ void webRequestRegister(web_request_callback_f callback); #include "JustWifi.h" typedef std::function wifi_callback_f; void wifiRegister(wifi_callback_f callback); +bool wifiConnected(); diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index 8681194a..ad725601 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -440,6 +440,11 @@ #define HLW8012_USE_INTERRUPTS 1 // Use interrupts to trap HLW8012 signals #endif +#ifndef HLW8012_WAIT_FOR_WIFI +#define HLW8012_WAIT_FOR_WIFI 1 // Enable interrupts only after wifi connection + // has been established +#endif + #ifndef HLW8012_INTERRUPT_ON #define HLW8012_INTERRUPT_ON CHANGE // When to trigger the interrupt // Use CHANGE for HLW8012 diff --git a/code/espurna/sensors/HLW8012Sensor.h b/code/espurna/sensors/HLW8012Sensor.h index 14a5855f..1f7d24a7 100644 --- a/code/espurna/sensors/HLW8012Sensor.h +++ b/code/espurna/sensors/HLW8012Sensor.h @@ -148,14 +148,10 @@ class HLW8012Sensor : public BaseSensor { // Handle interrupts #if HLW8012_USE_INTERRUPTS - _enableInterrupts(true); - #else - _onconnect_handler = WiFi.onStationModeGotIP([this](WiFiEventStationModeGotIP ipInfo) { - _enableInterrupts(true); - }); - _ondisconnect_handler = WiFi.onStationModeDisconnected([this](WiFiEventStationModeDisconnected ipInfo) { + #if HLW8012_WAIT_FOR_WIFI == 0 _enableInterrupts(false); - }); + _enableInterrupts(true); + #endif #endif _ready = true; @@ -205,6 +201,15 @@ class HLW8012Sensor : public BaseSensor { return 0; } + // Pre-read hook (usually to populate registers with up-to-date data) + #if HLW8012_USE_INTERRUPTS + #if HLW8012_WAIT_FOR_WIFI + void pre() { + _enableInterrupts(wifiConnected()); + } + #endif + #endif + // Toggle between current and voltage monitoring #if HLW8012_USE_INTERRUPTS == 0 // Post-read hook (usually to reset things) @@ -228,22 +233,22 @@ class HLW8012Sensor : public BaseSensor { void _enableInterrupts(bool value) { + static bool state = false; static unsigned char _interrupt_cf = GPIO_NONE; static unsigned char _interrupt_cf1 = GPIO_NONE; + if (value == state) return; + state = value; + if (value) { - if (_interrupt_cf != _cf) { - if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf); - _attach(this, _cf, HLW8012_INTERRUPT_ON); - _interrupt_cf = _cf; - } + if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf); + _attach(this, _cf, HLW8012_INTERRUPT_ON); + _interrupt_cf = _cf; - if (_interrupt_cf1 != _cf1) { - if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1); - _attach(this, _cf1, HLW8012_INTERRUPT_ON); - _interrupt_cf1 = _cf1; - } + if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1); + _attach(this, _cf1, HLW8012_INTERRUPT_ON); + _interrupt_cf1 = _cf1; } else { @@ -266,11 +271,6 @@ class HLW8012Sensor : public BaseSensor { HLW8012 * _hlw8012 = NULL; - #if HLW8012_USE_INTERRUPTS == 0 - WiFiEventHandler _onconnect_handler; - WiFiEventHandler _ondisconnect_handler; - #endif - }; // ----------------------------------------------------------------------------- diff --git a/code/ota.py b/code/ota.py index a52ea7e0..a7454cce 100755 --- a/code/ota.py +++ b/code/ota.py @@ -55,9 +55,9 @@ def on_service_state_change(zeroconf, service_type, name, state_change): 'app_name': '', 'app_version': '', 'target_board': '', - 'mem_size': '', - 'sdk_size': '', - 'free_space': '', + 'mem_size': 0, + 'sdk_size': 0, + 'free_space': 0, } for key, item in info.properties.items(): @@ -101,9 +101,9 @@ def list_devices(): device.get('app_name', ''), device.get('app_version', ''), device.get('target_board', ''), - device.get('mem_size', ''), - device.get('sdk_size', ''), - device.get('free_space', ''), + device.get('mem_size', 0), + device.get('sdk_size', 0), + device.get('free_space', 0), )) print() diff --git a/code/platformio.ini b/code/platformio.ini index 4685ec2f..d097b036 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -2579,6 +2579,32 @@ upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} extra_scripts = ${common.extra_scripts} +[env:teckin-sp22-v14] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DTECKIN_SP22_V14 +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} + +[env:teckin-sp22-v14-ota] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board_1m} +board_build.flash_mode = ${common.flash_mode} +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m0m} -DTECKIN_SP22_V14 +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +upload_port = ${common.upload_port} +upload_flags = ${common.upload_flags} +extra_scripts = ${common.extra_scripts} + [env:homecube-16a] platform = ${common.platform} framework = ${common.framework}