diff --git a/tasmota/support.ino b/tasmota/support.ino index e23b4519b..e94170759 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1142,6 +1142,27 @@ void TemplateConvert(uint8_t template8[], uint16_t template16[]) { template16[i] = GpioConvert(template8[i]); } template16[(sizeof(mytmplt) / 2) -2] = Adc0Convert(template8[sizeof(mytmplt8285) -1]); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FNC: TemplateConvert")); + AddLogBuffer(LOG_LEVEL_DEBUG, template8, sizeof(mytmplt8285)); + AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)template16, sizeof(mytmplt) / 2, 2); +} + +void ConvertGpios(void) { + if (Settings.user_template8.flag != 255) { + // Convert 8-bit user template + TemplateConvert((uint8_t*)&Settings.user_template8, (uint16_t*)&Settings.user_template); + Settings.user_template8.flag = 255; + + for (uint32_t i = 0; i < sizeof(Settings.my_gp8.io); i++) { + Settings.my_gp.io[i] = GpioConvert(Settings.my_gp8.io[i]); + } + Settings.my_gp.io[(sizeof(myio) / 2) -1] = Adc0Convert(Settings.my_adc0); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FNC: ConvertGpios")); + AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&Settings.my_gp8.io, sizeof(myio8)); + AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t *)&Settings.my_gp.io, sizeof(myio) / 2, 2); + } } #endif // ESP8266 @@ -1247,28 +1268,29 @@ void GetInternalTemplate(void* ptr, uint32_t module, uint32_t option) { memcpy_P(&template8, &kModules8285[module_template - TMP_WEMOS], sizeof(template8)); } -// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&template8, sizeof(mytmplt)); +// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&template8, sizeof(mytmplt8285)); // template16 = GPIO 0,1,2,3,4,5,9,10,12,13,14,15,16,Adc,Flg uint16_t template16[(sizeof(mytmplt) / 2)] = { GPIO_NONE }; TemplateConvert(template8, template16); uint32_t index = 0; - uint32_t size = sizeof(mycfgio); // template16[module_template].gp + uint32_t size = sizeof(mycfgio); // template16[module_template].gp switch (option) { case 2: { - index = sizeof(template16) -2; // template16[module_template].flag + index = (sizeof(mytmplt) / 2) -1; // template16[module_template].flag size = 2; break; } case 3: { - size = sizeof(template16); // template16[module_template] + size = sizeof(mytmplt); // template16[module_template] break; } } memcpy(ptr, &template16[index], size); -// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)ptr, size); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FNC: GetInternalTemplate option %d"), option); + AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t *)ptr, size / 2, 2); } #endif // ESP8266 @@ -1356,7 +1378,7 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio) // if (!is_8285 && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's if ((WEMOS == Settings.module) && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's - if ((pin == 9) || (pin == 10)) { + if ((9 == pin) || (10 == pin)) { return GPIO_NONE; // Disable possible flash GPIO9 and GPIO10 } } @@ -1366,6 +1388,11 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio) bool ValidGPIO(uint32_t pin, uint32_t gpio) { +#ifdef ESP8266 +#ifdef USE_ADC_VCC + if (17 == pin) { return false; } // ADC0 = GPIO17 +#endif +#endif return (GPIO_USER == ValidPin(pin, BGPIO(gpio))); // Only allow GPIO_USER pins } @@ -1465,6 +1492,9 @@ bool JsonTemplate(const char* dataBuf) if (obj[D_JSON_GPIO].success()) { #ifdef ESP8266 if (!obj[D_JSON_GPIO][13].success()) { // Old template + + AddLog_P(LOG_LEVEL_DEBUG, PSTR("TPL: Converting template ...")); + uint8_t template8[sizeof(mytmplt8285)] = { GPIO_NONE }; for (uint32_t i = 0; i < ARRAY_SIZE(template8) -1; i++) { template8[i] = obj[D_JSON_GPIO][i] | 0; diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index c2979fccf..303de23ba 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -90,16 +90,14 @@ void ButtonInit(void) Button.present++; pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); } -/* #ifdef ESP8266 #ifndef USE_ADC_VCC - else if ((99 == Button.adc) && ((ADC0_BUTTON == my_adc0) || (ADC0_BUTTON_INV == my_adc0))) { + else if ((99 == Button.adc) && AdcButtonPresent(0)) { Button.present++; Button.adc = i; } #endif // USE_ADC_VCC #endif // ESP8266 -*/ } } @@ -169,14 +167,7 @@ void ButtonHandler(void) #ifndef USE_ADC_VCC if (Button.adc == button_index) { button_present = 1; -/* - if (ADC0_BUTTON_INV == my_adc0) { - button = (AdcRead(1) < 128); - } - else if (ADC0_BUTTON == my_adc0) { - button = (AdcRead(1) > 128); - } -*/ + button = AdcGetButton(0); } #endif // USE_ADC_VCC #else // ESP32 diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 43e4ce548..4812ac788 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1477,11 +1477,7 @@ void GpioInit(void) // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: Used GPIOs %d"), GPIO_SENSOR_END); #ifdef ESP8266 - if (Settings.user_template8.flag != 255) { - // Convert 8-bit user template - TemplateConvert((uint8_t*)&Settings.user_template8, (uint16_t*)&Settings.user_template); - Settings.user_template8.flag = 255; - } + ConvertGpios(); #endif // ESP8266 for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index da59989cc..e587a4a7e 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -596,19 +596,6 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_ETH_PHY_MDC), AGPIO(GPIO_ETH_PHY_MDIO), // Ethernet #endif -#endif // ESP32 - -#ifdef USE_ADC -#ifdef ESP8266 - AGPIO(GPIO_ADC_INPUT), // Analog inputs - AGPIO(GPIO_ADC_TEMP), // Thermistor - AGPIO(GPIO_ADC_LIGHT), // Light sensor - AGPIO(GPIO_ADC_BUTTON), // Button - AGPIO(GPIO_ADC_BUTTON_INV), - AGPIO(GPIO_ADC_RANGE), // Range - AGPIO(GPIO_ADC_CT_POWER), // Current - AGPIO(GPIO_ADC_JOY), // Joystick -#else // ESP32 AGPIO(GPIO_ADC_INPUT) + MAX_ADCS, // Analog inputs AGPIO(GPIO_ADC_TEMP) + MAX_ADCS, // Thermistor AGPIO(GPIO_ADC_LIGHT) + MAX_ADCS, // Light sensor @@ -617,10 +604,23 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_ADC_RANGE) + MAX_ADCS, // Range AGPIO(GPIO_ADC_CT_POWER) + MAX_ADCS, // Current AGPIO(GPIO_ADC_JOY) + MAX_ADCS, // Joystick -#endif // ESP8266 or ESP32 -#endif // USE_ADC +#endif // ESP32 }; +#ifdef ESP8266 +const uint16_t kAdcNiceList[] PROGMEM = { + GPIO_NONE, // Not used + AGPIO(GPIO_ADC_INPUT), // Analog inputs + AGPIO(GPIO_ADC_TEMP), // Thermistor + AGPIO(GPIO_ADC_LIGHT), // Light sensor + AGPIO(GPIO_ADC_BUTTON), // Button + AGPIO(GPIO_ADC_BUTTON_INV), + AGPIO(GPIO_ADC_RANGE), // Range + AGPIO(GPIO_ADC_CT_POWER), // Current + AGPIO(GPIO_ADC_JOY), // Joystick +}; +#endif // ESP8266 + /*********************************************************************************************\ * ATTENTION: No user changeable features beyond this point - do not add templates !!! \*********************************************************************************************/ diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index dda6c9a73..b73a264e5 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -486,13 +486,14 @@ const char HTTP_SCRIPT_TEMPLATE2[] PROGMEM = "if(8==i){j=12;}" "sk(g[i],j);" // Set GPIO "j++;" - "}" - "g=o.shift();"; // FLAG + "}"; +// "g=o.shift();"; // FLAG const char HTTP_SCRIPT_TEMPLATE3[] PROGMEM = "\";" - "sk(g&15," STR(ADC0_PIN) ");" // Set ADC0 - "g>>=4;"; + "sk(g[13]," STR(ADC0_PIN) ");"; // Set ADC0 +// "g>>=4;"; const char HTTP_SCRIPT_TEMPLATE4[] PROGMEM = + "g=o.shift();" // FLAG "for(i=0;i<" STR(GPIO_FLAG_USED) ";i++){" "p=(g>>i)&1;" "eb('c'+i).checked=p;" // Set FLAG checkboxes @@ -1760,16 +1761,19 @@ void HandleTemplateConfiguration(void) WSContentSend_P(HTTP_SCRIPT_TEMPLATE2); -//#ifdef ESP8266 -// WSContentSend_P(PSTR("os=\"")); -// for (uint32_t i = 0; i < ADC0_END; i++) { // FLAG: }2'0'>None (0)}3}2'17'>Analog (17)}3... -// if (1 == i) { -// WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, ADC0_USER, D_SENSOR_USER, ADC0_USER); // }2'15'>User (15)}3 -// } +#ifdef ESP8266 + WSContentSend_P(PSTR("os=\"")); + for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { // FLAG: }2'0'>None}3}2'17'>Analog}3... + if (1 == i) { + WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), D_SENSOR_USER); // }2'15'>User}3 + } // WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, i, GetTextIndexed(stemp, sizeof(stemp), i, kAdc0Names), i); -// } -// WSContentSend_P(HTTP_SCRIPT_TEMPLATE3); -//#endif // ESP8266 + uint32_t ridx = pgm_read_word(kAdcNiceList + i) & 0xFFE0; + uint32_t midx = BGPIO(ridx); + WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, ridx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames)); + } + WSContentSend_P(HTTP_SCRIPT_TEMPLATE3); +#endif // ESP8266 WSContentSend_P(HTTP_SCRIPT_TEMPLATE4); for (uint32_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3" @@ -1797,15 +1801,15 @@ void HandleTemplateConfiguration(void) // ((9==i)||(10==i)) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? " style='width:200px'" : "", i); //#else // ESP32 -#ifdef ESP8266 - WSContentSend_P(PSTR("