From ead7dc809282a4d87b195ac8528483e9f2d3143c Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 11 May 2018 13:14:28 -0300 Subject: [PATCH 01/19] Update Spanish Translation Update Spanish Translation --- sonoff/language/es-AR.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index 200af4e1a..33b130711 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -91,7 +91,7 @@ #define D_FALSE "Falso" #define D_FILE "Archivo" #define D_FREE_MEMORY "Memoria Libre" -#define D_FREQUENCY "Frequency" +#define D_FREQUENCY "Frecuencia" #define D_GAS "Gas" #define D_GATEWAY "Gateway" #define D_GROUP "Grupo" @@ -131,7 +131,7 @@ #define D_RESTART_REASON "Causa Reinicio" #define D_RESTORE "Restauración" #define D_RETAINED "Grabado" -#define D_RULE "Rule" +#define D_RULE "Regla" #define D_SAVE "Grabar" #define D_SENSOR "Sensor" #define D_SSID "SSId" @@ -200,7 +200,7 @@ #define D_ERASED_SECTOR "Sector borrado" // webserver.ino -#define D_MINIMAL_FIRMWARE_PLEASE_UPGRADE "firmware MÍNIMO - actualice por favor" +#define D_MINIMAL_FIRMWARE_PLEASE_UPGRADE "Firmware MÍNIMO - actualice por favor" #define D_WEBSERVER_ACTIVE_ON "Servidor web activo en" #define D_WITH_IP_ADDRESS "con dirección IP" #define D_WEBSERVER_STOPPED "Servidor web detenido" From b9cad25e15a3a58c79935506348b95dbf6a8b0de Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 11 May 2018 13:23:43 -0300 Subject: [PATCH 02/19] Updated Spanish Translation Updated Spanish Translation --- sonoff/language/es-AR.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index 33b130711..e77f8ebc8 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v5.12.0m + * Updated until v5.13.1a \*********************************************************************/ #define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) From 7e9db309bfeeb9bc0f048b7a728ea831ccb75dde Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Fri, 11 May 2018 22:20:21 -0300 Subject: [PATCH 03/19] Fix Translation Error for PL #2698 Fix Translation Error for PL #2698 --- sonoff/language/pl-PL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index e1b1a5878..6446cc0a4 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -43,7 +43,7 @@ #define D_HOUR_MINUTE_SEPARATOR ":" #define D_MINUTE_SECOND_SEPARATOR ":" -#define D_DAY3LIST "PonWtoŚroCzwPiąSobNie" +#define D_DAY3LIST "NiePonWtoŚroCzwPiąSob" #define D_MONTH3LIST "StyLutMarKwiMajCzeLipSieWrzPaźLisGru" // Non JSON decimal separator From e6a1eff8ed82b72c2f9d12dc02d62a8f7170daa5 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sat, 12 May 2018 21:15:59 +0200 Subject: [PATCH 04/19] Add support for sensor SI1145 5.13.1a * Add support for sensor SI1145 UV Index / IR / Visible light (#2496) --- sonoff/_releasenotes.ino | 1 + sonoff/i18n.h | 2 + sonoff/language/bg-BG.h | 2 + sonoff/language/cs-CZ.h | 2 + sonoff/language/de-DE.h | 2 + sonoff/language/el-GR.h | 2 + sonoff/language/en-GB.h | 2 + sonoff/language/es-AR.h | 2 + sonoff/language/fr-FR.h | 2 + sonoff/language/hu-HU.h | 2 + sonoff/language/it-IT.h | 4 +- sonoff/language/nl-NL.h | 2 + sonoff/language/pl-PL.h | 2 + sonoff/language/pt-BR.h | 2 + sonoff/language/pt-PT.h | 2 + sonoff/language/ru-RU.h | 2 + sonoff/language/zh-CN.h | 2 + sonoff/language/zh-TW.h | 2 + sonoff/user_config.h | 1 + sonoff/xsns_16_tsl2561.ino | 6 +- sonoff/xsns_24_si1145.ino | 370 +++++++++++++++++++++++++++++++++++++ 21 files changed, 410 insertions(+), 4 deletions(-) create mode 100644 sonoff/xsns_24_si1145.ino diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index bfb2b08c2..b0e96480c 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -11,6 +11,7 @@ * Add rule state test for On/Off in addition to 0/1 (#2613) * Add hardware serial option to MHZ-19 sensor (#2659) * Add Eastron SDM120 energy meter (#2694) + * Add support for sensor SI1145 UV Index / IR / Visible light (#2496) * Updated Italian language file (#2618) * Update TasmotaSerial to 2.0.0 allowing Hardware Serial Fallback when correct connections are configured * Optimize command handling diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 5e34007f3..ea626017c 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -73,6 +73,7 @@ #define D_JSON_I2CSCAN_NO_DEVICES_FOUND "No devices found" #define D_JSON_ID "Id" #define D_JSON_ILLUMINANCE "Illuminance" +#define D_JSON_INFRARED "Infrared" #define D_JSON_UNKNOWN "Unknown" #define D_JSON_LIGHT "Light" #define D_JSON_LOCAL_TIME "Local" @@ -121,6 +122,7 @@ #define D_JSON_TYPE "Type" #define D_JSON_UPTIME "Uptime" #define D_JSON_UTC_TIME "UTC" +#define D_JSON_UVINDEX "UvIndex" #define D_JSON_UV_LEVEL "UvLevel" #define D_JSON_VCC "Vcc" #define D_JSON_VERSION "Version" diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index b3aa97528..dfaebe802 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "моментален" // Button immediate #define D_INDEX "Индекс" #define D_INFO "Информация" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Инициализирано" #define D_IP_ADDRESS "IP адрес" #define D_LIGHT "Светлина" @@ -155,6 +156,7 @@ #define D_UPTIME "Време от стартирането" #define D_USER "Потребител" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "Ниво на ултравиолетово излъчване" #define D_VERSION "Версия" #define D_VOLTAGE "Напрежение" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 6c07717c9..49239eef8 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "Okamžité" // Button immediate #define D_INDEX "Index" #define D_INFO "Informace" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inicializovaný" #define D_IP_ADDRESS "Adresa IP" #define D_LIGHT "Světlo" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "Uživatel" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "úroveň UV" #define D_VERSION "Verze" #define D_VOLTAGE "Napětí" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index d2808dd9c..0201e00ed 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "direkt" // Button immediate #define D_INDEX "Index" #define D_INFO "Info" +#define D_INFRARED "Infrarot" #define D_INITIALIZED "initialisiert" #define D_IP_ADDRESS "IP-Adresse" #define D_LIGHT "Licht" @@ -155,6 +156,7 @@ #define D_UPTIME "Laufzeit" #define D_USER "Benutzer" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV-Index" #define D_UV_LEVEL "UV-Level" #define D_VERSION "Version" #define D_VOLTAGE "Spannung" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 595281610..c479b3586 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "Φωτεινότητα" // Button immediate #define D_INDEX "Κατάλογος" #define D_INFO "Πληροφορίες" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Αρχικό" #define D_IP_ADDRESS "IP Address" #define D_LIGHT "Light" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "Χρήστης" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "Επίπεδο UV" #define D_VERSION "Έκδοση" #define D_VOLTAGE "Τάση" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 32ca90460..b841f02d5 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "immediate" // Button immediate #define D_INDEX "Index" #define D_INFO "Info" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Initialized" #define D_IP_ADDRESS "IP Address" #define D_LIGHT "Light" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "User" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "UV Level" #define D_VERSION "Version" #define D_VOLTAGE "Voltage" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index e77f8ebc8..64f8fd677 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "inmediato" // Button immediate #define D_INDEX "Índice" #define D_INFO "Información" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inicializado" #define D_IP_ADDRESS "Dirección IP" #define D_LIGHT "Luz" @@ -155,6 +156,7 @@ #define D_UPTIME "Tiempo Encendido" #define D_USER "Usuario" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "Índice UV" #define D_UV_LEVEL "Nivel UV" #define D_VERSION "Versión" #define D_VOLTAGE "Tensión" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index b13e22418..cae6908ae 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "immédiat" // Button immediate #define D_INDEX "Index" #define D_INFO "Info" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Initialisé" #define D_IP_ADDRESS "Adresse IP" #define D_LIGHT "Lumière" @@ -155,6 +156,7 @@ #define D_UPTIME "Durée d'activité" #define D_USER "Utilisateur" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "Index UV" #define D_UV_LEVEL "Niveau UV" #define D_VERSION "Version" #define D_VOLTAGE "Tension" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 0a5c9a79c..773ff3d2e 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "azonnali" // Button immediate #define D_INDEX "Index" #define D_INFO "Info" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inicializálva" #define D_IP_ADDRESS "IP Cím" #define D_LIGHT "Fény" @@ -155,6 +156,7 @@ #define D_UPTIME "Üzemidő" #define D_USER "Felhasználó" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "UV Szint" #define D_VERSION "Verzió" #define D_VOLTAGE "Feszültség" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 85f91a0a2..2096fe8c3 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v5.13.0 + * Updated until v5.13.1a \*********************************************************************/ #define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -102,6 +102,7 @@ #define D_IMMEDIATE "immediato" // Button immediate #define D_INDEX "Indice" #define D_INFO "Info" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inizializzato" #define D_IP_ADDRESS "Indirizzo IP" #define D_LIGHT "Luce" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "Utente" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "Indice UV" #define D_UV_LEVEL "Livello UV" #define D_VERSION "Versione" #define D_VOLTAGE "Tensione" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 081a957e3..dec9a11de 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "onmiddelijk" // Button immediate #define D_INDEX "Index" #define D_INFO "Info" +#define D_INFRARED "Infrarood" #define D_INITIALIZED "Geinitialiseerd" #define D_IP_ADDRESS "IP Adres" #define D_LIGHT "Licht" @@ -155,6 +156,7 @@ #define D_UPTIME "Bedrijfstijd" #define D_USER "Gebruiker" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV-index" #define D_UV_LEVEL "UV niveau" #define D_VERSION "Versie" #define D_VOLTAGE "Spanning" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 6446cc0a4..5d30ffd7f 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "Natychmiastowe" // Button immediate #define D_INDEX "Indeks" #define D_INFO "Informacja" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Zainicjowany" #define D_IP_ADDRESS "Adres IP" #define D_LIGHT "Światło" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "Użytkownik" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "Poziom UV" #define D_VERSION "Wersja" #define D_VOLTAGE "Napięcie" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 83f53a165..c29cf9bd9 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "Imediato" // Button immediate #define D_INDEX "Índice" #define D_INFO "Informação" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inicializado" #define D_IP_ADDRESS "Endereço IP" #define D_LIGHT "Luz" @@ -155,6 +156,7 @@ #define D_UPTIME "Tempo de atividade" #define D_USER "Usuário" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "Índice UV" #define D_UV_LEVEL "Nível UV" #define D_VERSION "Versão" #define D_VOLTAGE "Voltagem" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 9765830bd..4605975c3 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "Immediato" // Button immediate #define D_INDEX "Indíce" #define D_INFO "Info" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Inicializado" #define D_IP_ADDRESS "Endereço IP" #define D_LIGHT "Luz" @@ -155,6 +156,7 @@ #define D_UPTIME "Tempo de Atividade" #define D_USER "Utilizador" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "Indíce UV" #define D_UV_LEVEL "Nível UV" #define D_VERSION "Versão" #define D_VOLTAGE "Voltagem" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index c19eccbf1..0de9d88cc 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "немедленно" // Button immediate #define D_INDEX "Индекс" #define D_INFO "Инфо" +#define D_INFRARED "Infrared" #define D_INITIALIZED "Инициализировано" #define D_IP_ADDRESS "IP Адрес" #define D_LIGHT "Свет" @@ -155,6 +156,7 @@ #define D_UPTIME "Uptime" #define D_USER "Пользователь" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "УФ уровень" #define D_VERSION "Версия" #define D_VOLTAGE "Напряжение" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index c10cbdc16..fce4fe3e7 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "immediate" // Button immediate #define D_INDEX "索引:" #define D_INFO "信息" +#define D_INFRARED "Infrared" #define D_INITIALIZED "初始化完成" #define D_IP_ADDRESS "IP地址" #define D_LIGHT "灯" @@ -155,6 +156,7 @@ #define D_UPTIME "运行时间" #define D_USER "用户名" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "紫外线水平" #define D_VERSION "版本" #define D_VOLTAGE "电压" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index e2c5b9193..f17caf10e 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -102,6 +102,7 @@ #define D_IMMEDIATE "immediate" // Button immediate #define D_INDEX "索引:" #define D_INFO "信息" +#define D_INFRARED "Infrared" #define D_INITIALIZED "初始化完成" #define D_IP_ADDRESS "IP地址" #define D_LIGHT "燈" @@ -155,6 +156,7 @@ #define D_UPTIME "運行時間" #define D_USER "用戶名" #define D_UTC_TIME "UTC" +#define D_UV_INDEX "UV Index" #define D_UV_LEVEL "紫外線等級" #define D_VERSION "版本" #define D_VOLTAGE "電壓" diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 5c57d4478..9368c6806 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -258,6 +258,7 @@ #define USE_BH1750 // Add I2C code for BH1750 sensor (+0k5 code) // #define USE_VEML6070 // Add I2C code for VEML6070 sensor (+0k5 code) // #define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Joba_Tsl2561 (+2k3 code) + #define USE_SI1145 // Add I2C code for SI1145/46/47 sensor (+1k code) // #define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code) // #define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code) // #define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code) diff --git a/sonoff/xsns_16_tsl2561.ino b/sonoff/xsns_16_tsl2561.ino index 6fe09a88f..63abbc4a1 100644 --- a/sonoff/xsns_16_tsl2561.ino +++ b/sonoff/xsns_16_tsl2561.ino @@ -22,9 +22,9 @@ /*********************************************************************************************\ * TSL2561 - Light Intensity * - * I2C Addresses: 0x29 (low), 0x39 (float) or 0x49 (high) - * * Using library https://github.com/joba-1/Joba_Tsl2561 + * + * I2C Addresses: 0x29 (low), 0x39 (float) or 0x49 (high) \*********************************************************************************************/ #include @@ -112,5 +112,5 @@ boolean Xsns16(byte function) return result; } -#endif // USE_TSL2561_JOBA +#endif // USE_TSL2561 #endif // USE_I2C diff --git a/sonoff/xsns_24_si1145.ino b/sonoff/xsns_24_si1145.ino new file mode 100644 index 000000000..e09f95398 --- /dev/null +++ b/sonoff/xsns_24_si1145.ino @@ -0,0 +1,370 @@ +/* + xsns_24_si1145.ino - SI1145/46/47 UV Index / IR / Visible light sensor support for Sonoff-Tasmota + + Copyright (C) 2018 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_I2C +#ifdef USE_SI1145 +/*********************************************************************************************\ + * SI1145/46/47 - UV Index / IR / Visible light + * + * Based on library https://github.com/SeeedDocument/Grove-Sunlight_Sensor/ + * + * I2C Addresses: 0x60 +\*********************************************************************************************/ + +uint8_t si1145_type = 0; + +/********************************************************************************************/ + +#define SI114X_ADDR 0X60 +// +//commands +// +#define SI114X_QUERY 0X80 +#define SI114X_SET 0XA0 +#define SI114X_NOP 0X00 +#define SI114X_RESET 0X01 +#define SI114X_BUSADDR 0X02 +#define SI114X_PS_FORCE 0X05 +#define SI114X_GET_CAL 0X12 +#define SI114X_ALS_FORCE 0X06 +#define SI114X_PSALS_FORCE 0X07 +#define SI114X_PS_PAUSE 0X09 +#define SI114X_ALS_PAUSE 0X0A +#define SI114X_PSALS_PAUSE 0X0B +#define SI114X_PS_AUTO 0X0D +#define SI114X_ALS_AUTO 0X0E +#define SI114X_PSALS_AUTO 0X0F +// +//IIC REGISTERS +// +#define SI114X_PART_ID 0X00 +#define SI114X_REV_ID 0X01 +#define SI114X_SEQ_ID 0X02 +#define SI114X_INT_CFG 0X03 +#define SI114X_IRQ_ENABLE 0X04 +#define SI114X_IRQ_MODE1 0x05 +#define SI114X_IRQ_MODE2 0x06 +#define SI114X_HW_KEY 0X07 +#define SI114X_MEAS_RATE0 0X08 +#define SI114X_MEAS_RATE1 0X09 +#define SI114X_PS_RATE 0X0A +#define SI114X_PS_LED21 0X0F +#define SI114X_PS_LED3 0X10 +#define SI114X_UCOEFF0 0X13 +#define SI114X_UCOEFF1 0X14 +#define SI114X_UCOEFF2 0X15 +#define SI114X_UCOEFF3 0X16 +#define SI114X_WR 0X17 +#define SI114X_COMMAND 0X18 +#define SI114X_RESPONSE 0X20 +#define SI114X_IRQ_STATUS 0X21 +#define SI114X_ALS_VIS_DATA0 0X22 +#define SI114X_ALS_VIS_DATA1 0X23 +#define SI114X_ALS_IR_DATA0 0X24 +#define SI114X_ALS_IR_DATA1 0X25 +#define SI114X_PS1_DATA0 0X26 +#define SI114X_PS1_DATA1 0X27 +#define SI114X_PS2_DATA0 0X28 +#define SI114X_PS2_DATA1 0X29 +#define SI114X_PS3_DATA0 0X2A +#define SI114X_PS3_DATA1 0X2B +#define SI114X_AUX_DATA0_UVINDEX0 0X2C +#define SI114X_AUX_DATA1_UVINDEX1 0X2D +#define SI114X_RD 0X2E +#define SI114X_CHIP_STAT 0X30 +// +//Parameters +// +#define SI114X_CHLIST 0X01 +#define SI114X_CHLIST_ENUV 0x80 +#define SI114X_CHLIST_ENAUX 0x40 +#define SI114X_CHLIST_ENALSIR 0x20 +#define SI114X_CHLIST_ENALSVIS 0x10 +#define SI114X_CHLIST_ENPS1 0x01 +#define SI114X_CHLIST_ENPS2 0x02 +#define SI114X_CHLIST_ENPS3 0x04 + +#define SI114X_PSLED12_SELECT 0X02 +#define SI114X_PSLED3_SELECT 0X03 + +#define SI114X_PS_ENCODE 0X05 +#define SI114X_ALS_ENCODE 0X06 + +#define SI114X_PS1_ADCMUX 0X07 +#define SI114X_PS2_ADCMUX 0X08 +#define SI114X_PS3_ADCMUX 0X09 + +#define SI114X_PS_ADC_COUNTER 0X0A +#define SI114X_PS_ADC_GAIN 0X0B +#define SI114X_PS_ADC_MISC 0X0C + +#define SI114X_ALS_IR_ADC_MUX 0X0E +#define SI114X_AUX_ADC_MUX 0X0F + +#define SI114X_ALS_VIS_ADC_COUNTER 0X10 +#define SI114X_ALS_VIS_ADC_GAIN 0X11 +#define SI114X_ALS_VIS_ADC_MISC 0X12 + +#define SI114X_LED_REC 0X1C + +#define SI114X_ALS_IR_ADC_COUNTER 0X1D +#define SI114X_ALS_IR_ADC_GAIN 0X1E +#define SI114X_ALS_IR_ADC_MISC 0X1F +// +//USER SETTINGS DEFINE +// +//ADCMUX +#define SI114X_ADCMUX_SMALL_IR 0x00 +#define SI114X_ADCMUX_VISIABLE 0x02 +#define SI114X_ADCMUX_LARGE_IR 0x03 +#define SI114X_ADCMUX_NO 0x06 +#define SI114X_ADCMUX_GND 0x25 +#define SI114X_ADCMUX_TEMPERATURE 0x65 +#define SI114X_ADCMUX_VDD 0x75 +//LED SEL +#define SI114X_PSLED12_SELECT_PS1_NONE 0x00 +#define SI114X_PSLED12_SELECT_PS1_LED1 0x01 +#define SI114X_PSLED12_SELECT_PS1_LED2 0x02 +#define SI114X_PSLED12_SELECT_PS1_LED3 0x04 +#define SI114X_PSLED12_SELECT_PS2_NONE 0x00 +#define SI114X_PSLED12_SELECT_PS2_LED1 0x10 +#define SI114X_PSLED12_SELECT_PS2_LED2 0x20 +#define SI114X_PSLED12_SELECT_PS2_LED3 0x40 +#define SI114X_PSLED3_SELECT_PS2_NONE 0x00 +#define SI114X_PSLED3_SELECT_PS2_LED1 0x10 +#define SI114X_PSLED3_SELECT_PS2_LED2 0x20 +#define SI114X_PSLED3_SELECT_PS2_LED3 0x40 +//ADC GAIN DIV +#define SI114X_ADC_GAIN_DIV1 0X00 +#define SI114X_ADC_GAIN_DIV2 0X01 +#define SI114X_ADC_GAIN_DIV4 0X02 +#define SI114X_ADC_GAIN_DIV8 0X03 +#define SI114X_ADC_GAIN_DIV16 0X04 +#define SI114X_ADC_GAIN_DIV32 0X05 +//LED CURRENT +#define SI114X_LED_CURRENT_5MA 0X01 +#define SI114X_LED_CURRENT_11MA 0X02 +#define SI114X_LED_CURRENT_22MA 0X03 +#define SI114X_LED_CURRENT_45MA 0X04 +//Recovery period the ADC takes before making a PS measurement +#define SI114X_ADC_COUNTER_1ADCCLK 0X00 +#define SI114X_ADC_COUNTER_7ADCCLK 0X01 +#define SI114X_ADC_COUNTER_15ADCCLK 0X02 +#define SI114X_ADC_COUNTER_31ADCCLK 0X03 +#define SI114X_ADC_COUNTER_63ADCCLK 0X04 +#define SI114X_ADC_COUNTER_127ADCCLK 0X05 +#define SI114X_ADC_COUNTER_255ADCCLK 0X06 +#define SI114X_ADC_COUNTER_511ADCCLK 0X07 +//ADC MISC +#define SI114X_ADC_MISC_LOWRANGE 0X00 +#define SI114X_ADC_MISC_HIGHRANGE 0X20 +#define SI114X_ADC_MISC_ADC_NORMALPROXIMITY 0X00 +#define SI114X_ADC_MISC_ADC_RAWADC 0X04 +//INT OE +#define SI114X_INT_CFG_INTOE 0X01 +//IRQ ENABLE +#define SI114X_IRQEN_ALS 0x01 +#define SI114X_IRQEN_PS1 0x04 +#define SI114X_IRQEN_PS2 0x08 +#define SI114X_IRQEN_PS3 0x10 + +/********************************************************************************************/ + +uint8_t Si1145ReadByte(uint8_t reg) +{ + return I2cRead8(SI114X_ADDR, reg); +} + +uint16_t Si1145ReadHalfWord(uint8_t reg) +{ + return I2cRead16LE(SI114X_ADDR, reg); +} + +bool Si1145WriteByte(uint8_t reg, uint16_t val) +{ + I2cWrite8(SI114X_ADDR, reg, val); +} + +uint8_t Si1145WriteParamData(uint8_t p, uint8_t v) +{ + Si1145WriteByte(SI114X_WR, v); + Si1145WriteByte(SI114X_COMMAND, p | SI114X_SET); + return Si1145ReadByte(SI114X_RD); +} + +/********************************************************************************************/ + +void Si1145Reset() +{ + Si1145WriteByte(SI114X_MEAS_RATE0, 0); + Si1145WriteByte(SI114X_MEAS_RATE1, 0); + Si1145WriteByte(SI114X_IRQ_ENABLE, 0); + Si1145WriteByte(SI114X_IRQ_MODE1, 0); + Si1145WriteByte(SI114X_IRQ_MODE2, 0); + Si1145WriteByte(SI114X_INT_CFG, 0); + Si1145WriteByte(SI114X_IRQ_STATUS, 0xFF); + + Si1145WriteByte(SI114X_COMMAND, SI114X_RESET); + delay(10); + Si1145WriteByte(SI114X_HW_KEY, 0x17); + delay(10); +} + +void Si1145DeInit() +{ + //ENABLE UV reading + //these reg must be set to the fixed value + Si1145WriteByte(SI114X_UCOEFF0, 0x29); + Si1145WriteByte(SI114X_UCOEFF1, 0x89); + Si1145WriteByte(SI114X_UCOEFF2, 0x02); + Si1145WriteByte(SI114X_UCOEFF3, 0x00); + Si1145WriteParamData(SI114X_CHLIST, SI114X_CHLIST_ENUV |SI114X_CHLIST_ENALSIR | SI114X_CHLIST_ENALSVIS |SI114X_CHLIST_ENPS1); + // + //set LED1 CURRENT(22.4mA)(It is a normal value for many LED) + // + Si1145WriteParamData(SI114X_PS1_ADCMUX, SI114X_ADCMUX_LARGE_IR); + Si1145WriteByte(SI114X_PS_LED21, SI114X_LED_CURRENT_22MA); + Si1145WriteParamData(SI114X_PSLED12_SELECT, SI114X_PSLED12_SELECT_PS1_LED1); // + // + //PS ADC SETTING + // + Si1145WriteParamData(SI114X_PS_ADC_GAIN, SI114X_ADC_GAIN_DIV1); + Si1145WriteParamData(SI114X_PS_ADC_COUNTER, SI114X_ADC_COUNTER_511ADCCLK); + Si1145WriteParamData(SI114X_PS_ADC_MISC, SI114X_ADC_MISC_HIGHRANGE|SI114X_ADC_MISC_ADC_RAWADC); + // + //VIS ADC SETTING + // + Si1145WriteParamData(SI114X_ALS_VIS_ADC_GAIN, SI114X_ADC_GAIN_DIV1); + Si1145WriteParamData(SI114X_ALS_VIS_ADC_COUNTER, SI114X_ADC_COUNTER_511ADCCLK); + Si1145WriteParamData(SI114X_ALS_VIS_ADC_MISC, SI114X_ADC_MISC_HIGHRANGE); + // + //IR ADC SETTING + // + Si1145WriteParamData(SI114X_ALS_IR_ADC_GAIN, SI114X_ADC_GAIN_DIV1); + Si1145WriteParamData(SI114X_ALS_IR_ADC_COUNTER, SI114X_ADC_COUNTER_511ADCCLK); + Si1145WriteParamData(SI114X_ALS_IR_ADC_MISC, SI114X_ADC_MISC_HIGHRANGE); + // + //interrupt enable + // + Si1145WriteByte(SI114X_INT_CFG, SI114X_INT_CFG_INTOE); + Si1145WriteByte(SI114X_IRQ_ENABLE, SI114X_IRQEN_ALS); + // + //AUTO RUN + // + Si1145WriteByte(SI114X_MEAS_RATE0, 0xFF); + Si1145WriteByte(SI114X_COMMAND, SI114X_PSALS_AUTO); +} + +boolean Si1145Begin() +{ + if (Si1145ReadByte(SI114X_PART_ID) != 0X45) { return false; } + + Si1145Reset(); + Si1145DeInit(); + return true; +} + +// returns the UV index * 100 (divide by 100 to get the index) +uint16_t Si1145ReadUV() +{ + return Si1145ReadHalfWord(SI114X_AUX_DATA0_UVINDEX0); +} + +// returns visible+IR light levels +uint16_t Si1145ReadVisible() +{ + return Si1145ReadHalfWord(SI114X_ALS_VIS_DATA0); +} + +// returns IR light levels +uint16_t Si1145ReadIR() +{ + return Si1145ReadHalfWord(SI114X_ALS_IR_DATA0); +} + +/********************************************************************************************/ + +void Si1145Update() +{ + if (!si1145_type) { + if (Si1145Begin()) { + si1145_type = 1; + snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "SI1145", SI114X_ADDR); + AddLog(LOG_LEVEL_DEBUG); + } + } +} + +#ifdef USE_WEBSERVER +const char HTTP_SNS_SI1145[] PROGMEM = "%s" + "{s}SI1145 " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}" // {s} = , {m} = , {e} = + "{s}SI1145 " D_INFRARED "{m}%d " D_UNIT_LUX "{e}" + "{s}SI1145 " D_UV_INDEX "{m}%d.%d{e}"; +#endif // USE_WEBSERVER + +void Si1145Show(boolean json) +{ + if (si1145_type) { + uint16_t visible = Si1145ReadVisible(); + uint16_t infrared = Si1145ReadIR(); + uint16_t uvindex = Si1145ReadUV(); + if (json) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SI1145\":{\"" D_JSON_ILLUMINANCE "\":%d,\"" D_JSON_INFRARED "\":%d,\"" D_JSON_UVINDEX "\":%d.%d}"), + mqtt_data, visible, infrared, uvindex /100, uvindex %100); +#ifdef USE_DOMOTICZ + if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, visible); +#endif // USE_DOMOTICZ + } else { +#ifdef USE_WEBSERVER + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SI1145, mqtt_data, visible, infrared, uvindex /100, uvindex %100); +#endif + } + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +#define XSNS_24 + +boolean Xsns24(byte function) +{ + boolean result = false; + + if (i2c_flg) { + switch (function) { + case FUNC_EVERY_SECOND: + Si1145Update(); + break; + case FUNC_JSON_APPEND: + Si1145Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_APPEND: + Si1145Show(0); + break; +#endif // USE_WEBSERVER + } + } + return result; +} + +#endif // USE_SI1145 +#endif // USE_I2C From 2167c642a6a118d35a33d4c7b949228fa79eb058 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 17:03:26 -0300 Subject: [PATCH 05/19] Update Spanish Translation --- sonoff/language/es-AR.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index 64f8fd677..a0f80b73f 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -102,7 +102,7 @@ #define D_IMMEDIATE "inmediato" // Button immediate #define D_INDEX "Índice" #define D_INFO "Información" -#define D_INFRARED "Infrared" +#define D_INFRARED "Infrarrojo" #define D_INITIALIZED "Inicializado" #define D_IP_ADDRESS "Dirección IP" #define D_LIGHT "Luz" From 162a3cc2ce096bc2d7f5f92f20779ad07181ba0a Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 20:31:34 -0300 Subject: [PATCH 06/19] Create templates for Bugs, Request and Troubleshooting As an attempt to help on the issues resolutions, a clasification is needed also providing some steps for the descriptions required. --- .github/ISSUE_TEMPLATE/Bug_report.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Bug_report.md diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md new file mode 100644 index 000000000..39c8f0f9d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** + +A clear and concise description of what the bug is. + +Also, make sure these boxes are checked [x] before submitting your issue - Thank you! + +- [ ] Searched the problem in issues and in the wiki +- [ ] Hardware used : +- [ ] Provide the output of command ``status 0`` : + +**To Reproduce** +Steps to reproduce the behavior: + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. From ef0f05025fa3f8fc26d8db820db38df5c8f0033c Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 20:32:52 -0300 Subject: [PATCH 07/19] Create Custom.md --- .github/ISSUE_TEMPLATE/Custom.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Custom.md diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md new file mode 100644 index 000000000..91e3ef143 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -0,0 +1,16 @@ +--- +name: Troubleshooting +about: Troubleshooting Help + +--- + +Make sure these boxes are checked [x] before submitting your issue - Thank you! + +- [ ] Searched the problem in issues (https://github.com/arendst/Sonoff-Tasmota/issues) +- [ ] Searched the problem in the wiki (https://github.com/arendst/Sonoff-Tasmota/wiki/Troubleshooting) +- [ ] Searched the problem in the forum (https://forum.digital-pig.com/) +- [ ] Searched the problem in the discussion group (https://groups.google.com/d/forum/sonoffusers) +- [ ] Hardware used : +- [ ] Provide the output of command ``status 0`` : + +**Please, remember to close the issue when the problem has been addressed.** From fa4e37b09b94dc5eae8597fa958f06c43828af5e Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 20:33:14 -0300 Subject: [PATCH 08/19] Create Feature_request.md --- .github/ISSUE_TEMPLATE/Feature_request.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/Feature_request.md diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md new file mode 100644 index 000000000..d10bdb778 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -0,0 +1,18 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- +**Have you look for this feature in other issues and in the wiki?** + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 1e9b985e6b2fd911973e631b933fac822a5ab706 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 20:33:35 -0300 Subject: [PATCH 09/19] Delete ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index cb8cd1d03..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,6 +0,0 @@ -Make sure these boxes are checked before submitting your issue - Thank you! - -- [ ] What hardware you are using -- [ ] Provide the output of command ``status 0`` -- [ ] If you have a stack dump decode it: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst -- [ ] For better debug messages: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst From 043ce1a51c61c329080fda00cadaf75f21909f4e Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 20:34:35 -0300 Subject: [PATCH 10/19] Troubleshooting Template --- .github/ISSUE_TEMPLATE/Custom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md index 91e3ef143..e4a0eb8df 100644 --- a/.github/ISSUE_TEMPLATE/Custom.md +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -1,6 +1,6 @@ --- name: Troubleshooting -about: Troubleshooting Help +about: Users Troubleshooting Help --- From 2cb713f5c65b05d9ae44cdeb9c3c67cc66063d1f Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 21:03:26 -0300 Subject: [PATCH 11/19] Update Feature_request.md --- .github/ISSUE_TEMPLATE/Feature_request.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index d10bdb778..8a0895c8e 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -16,3 +16,5 @@ A clear and concise description of any alternative solutions or features you've **Additional context** Add any other context or screenshots about the feature request here. + +**(Please, remember to close the issue when the problem has been addressed)** From da89d75f8bb1d4f3c9aa62037ce1cbfffad78e07 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 21:03:37 -0300 Subject: [PATCH 12/19] Update Custom.md --- .github/ISSUE_TEMPLATE/Custom.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/Custom.md b/.github/ISSUE_TEMPLATE/Custom.md index e4a0eb8df..62e47446d 100644 --- a/.github/ISSUE_TEMPLATE/Custom.md +++ b/.github/ISSUE_TEMPLATE/Custom.md @@ -13,4 +13,4 @@ Make sure these boxes are checked [x] before submitting your issue - Thank you! - [ ] Hardware used : - [ ] Provide the output of command ``status 0`` : -**Please, remember to close the issue when the problem has been addressed.** +**(Please, remember to close the issue when the problem has been addressed)** From b83543d209c0c188a7abedb3a86d2a6593be38d2 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 12 May 2018 21:03:46 -0300 Subject: [PATCH 13/19] Update Bug_report.md --- .github/ISSUE_TEMPLATE/Bug_report.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 39c8f0f9d..7dc1e3499 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -25,3 +25,5 @@ If applicable, add screenshots to help explain your problem. **Additional context** Add any other context about the problem here. + +**(Please, remember to close the issue when the problem has been addressed)** From 0cfc921461ef3b6674c7f3cd786342419edc9d2a Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sun, 13 May 2018 00:12:02 -0300 Subject: [PATCH 14/19] Fix DST and STD times for Southern Hemisphere Fix issue #2684 DST and STD times for Southern Hemisphere --- sonoff/support.ino | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sonoff/support.ino b/sonoff/support.ino index e56d7e540..84760e92b 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1389,17 +1389,22 @@ void RtcSecond() if (local_time > 1451602800) { // 2016-01-01 int32_t time_offset = Settings.timezone * SECS_PER_HOUR; if (99 == Settings.timezone) { + dstoffset = DaylightSavingTime.offset * SECS_PER_MIN; + stdoffset = StandardTime.offset * SECS_PER_MIN; if (DaylightSavingTime.hemis) { - dstoffset = StandardTime.offset * SECS_PER_MIN; // Southern hemisphere - stdoffset = DaylightSavingTime.offset * SECS_PER_MIN; + // Southern hemisphere + if ((utc_time >= (standard_time - dstoffset)) && (utc_time < (daylight_saving_time - stdoffset))) { + time_offset = stdoffset; // Standard Time + } else { + time_offset = dstoffset; // Daylight Saving Time + } } else { - dstoffset = DaylightSavingTime.offset * SECS_PER_MIN; // Northern hemisphere - stdoffset = StandardTime.offset * SECS_PER_MIN; - } - if ((utc_time >= (daylight_saving_time - stdoffset)) && (utc_time < (standard_time - dstoffset))) { - time_offset = dstoffset; // Daylight Saving Time - } else { - time_offset = stdoffset; // Standard Time + // Northern hemisphere + if ((utc_time >= (daylight_saving_time - stdoffset)) && (utc_time < (standard_time - dstoffset))) { + time_offset = dstoffset; // Daylight Saving Time + } else { + time_offset = stdoffset; // Standard Time + } } } local_time += time_offset; From a6e01565760cc99297e7a5663263dfa6a6b165dc Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 13 May 2018 17:38:44 +0200 Subject: [PATCH 15/19] Add SetOption16 Power legacy/indexed mode 5.13.1a * Add SetOption26 to enforce use of indexes even when only one relay is present (#1055) --- sonoff/_releasenotes.ino | 2 ++ sonoff/settings.h | 2 +- sonoff/sonoff.ino | 14 +++++++++++--- sonoff/xdrv_00_mqtt.ino | 13 ++++++------- sonoff/xdrv_01_light.ino | 2 +- sonoff/xdrv_07_home_assistant.ino | 4 ++-- sonoff/xdrv_10_rules.ino | 11 +++++++---- sonoff/xsns_24_si1145.ino | 17 ++++++++++++----- 8 files changed, 42 insertions(+), 23 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index b0e96480c..27638c3de 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -7,6 +7,8 @@ * Fix KNX config error (#2628) * Fix sensor MHZ-19 vanishing data over time (#2659) * Fix KNX reconnection issue (#2679) + * Fix DST and STD time for Southern Hemisphere (#2684, #2714) + * Add SetOption26 to enforce use of indexes even when only one relay is present (#1055) * Add Portuguese in Brazil language file * Add rule state test for On/Off in addition to 0/1 (#2613) * Add hardware serial option to MHZ-19 sensor (#2659) diff --git a/sonoff/settings.h b/sonoff/settings.h index 313ca3c6f..bedf60094 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -51,7 +51,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t rules_enabled : 1; // bit 23 (v5.12.0j) uint32_t rules_once : 1; // bit 24 (v5.12.0k) uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) KNX - uint32_t spare26 : 1; + uint32_t device_index_enable : 1; // bit 26 (v5.13.1a) uint32_t spare27 : 1; uint32_t spare28 : 1; uint32_t spare29 : 1; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 11c9cb29c..3e879b58c 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -376,6 +376,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) byte jsflg = 0; byte lines = 1; uint8_t grpflg = 0; +// uint8_t user_append_index = 0; uint16_t i = 0; uint16_t index; uint32_t address; @@ -407,7 +408,10 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) while (isdigit(type[i-1])) { i--; } - if (i < strlen(type)) index = atoi(type +i); + if (i < strlen(type)) { + index = atoi(type +i); +// user_append_index = 1; + } type[i] = '\0'; } @@ -478,6 +482,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } else if ((CMND_POWER == command_code) && (index > 0) && (index <= devices_present)) { if ((payload < 0) || (payload > 4)) payload = 9; +// Settings.flag.device_index_enable = user_append_index; ExecuteCommandPower(index, payload); fallback_topic_flag = 0; return; @@ -553,7 +558,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) XsnsCall(FUNC_COMMAND); // if (!XsnsCall(FUNC_COMMAND)) type = NULL; } - else if ((CMND_SETOPTION == command_code) && ((index <= 21) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) { + else if ((CMND_SETOPTION == command_code) && ((index <= 26) || ((index > 31) && (index <= P_MAX_PARAM8 + 31)))) { if (index <= 31) { ptype = 0; // SetOption0 .. 31 } else { @@ -585,6 +590,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) case 21: // no_power_on_check // case 22: // mqtt_serial - use commands SerialSend and SerialLog // case 23: // rules_enabled - use command Rule +// case 24: // rules_once +// case 25: // knx_enabled + case 26: // device_index_enable bitWrite(Settings.flag.data, index, payload); } if (12 == index) { // stop_flash_rotate @@ -1367,7 +1375,7 @@ void MqttShowState() if (i == light_device -1) { LightState(1); } else { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":\"%s\""), mqtt_data, GetPowerDevice(stemp1, i +1, sizeof(stemp1)), GetStateText(bitRead(power, i))); + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":\"%s\""), mqtt_data, GetPowerDevice(stemp1, i +1, sizeof(stemp1), Settings.flag.device_index_enable), GetStateText(bitRead(power, i))); } } diff --git a/sonoff/xdrv_00_mqtt.ino b/sonoff/xdrv_00_mqtt.ino index d90ae2591..c3eda47d2 100644 --- a/sonoff/xdrv_00_mqtt.ino +++ b/sonoff/xdrv_00_mqtt.ino @@ -280,10 +280,9 @@ void MqttPublishPowerState(byte device) char stopic[TOPSZ]; char scommand[33]; - if ((device < 1) || (device > devices_present)) { - device = 1; - } - GetPowerDevice(scommand, device, sizeof(scommand)); + if ((device < 1) || (device > devices_present)) { device = 1; } + GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable); + GetTopic_P(stopic, STAT, mqtt_topic, (Settings.flag.mqtt_response) ? scommand : S_RSLT_RESULT); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, scommand, GetStateText(bitRead(power, device -1))); MqttPublish(stopic); @@ -301,7 +300,7 @@ void MqttPublishPowerBlinkState(byte device) device = 1; } snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"" D_JSON_BLINK " %s\"}"), - GetPowerDevice(scommand, device, sizeof(scommand)), GetStateText(bitRead(blink_mask, device -1))); + GetPowerDevice(scommand, device, sizeof(scommand), Settings.flag.device_index_enable), GetStateText(bitRead(blink_mask, device -1))); MqttPublishPrefixTopic_P(RESULT_OR_STAT, S_RSLT_POWER); } @@ -723,7 +722,7 @@ bool MqttCommand() if ((payload >= 0) && (payload <= 1)) { if (!payload) { for(i = 1; i <= devices_present; i++) { // Clear MQTT retain in broker - GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand))); + GetTopic_P(stemp1, STAT, mqtt_topic, GetPowerDevice(scommand, i, sizeof(scommand), Settings.flag.device_index_enable)); mqtt_data[0] = '\0'; MqttPublish(stemp1, Settings.flag.mqtt_power_retain); } @@ -744,7 +743,7 @@ bool MqttCommand() snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, GetStateText(Settings.flag.mqtt_sensor_retain)); } else serviced = false; // Unknown command - + return serviced; } diff --git a/sonoff/xdrv_01_light.ino b/sonoff/xdrv_01_light.ino index a72ada7f6..6ea7ca7e9 100644 --- a/sonoff/xdrv_01_light.ino +++ b/sonoff/xdrv_01_light.ino @@ -545,7 +545,7 @@ void LightState(uint8_t append) } else { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{")); } - GetPowerDevice(scommand, light_device, sizeof(scommand)); + GetPowerDevice(scommand, light_device, sizeof(scommand), Settings.flag.device_index_enable); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%s\":\"%s\",\"" D_CMND_DIMMER "\":%d"), mqtt_data, scommand, GetStateText(light_power), Settings.light_dimmer); if (light_subtype > LST_SINGLE) { diff --git a/sonoff/xdrv_07_home_assistant.ino b/sonoff/xdrv_07_home_assistant.ino index 3f8e001be..657f8d5b7 100644 --- a/sonoff/xdrv_07_home_assistant.ino +++ b/sonoff/xdrv_07_home_assistant.ino @@ -96,7 +96,7 @@ void HAssDiscoverRelay() } else { snprintf_P(name, sizeof(name), Settings.friendlyname[i -1]); } - GetPowerDevice(value_template, i, sizeof(value_template)); + GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable); GetTopic_P(command_topic, CMND, mqtt_topic, value_template); GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT); GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT); @@ -171,7 +171,7 @@ void HAssDiscoverButton() } else { snprintf_P(name, sizeof(name), PSTR("%s BTN"), Settings.friendlyname[button_index]); } - GetPowerDevice(value_template, button_index+1, sizeof(value_template)); + GetPowerDevice(value_template, button_index+1, sizeof(value_template), Settings.flag.device_index_enable); GetTopic_P(state_topic, CMND, key_topic, value_template); // State of button is sent as CMND TOGGLE GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT); snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON, name, state_topic, Settings.state_text[2], availability_topic); diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index fa71d0a12..076e7333d 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -248,6 +248,9 @@ bool RulesProcess() delay(0); // Prohibit possible loop software watchdog +//snprintf_P(log_data, sizeof(log_data), PSTR("RUL: Event = %s, Rule = %s"), mqtt_data, Settings.rules); +//AddLog(LOG_LEVEL_DEBUG); + if (!Settings.flag.rules_enabled) { return serviced; } // Not enabled if (!strlen(Settings.rules)) { return serviced; } // No rules @@ -274,12 +277,12 @@ bool RulesProcess() if (plen == -1) { return serviced; } // Bad syntax - No endon String commands = rules.substring(pevt +4, plen); // "Backlog Dimmer 10;Color 100000" plen += 6; - -//snprintf_P(log_data, sizeof(log_data), PSTR("RUL: Trigger |%s|, Commands |%s|"), event_trigger.c_str(), commands.c_str()); -//AddLog(LOG_LEVEL_DEBUG); - rules_event_value = ""; String event = event_saved; + +//snprintf_P(log_data, sizeof(log_data), PSTR("RUL: Event |%s|, Rule |%s|, Command(s) |%s|"), event.c_str(), event_trigger.c_str(), commands.c_str()); +//AddLog(LOG_LEVEL_DEBUG); + if (RulesRuleMatch(event, event_trigger)) { commands.trim(); String ucommand = commands; diff --git a/sonoff/xsns_24_si1145.ino b/sonoff/xsns_24_si1145.ino index e09f95398..5ddd713d8 100644 --- a/sonoff/xsns_24_si1145.ino +++ b/sonoff/xsns_24_si1145.ino @@ -210,6 +210,11 @@ uint8_t Si1145WriteParamData(uint8_t p, uint8_t v) /********************************************************************************************/ +bool Si1145Present() +{ + return (Si1145ReadByte(SI114X_PART_ID) == 0X45); +} + void Si1145Reset() { Si1145WriteByte(SI114X_MEAS_RATE0, 0); @@ -234,19 +239,19 @@ void Si1145DeInit() Si1145WriteByte(SI114X_UCOEFF1, 0x89); Si1145WriteByte(SI114X_UCOEFF2, 0x02); Si1145WriteByte(SI114X_UCOEFF3, 0x00); - Si1145WriteParamData(SI114X_CHLIST, SI114X_CHLIST_ENUV |SI114X_CHLIST_ENALSIR | SI114X_CHLIST_ENALSVIS |SI114X_CHLIST_ENPS1); + Si1145WriteParamData(SI114X_CHLIST, SI114X_CHLIST_ENUV | SI114X_CHLIST_ENALSIR | SI114X_CHLIST_ENALSVIS | SI114X_CHLIST_ENPS1); // //set LED1 CURRENT(22.4mA)(It is a normal value for many LED) // Si1145WriteParamData(SI114X_PS1_ADCMUX, SI114X_ADCMUX_LARGE_IR); Si1145WriteByte(SI114X_PS_LED21, SI114X_LED_CURRENT_22MA); - Si1145WriteParamData(SI114X_PSLED12_SELECT, SI114X_PSLED12_SELECT_PS1_LED1); // + Si1145WriteParamData(SI114X_PSLED12_SELECT, SI114X_PSLED12_SELECT_PS1_LED1); // //PS ADC SETTING // Si1145WriteParamData(SI114X_PS_ADC_GAIN, SI114X_ADC_GAIN_DIV1); Si1145WriteParamData(SI114X_PS_ADC_COUNTER, SI114X_ADC_COUNTER_511ADCCLK); - Si1145WriteParamData(SI114X_PS_ADC_MISC, SI114X_ADC_MISC_HIGHRANGE|SI114X_ADC_MISC_ADC_RAWADC); + Si1145WriteParamData(SI114X_PS_ADC_MISC, SI114X_ADC_MISC_HIGHRANGE | SI114X_ADC_MISC_ADC_RAWADC); // //VIS ADC SETTING // @@ -273,7 +278,7 @@ void Si1145DeInit() boolean Si1145Begin() { - if (Si1145ReadByte(SI114X_PART_ID) != 0X45) { return false; } + if (!Si1145Present()) { return false; } Si1145Reset(); Si1145DeInit(); @@ -320,7 +325,7 @@ const char HTTP_SNS_SI1145[] PROGMEM = "%s" void Si1145Show(boolean json) { - if (si1145_type) { + if (si1145_type && Si1145Present()) { uint16_t visible = Si1145ReadVisible(); uint16_t infrared = Si1145ReadIR(); uint16_t uvindex = Si1145ReadUV(); @@ -335,6 +340,8 @@ void Si1145Show(boolean json) snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_SI1145, mqtt_data, visible, infrared, uvindex /100, uvindex %100); #endif } + } else { + si1145_type = 0; } } From 42cd1b97dcb5f9f16dd910eb2a6922f68acf7869 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 13 May 2018 18:44:35 +0200 Subject: [PATCH 16/19] Prep for user entry STD/DST Prep for user entry STD/DST (#2721) --- sonoff/settings.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index bedf60094..27a094403 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -89,6 +89,17 @@ typedef union { }; } SysBitfield2; +typedef union { + uint16_t data; + struct { + uint32_t hemis : 1; // bit 0 = 0=Northern, 1=Southern Hemisphere (=Opposite DST/STD) + uint32_t week : 3; // bits 1 - 3 = 0=Last week of the month, 1=First, 2=Second, 3=Third, 4=Fourth + uint32_t month : 4; // bits 4 - 7 = 1=Jan, 2=Feb, ... 12=Dec + uint32_t dow : 3; // bits 8 - 10 = day of week, 1=Sun, 2=Mon, ... 7=Sat + uint32_t hour : 5; // bits 11 - 15 = 0-23 + }; +} TimeRule; + typedef union { uint32_t data; struct { @@ -148,9 +159,8 @@ struct SYSCFG { uint8_t display_address[8]; // 2D8 uint8_t display_dimmer; // 2E0 uint8_t display_size; // 2E1 - - uint8_t free_2E2[4]; // 2E2 - + TimeRule std_flags; // 2E2 + int16_t std_offset; // 2E4 offset from UTC in minutes uint16_t pwm_frequency; // 2E6 power_t power; // 2E8 uint16_t pwm_value[MAX_PWMS]; // 2EC @@ -234,9 +244,7 @@ struct SYSCFG { char ntp_server[3][33]; // 4CE byte ina219_mode; // 531 uint16_t pulse_timer[MAX_PULSETIMERS]; // 532 - - byte free_542[2]; // 542 - + TimeRule dst_flags; // 542 uint32_t ip_address[4]; // 544 unsigned long energy_kWhtotal; // 554 char mqtt_fulltopic[100]; // 558 @@ -246,8 +254,9 @@ struct SYSCFG { uint16_t pulse_counter_debounce; // 5D2 uint8_t rf_code[17][9]; // 5D4 - byte free_66d[3]; // 66D + byte free_66d[1]; // 66D + int16_t dst_offset; // 66E Timer timer[MAX_TIMERS]; // 670 int latitude; // 6B0 int longitude; // 6B4 From 137ac826543f2205e13bc77a8e609c4ad56ccd90 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 13 May 2018 18:48:14 +0200 Subject: [PATCH 17/19] Revert "Prep for user entry STD/DST" This reverts commit 42cd1b97dcb5f9f16dd910eb2a6922f68acf7869. --- sonoff/settings.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index 27a094403..bedf60094 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -89,17 +89,6 @@ typedef union { }; } SysBitfield2; -typedef union { - uint16_t data; - struct { - uint32_t hemis : 1; // bit 0 = 0=Northern, 1=Southern Hemisphere (=Opposite DST/STD) - uint32_t week : 3; // bits 1 - 3 = 0=Last week of the month, 1=First, 2=Second, 3=Third, 4=Fourth - uint32_t month : 4; // bits 4 - 7 = 1=Jan, 2=Feb, ... 12=Dec - uint32_t dow : 3; // bits 8 - 10 = day of week, 1=Sun, 2=Mon, ... 7=Sat - uint32_t hour : 5; // bits 11 - 15 = 0-23 - }; -} TimeRule; - typedef union { uint32_t data; struct { @@ -159,8 +148,9 @@ struct SYSCFG { uint8_t display_address[8]; // 2D8 uint8_t display_dimmer; // 2E0 uint8_t display_size; // 2E1 - TimeRule std_flags; // 2E2 - int16_t std_offset; // 2E4 offset from UTC in minutes + + uint8_t free_2E2[4]; // 2E2 + uint16_t pwm_frequency; // 2E6 power_t power; // 2E8 uint16_t pwm_value[MAX_PWMS]; // 2EC @@ -244,7 +234,9 @@ struct SYSCFG { char ntp_server[3][33]; // 4CE byte ina219_mode; // 531 uint16_t pulse_timer[MAX_PULSETIMERS]; // 532 - TimeRule dst_flags; // 542 + + byte free_542[2]; // 542 + uint32_t ip_address[4]; // 544 unsigned long energy_kWhtotal; // 554 char mqtt_fulltopic[100]; // 558 @@ -254,9 +246,8 @@ struct SYSCFG { uint16_t pulse_counter_debounce; // 5D2 uint8_t rf_code[17][9]; // 5D4 - byte free_66d[1]; // 66D + byte free_66d[3]; // 66D - int16_t dst_offset; // 66E Timer timer[MAX_TIMERS]; // 670 int latitude; // 6B0 int longitude; // 6B4 From 854e0f9eb86bde9903154c81a5dd2393b483bda9 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 13 May 2018 18:54:21 +0200 Subject: [PATCH 18/19] Prep for user entry STD/DST Prep for user entry STD/DST (#2721) --- sonoff/settings.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index bedf60094..e71c6e1b1 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -89,6 +89,17 @@ typedef union { }; } SysBitfield2; +typedef union { + uint16_t data; + struct { + uint16_t hemis : 1; // bit 0 = 0=Northern, 1=Southern Hemisphere (=Opposite DST/STD) + uint16_t week : 3; // bits 1 - 3 = 0=Last week of the month, 1=First, 2=Second, 3=Third, 4=Fourth + uint16_t month : 4; // bits 4 - 7 = 1=Jan, 2=Feb, ... 12=Dec + uint16_t dow : 3; // bits 8 - 10 = day of week, 1=Sun, 2=Mon, ... 7=Sat + uint16_t hour : 5; // bits 11 - 15 = 0-23 + }; +} TimeRule; + typedef union { uint32_t data; struct { @@ -148,9 +159,8 @@ struct SYSCFG { uint8_t display_address[8]; // 2D8 uint8_t display_dimmer; // 2E0 uint8_t display_size; // 2E1 - - uint8_t free_2E2[4]; // 2E2 - + TimeRule std_flags; // 2E2 + int16_t std_offset; // 2E4 offset from UTC in minutes uint16_t pwm_frequency; // 2E6 power_t power; // 2E8 uint16_t pwm_value[MAX_PWMS]; // 2EC @@ -234,9 +244,7 @@ struct SYSCFG { char ntp_server[3][33]; // 4CE byte ina219_mode; // 531 uint16_t pulse_timer[MAX_PULSETIMERS]; // 532 - - byte free_542[2]; // 542 - + TimeRule dst_flags; // 542 uint32_t ip_address[4]; // 544 unsigned long energy_kWhtotal; // 554 char mqtt_fulltopic[100]; // 558 @@ -246,8 +254,9 @@ struct SYSCFG { uint16_t pulse_counter_debounce; // 5D2 uint8_t rf_code[17][9]; // 5D4 - byte free_66d[3]; // 66D + byte free_66d[1]; // 66D + int16_t dst_offset; // 66E Timer timer[MAX_TIMERS]; // 670 int latitude; // 6B0 int longitude; // 6B4 From 20eb04b7efbf0a88535ee0929d6e7239560fbfaa Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Sun, 13 May 2018 19:43:48 +0200 Subject: [PATCH 19/19] v5.13.1b - Prep for user entry DST/STD Prep for user entry DST/STD (#2721) --- README.md | 2 +- sonoff/_releasenotes.ino | 5 ++++- sonoff/settings.h | 13 ------------- sonoff/settings.ino | 28 +++++++++++++++++++++++++--- sonoff/sonoff.ino | 2 +- sonoff/support.ino | 16 ++++++++-------- sonoff/user_config.h | 22 ++++++++++++++++------ 7 files changed, 55 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 587a67d18..303fb872e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute! ### Development [![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota) -Current version is **5.13.1a** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. +Current version is **5.13.1b** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information. ### Quick install Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki. diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 27638c3de..fc814d10a 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,7 @@ -/* 5.13.1a +/* 5.13.1b + * Prep for user entry DST/STD (#2721) + * + * 5.13.1a * Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602) * Fix configuration restore regression from 5.13.1 * Fix compile error when ADC is enabled and Rules are disabled (#2608) diff --git a/sonoff/settings.h b/sonoff/settings.h index e71c6e1b1..6dfc4cdeb 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -298,19 +298,6 @@ struct TIME_T { unsigned long valid; } RtcTime; -struct TimeChangeRule -{ - uint8_t hemis; // 0-Northern, 1=Southern Hemisphere (=Opposite DST/STD) - uint8_t week; // 1=First, 2=Second, 3=Third, 4=Fourth, or 0=Last week of the month - uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat - uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec - uint8_t hour; // 0-23 - int offset; // offset from UTC in minutes -}; - -TimeChangeRule DaylightSavingTime = { TIME_DST }; // Daylight Saving Time -TimeChangeRule StandardTime = { TIME_STD }; // Standard Time - struct XDRVMAILBOX { uint16_t valid; uint16_t index; diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 059383d72..78a48e657 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -521,6 +521,8 @@ void SettingsDefaultSet2() Settings.latitude = (int)((double)LATITUDE * 1000000); Settings.longitude = (int)((double)LONGITUDE * 1000000); + + SettingsDefaultSet_5_13_1a(); } /********************************************************************************************/ @@ -652,6 +654,22 @@ void SettingsDefaultSet_5_10_1() Settings.display_size = 1; } +void SettingsDefaultSet_5_13_1a() +{ + Settings.dst_flags.hemis = TIME_DST_HEMISPHERE; + Settings.dst_flags.week = TIME_DST_WEEK; + Settings.dst_flags.dow = TIME_DST_DAY; + Settings.dst_flags.month = TIME_DST_MONTH; + Settings.dst_flags.hour = TIME_DST_HOUR; + Settings.dst_offset = TIME_DST_OFFSET; + Settings.std_flags.hemis = TIME_STD_HEMISPHERE; + Settings.std_flags.week = TIME_STD_WEEK; + Settings.std_flags.dow = TIME_STD_DAY; + Settings.std_flags.month = TIME_STD_MONTH; + Settings.std_flags.hour = TIME_STD_HOUR; + Settings.std_offset = TIME_STD_OFFSET; +} + /********************************************************************************************/ void SettingsDelta() @@ -852,10 +870,14 @@ void SettingsDelta() memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use } if (Settings.version < 0x050C000F) { - Settings.energy_kWhtoday /= 1000; - Settings.energy_kWhyesterday /= 1000; - RtcSettings.energy_kWhtoday /= 1000; + Settings.energy_kWhtoday /= 1000; + Settings.energy_kWhyesterday /= 1000; + RtcSettings.energy_kWhtoday /= 1000; } + if (Settings.version < 0x050D0102) { + SettingsDefaultSet_5_13_1a(); + } + Settings.version = VERSION; SettingsSave(1); } diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 3e879b58c..858ff8579 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -25,7 +25,7 @@ - Select IDE Tools - Flash Size: "1M (no SPIFFS)" ====================================================*/ -#define VERSION 0x050D0101 // 5.13.1a +#define VERSION 0x050D0102 // 5.13.1b // Location specific includes #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) diff --git a/sonoff/support.ino b/sonoff/support.ino index 84760e92b..9564f83aa 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1288,7 +1288,7 @@ uint32_t MakeTime(TIME_T &tm) return seconds; } -uint32_t RuleToTime(TimeChangeRule r, int yr) +uint32_t RuleToTime(TimeRule r, int yr) { TIME_T tm; uint32_t t; @@ -1367,8 +1367,8 @@ void RtcSecond() } BreakTime(utc_time, tmpTime); RtcTime.year = tmpTime.year + 1970; - daylight_saving_time = RuleToTime(DaylightSavingTime, RtcTime.year); - standard_time = RuleToTime(StandardTime, RtcTime.year); + daylight_saving_time = RuleToTime(Settings.dst_flags, RtcTime.year); + standard_time = RuleToTime(Settings.std_flags, RtcTime.year); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); AddLog(LOG_LEVEL_DEBUG); @@ -1389,22 +1389,22 @@ void RtcSecond() if (local_time > 1451602800) { // 2016-01-01 int32_t time_offset = Settings.timezone * SECS_PER_HOUR; if (99 == Settings.timezone) { - dstoffset = DaylightSavingTime.offset * SECS_PER_MIN; - stdoffset = StandardTime.offset * SECS_PER_MIN; - if (DaylightSavingTime.hemis) { + dstoffset = Settings.dst_offset * SECS_PER_MIN; + stdoffset = Settings.std_offset * SECS_PER_MIN; + if (Settings.dst_flags.hemis) { // Southern hemisphere if ((utc_time >= (standard_time - dstoffset)) && (utc_time < (daylight_saving_time - stdoffset))) { time_offset = stdoffset; // Standard Time } else { time_offset = dstoffset; // Daylight Saving Time - } + } } else { // Northern hemisphere if ((utc_time >= (daylight_saving_time - stdoffset)) && (utc_time < (standard_time - dstoffset))) { time_offset = dstoffset; // Daylight Saving Time } else { time_offset = stdoffset; // Standard Time - } + } } } local_time += time_offset; diff --git a/sonoff/user_config.h b/sonoff/user_config.h index 9368c6806..e06d1935a 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -129,6 +129,22 @@ #define NTP_SERVER2 "nl.pool.ntp.org" // [NtpServer2] Select second NTP server by name or IP address (5.39.184.5) #define NTP_SERVER3 "0.nl.pool.ntp.org" // [NtpServer3] Select third NTP server by name or IP address (93.94.224.67) +// -- Time - Start Daylight Saving Time and timezone offset from UTC in minutes +#define TIME_DST_HEMISPHERE North // Northern Hemisphere +#define TIME_DST_WEEK Last +#define TIME_DST_DAY Sun +#define TIME_DST_MONTH Mar // Last sunday in march +#define TIME_DST_HOUR 2 // at 02:00 +#define TIME_DST_OFFSET +120 // +120 minutes + +// -- Time - Start Standard Time and timezone offset from UTC in minutes +#define TIME_STD_HEMISPHERE North // Northern Hemisphere +#define TIME_STD_WEEK Last +#define TIME_STD_DAY Sun +#define TIME_STD_MONTH Oct // Last sunday in october +#define TIME_STD_HOUR 3 // at 03:00 +#define TIME_STD_OFFSET +60 // +60 minutes + // -- Location ------------------------------------ #define LATITUDE 48.858360 // [Latitude] Your location to be used with sunrise and sunset #define LONGITUDE 2.294442 // [Longitude] Your location to be used with sunrise and sunset @@ -223,12 +239,6 @@ #define WEBSERVER_ADVERTISE // Provide access to webserver by name .local/ #define MQTT_HOST_DISCOVERY // Find MQTT host server (overrides MQTT_HOST if found) -// -- Time - Start Daylight Saving Time and timezone offset from UTC in minutes -#define TIME_DST North, Last, Sun, Mar, 2, +120 // Northern Hemisphere, Last sunday in march at 02:00 +120 minutes - -// -- Time - Start Standard Time and timezone offset from UTC in minutes -#define TIME_STD North, Last, Sun, Oct, 3, +60 // Northern Hemisphere, Last sunday in october 02:00 +60 minutes - // -- Time ---------------------------------------- #define USE_TIMERS // Add support for up to 16 timers (+2k2 code) #define USE_TIMERS_WEB // Add timer webpage support (+4k5 code)