Browse Source

Fix numbers checks

alexa
Xose Pérez 5 years ago
parent
commit
9ac06d0c7d
8 changed files with 115 additions and 33 deletions
  1. +8
    -5
      code/debug.sh
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +46
    -0
      code/espurna/config/hardware.h
  4. +1
    -0
      code/espurna/config/prototypes.h
  5. +5
    -0
      code/espurna/config/sensors.h
  6. +22
    -22
      code/espurna/sensors/HLW8012Sensor.h
  7. +6
    -6
      code/ota.py
  8. +26
    -0
      code/platformio.ini

+ 8
- 5
code/debug.sh View File

@ -19,7 +19,7 @@ rm -rf $FILE
function help {
echo
echo "Syntax: $0 [-e <environment>] [-d <dumpfile>]"
echo "Syntax: $0 [-e <environment>] [-f <elf_file>] [-d <dumpfile>]"
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


+ 1
- 0
code/espurna/config/arduino.h View File

@ -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)


+ 46
- 0
code/espurna/config/hardware.h View File

@ -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


+ 1
- 0
code/espurna/config/prototypes.h View File

@ -195,3 +195,4 @@ void webRequestRegister(web_request_callback_f callback);
#include "JustWifi.h"
typedef std::function<void(justwifi_messages_t code, char * parameter)> wifi_callback_f;
void wifiRegister(wifi_callback_f callback);
bool wifiConnected();

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

@ -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


+ 22
- 22
code/espurna/sensors/HLW8012Sensor.h View File

@ -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
};
// -----------------------------------------------------------------------------


+ 6
- 6
code/ota.py View File

@ -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()


+ 26
- 0
code/platformio.ini View File

@ -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}


Loading…
Cancel
Save