From 6757d9731a58db59609de709980648eec7ede419 Mon Sep 17 00:00:00 2001 From: Federico Leoni Date: Thu, 23 Jan 2020 19:17:15 -0300 Subject: [PATCH 1/2] new ADC Range definition --- tasmota/language/bg-BG.h | 1 + tasmota/language/cs-CZ.h | 1 + tasmota/language/de-DE.h | 1 + tasmota/language/el-GR.h | 1 + tasmota/language/en-GB.h | 1 + tasmota/language/es-ES.h | 1 + tasmota/language/fr-FR.h | 1 + tasmota/language/he-HE.h | 1 + tasmota/language/hu-HU.h | 1 + tasmota/language/it-IT.h | 1 + tasmota/language/ko-KO.h | 1 + tasmota/language/nl-NL.h | 1 + tasmota/language/pl-PL.h | 1 + tasmota/language/pt-BR.h | 1 + tasmota/language/pt-PT.h | 1 + tasmota/language/ru-RU.h | 1 + tasmota/language/sk-SK.h | 1 + tasmota/language/sv-SE.h | 1 + tasmota/language/tr-TR.h | 1 + tasmota/language/uk-UA.h | 1 + tasmota/language/zh-CN.h | 1 + tasmota/language/zh-TW.h | 1 + 22 files changed, 22 insertions(+) diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index 8f1c82bc3..e89903cee 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Размер на програмата" #define D_PROJECT "Проект" #define D_RAIN "Дъжд" +#define D_RANGE "Range" #define D_RECEIVED "Получено" #define D_RESTART "Рестарт" #define D_RESTARTING "Рестартиране" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index 3b11a7ebc..d7e8e188e 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Velikost programu" #define D_PROJECT "Projekt" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Přijatý" #define D_RESTART "Restart" #define D_RESTARTING "Restartování" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index e09278526..b710e2975 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Ben. Flash Speicher" #define D_PROJECT "Projekt" #define D_RAIN "Regen" +#define D_RANGE "Range" #define D_RECEIVED "erhalten" #define D_RESTART "Neustart" #define D_RESTARTING "starte neu" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index 070267215..1c76125fa 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Μέγεθος προγράμματος" #define D_PROJECT "Έργο" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Ελήφθη" #define D_RESTART "Επανεκκίνηση" #define D_RESTARTING "Επανεκκινεί" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index 5121a7471..b994b0409 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Program Size" #define D_PROJECT "Project" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Received" #define D_RESTART "Restart" #define D_RESTARTING "Restarting" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 8ff2b415f..6b8d60d01 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Tamaño Programa" #define D_PROJECT "Proyecto" #define D_RAIN "Lluvia" +#define D_RANGE "Range" #define D_RECEIVED "Recibido" #define D_RESTART "Reiniciar" #define D_RESTARTING "Reiniciando" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index 3829a8681..4a861bd82 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Taille programme" #define D_PROJECT "Projet" #define D_RAIN "Pluie" +#define D_RANGE "Range" #define D_RECEIVED "Reçu" #define D_RESTART "Redémarrage" #define D_RESTARTING "Redémarre" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index d0c5e364b..166c5c735 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "גודל תוכנית" #define D_PROJECT "פרויקט" #define D_RAIN "גשם" +#define D_RANGE "Range" #define D_RECEIVED "התקבל" #define D_RESTART "איתחול" #define D_RESTARTING "הפעלה מחדש" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 70f219c98..e1cec813a 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Program méret" #define D_PROJECT "Projekt" #define D_RAIN "Eső" +#define D_RANGE "Range" #define D_RECEIVED "Érkezett" #define D_RESTART "Újraindítás" #define D_RESTARTING "Újraindítás" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 73830deca..d7ec1e0e5 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Dimensione Programma" #define D_PROJECT "Progetto" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Ricevuto" #define D_RESTART "Riavvio" #define D_RESTARTING "Riavviando" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index 328acc568..55b8dba97 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "프로그램 용량" #define D_PROJECT "프로젝트" #define D_RAIN "비" +#define D_RANGE "Range" #define D_RECEIVED "받음" #define D_RESTART "재시작" #define D_RESTARTING "재시작 중.." diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index 3d5ec8b7d..c0b5a9862 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Programma Grootte" #define D_PROJECT "Project" #define D_RAIN "Regen" +#define D_RANGE "Range" #define D_RECEIVED "Ontvangen" #define D_RESTART "Herstart" #define D_RESTARTING "Herstarten" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index 63fe6fcad..237bc66f1 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Rozmiar programu" #define D_PROJECT "Projekt" #define D_RAIN "Deszcz" +#define D_RANGE "Range" #define D_RECEIVED "Otrzymany" #define D_RESTART "Restart" #define D_RESTARTING "Restartowanie" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index da6e8ca1b..c56262b11 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Tamanho do programa" #define D_PROJECT "Projeto" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Recebido" #define D_RESTART "Reiniciar" #define D_RESTARTING "Reiniciando" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index 47137b90b..be9c6d493 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Tamanho do Programa" #define D_PROJECT "Projeto" #define D_RAIN "Chuva" +#define D_RANGE "Range" #define D_RECEIVED "Recebido" #define D_RESTART "Reiniciar" #define D_RESTARTING "A reiniciar" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index 31c295059..57dfa40e1 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Размер программы " #define D_PROJECT "Проект" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Получено" #define D_RESTART "Перезапуск" #define D_RESTARTING "Перезапуск" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index 89f3d7353..ee7afb49f 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Veľkosť programu" #define D_PROJECT "Projekt" #define D_RAIN "Dážď" +#define D_RANGE "Range" #define D_RECEIVED "Prijatý" #define D_RESTART "Reštart" #define D_RESTARTING "Reštartuje sa" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index ddc2307b4..351bf6dbb 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Programstorlek" #define D_PROJECT "Projekt" #define D_RAIN "Regn" +#define D_RANGE "Range" #define D_RECEIVED "Mottagen" #define D_RESTART "Omstart" #define D_RESTARTING "Startar om" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index 38f125d6c..fced504d3 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Yazılım Boyutu" #define D_PROJECT "Proje" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "Alınan" #define D_RESTART "Yeniden Başlat" #define D_RESTARTING "Yeniden Başlatılıyor" diff --git a/tasmota/language/uk-UA.h b/tasmota/language/uk-UA.h index b634935cf..81d02a8b3 100644 --- a/tasmota/language/uk-UA.h +++ b/tasmota/language/uk-UA.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "Розмір програми" #define D_PROJECT "Проект" #define D_RAIN "Дощ" +#define D_RANGE "Range" #define D_RECEIVED "Отримано" #define D_RESTART "Перезавантаження" #define D_RESTARTING "Перезавантаження" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index 97b41a29a..12c368cd3 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "固件大小" #define D_PROJECT "项目:" #define D_RAIN "降水量" +#define D_RANGE "Range" #define D_RECEIVED "已接收" #define D_RESTART "重启" #define D_RESTARTING "正在重启" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index 1fd30e6e4..7c1b2e3fb 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -137,6 +137,7 @@ #define D_PROGRAM_SIZE "韌體大小" #define D_PROJECT "項目:" #define D_RAIN "Rain" +#define D_RANGE "Range" #define D_RECEIVED "已接收" #define D_RESTART "重啟" #define D_RESTARTING "正在重啟" From 26755202c7336ac6256646591c4397b3bea93e2b Mon Sep 17 00:00:00 2001 From: Federico Leoni Date: Thu, 23 Jan 2020 19:21:49 -0300 Subject: [PATCH 2/2] New ADC Range --- tasmota/i18n.h | 4 ++++ tasmota/tasmota_template.h | 4 ++-- tasmota/xsns_02_analog.ino | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 20207bcb4..6437bc2dc 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -114,6 +114,7 @@ #define D_JSON_ACTIVE_POWERUSAGE "ActivePower" #define D_JSON_APPARENT_POWERUSAGE "ApparentPower" #define D_JSON_REACTIVE_POWERUSAGE "ReactivePower" +#define D_JSON_RANGE "Range" #define D_JSON_PRESSURE "Pressure" #define D_JSON_PRESSUREATSEALEVEL "SeaPressure" #define D_JSON_PRESSURE_UNIT "PressureUnit" @@ -605,6 +606,7 @@ const char JSON_SNS_TEMPHUM[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s, const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"; const char JSON_SNS_MOISTURE[] PROGMEM = ",\"%s\":{\"" D_JSON_MOISTURE "\":%d}"; +const char JSON_SNS_RANGE[] PROGMEM = ",\"%s\":{\"" D_JSON_RANGE "\":%d}"; const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}"; @@ -636,6 +638,8 @@ const char HTTP_SNS_CO2EAVG[] PROGMEM = "{s}%s " D_ECO2 "{m}%d " D_UNIT_PARTS_PE const char HTTP_SNS_GALLONS[] PROGMEM = "{s}%s " D_TOTAL_USAGE "{m}%s " D_UNIT_GALLONS " {e}"; const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{m}%s " D_UNIT_GALLONS_PER_MIN" {e}"; const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d %%{e}"; +const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d %%{e}"; + const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}"; const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}"; diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 9bb98ce6e..f041620c6 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -311,7 +311,7 @@ enum UserSelectableAdc0 { ADC0_LIGHT, // Light sensor ADC0_BUTTON, // Button ADC0_BUTTON_INV, - ADC0_MOIST, // Moisture + ADC0_RANGE, // Range ADC0_CT_POWER, // Current // ADC0_SWITCH, // Switch // ADC0_SWITCH_INV, @@ -328,7 +328,7 @@ const char kAdc0Names[] PROGMEM = D_SENSOR_NONE "|" D_ANALOG_INPUT "|" D_TEMPERATURE "|" D_LIGHT "|" D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|" - D_MOISTURE "|" + D_RANGE "|" D_CT_POWER "|" // D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|" ; diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index 93df3d5e1..038da9fa5 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -85,8 +85,8 @@ void AdcInit(void) Settings.adc_param2 = ANALOG_LDR_LUX_CALC_SCALAR; Settings.adc_param3 = ANALOG_LDR_LUX_CALC_EXPONENT * 10000; } - else if (ADC0_MOIST == my_adc0) { - Settings.adc_param_type = ADC0_MOIST; + else if (ADC0_RANGE == my_adc0) { + Settings.adc_param_type = ADC0_RANGE; Settings.adc_param1 = 0; Settings.adc_param2 = 1023; Settings.adc_param3 = 0; @@ -145,14 +145,14 @@ uint16_t AdcGetLux(void) return (uint16_t)ldrLux; } -uint16_t AdcGetMoist(void) +uint16_t AdcGetRange(void) { - // formula for calibration: value, fromLow, fromHigh, toHigh, toLow - // Example: 632, 0, 1023, 0, 100 - // int( ( ( ( - ) / ( - ) ) * ( - ) ) + ) + // formula for calibration: value, fromLow, fromHigh, toLow, toHigh + // Example: 514, 632, 236, 0, 100 + // int( (( - ) / ( - ) ) * ( - ) ) + ) int adc = AdcRead(2); - double amoist = ( ((double)Settings.adc_param2 - (double)adc) / ( ((double)Settings.adc_param2 - (double)Settings.adc_param1)) * ((double)Settings.adc_param3 - (double)Settings.adc_param4) + (double)Settings.adc_param4 ); - return (uint16_t)amoist; + double adcrange = ( ((double)Settings.adc_param2 - (double)adc) / ( ((double)Settings.adc_param2 - (double)Settings.adc_param1)) * ((double)Settings.adc_param3 - (double)Settings.adc_param4) + (double)Settings.adc_param4 ); + return (uint16_t)adcrange; } void AdcGetCurrentPower(uint8_t factor) @@ -253,14 +253,14 @@ void AdcShow(bool json) } } - else if (ADC0_MOIST == my_adc0) { - uint16_t adc_moist = AdcGetMoist(); + else if (ADC0_RANGE == my_adc0) { + uint16_t adc_range = AdcGetRange(); if (json) { - ResponseAppend_P(JSON_SNS_MOISTURE, "ANALOG", adc_moist); + ResponseAppend_P(JSON_SNS_RANGE, "ANALOG", adc_range); #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_MOISTURE, "", adc_moist); + WSContentSend_PD(HTTP_SNS_RANGE, "", adc_range); #endif // USE_WEBSERVER } } @@ -340,7 +340,7 @@ void CmndAdcParam(void) if (XdrvMailbox.data_len) { if ((ADC0_TEMP == XdrvMailbox.payload) || (ADC0_LIGHT == XdrvMailbox.payload) || - (ADC0_MOIST == XdrvMailbox.payload) || + (ADC0_RANGE == XdrvMailbox.payload) || (ADC0_CT_POWER == XdrvMailbox.payload)) { if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry char sub_string[XdrvMailbox.data_len +1]; @@ -350,7 +350,7 @@ void CmndAdcParam(void) Settings.adc_param_type = XdrvMailbox.payload; Settings.adc_param1 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.adc_param2 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 3), nullptr, 10); - if (ADC0_MOIST == XdrvMailbox.payload) { + if (ADC0_RANGE == XdrvMailbox.payload) { Settings.adc_param3 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 4), nullptr, 10)); Settings.adc_param4 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 5), nullptr, 10)); } else { @@ -375,7 +375,7 @@ void CmndAdcParam(void) // AdcParam Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d"), Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2); - if (ADC0_MOIST == my_adc0) { + if (ADC0_RANGE == my_adc0) { ResponseAppend_P(PSTR(",%d,%d"), Settings.adc_param3, Settings.adc_param4); } else { int value = Settings.adc_param3; @@ -407,7 +407,7 @@ bool Xsns02(uint8_t function) if ((ADC0_INPUT == my_adc0) || (ADC0_TEMP == my_adc0) || (ADC0_LIGHT == my_adc0) || - (ADC0_MOIST == my_adc0) || + (ADC0_RANGE == my_adc0) || (ADC0_CT_POWER == my_adc0)) { switch (function) { #ifdef USE_RULES