Fix command `gpio`

Fix command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)
This commit is contained in:
Theo Arends 2020-11-24 15:14:22 +01:00
parent 0e41e0b9fe
commit 547e5d9c5d
6 changed files with 32 additions and 28 deletions

View File

@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
## [9.1.0.2] ## [9.1.0.2]
### Added ### Added
- KNX read reply for Power (#9236, #9891) - KNX read reply for Power (#9236, #9891)
- Zigbee persistence of device/sensir data in EEPROM (only ZBBridge) - Zigbee persistence of device/sensor data in EEPROM (only ZBBridge)
### Breaking Changed ### Breaking Changed
- KNX DPT9 (16-bit float) to DPT14 (32-bit float) by Adrian Scillato (#9811, #9888) - KNX DPT9 (16-bit float) to DPT14 (32-bit float) by Adrian Scillato (#9811, #9888)
@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
### Fixed ### Fixed
- KNX ESP32 UDP mulicastpackage (#9811) - KNX ESP32 UDP mulicastpackage (#9811)
- Command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)
### Removed ### Removed

View File

@ -65,6 +65,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Zigbee command ``ZbLeave`` to unpair a device - Zigbee command ``ZbLeave`` to unpair a device
- Zigbee support for Mi Door and Contact (#9759) - Zigbee support for Mi Door and Contact (#9759)
- Zigbee alarm persistence (#9785) - Zigbee alarm persistence (#9785)
- Zigbee persistence of device/sensor data in EEPROM (only ZBBridge)
- Support for additional EZO sensors by Christopher Tremblay - Support for additional EZO sensors by Christopher Tremblay
- Support for AS608 optical and R503 capacitive fingerprint sensor - Support for AS608 optical and R503 capacitive fingerprint sensor
- Support for Shelly Dimmer 1 and 2 by James Turton (#9854) - Support for Shelly Dimmer 1 and 2 by James Turton (#9854)
@ -80,6 +81,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- MQTT Wifi connection timeout from 5000 to 200 mSec (#9886) - MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)
### Fixed ### Fixed
- Command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)
- NTP fallback server functionality (#9739) - NTP fallback server functionality (#9739)
- Telegram group chatid not supported (#9831) - Telegram group chatid not supported (#9831)
- KNX buttons, switches and sensors detection regression from v9.1.0 (#9811) - KNX buttons, switches and sensors detection regression from v9.1.0 (#9811)

View File

@ -1380,7 +1380,7 @@ void GetInternalTemplate(void* ptr, uint32_t module, uint32_t option) {
} }
#endif // ESP8266 #endif // ESP8266
void ModuleGpios(myio *gp) void TemplateGpios(myio *gp)
{ {
uint16_t *dest = (uint16_t *)gp; uint16_t *dest = (uint16_t *)gp;
uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)];

View File

@ -1132,20 +1132,21 @@ void CmndModules(void)
void CmndGpio(void) void CmndGpio(void)
{ {
if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) { if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) {
myio cmodule; myio template_gp;
ModuleGpios(&cmodule); TemplateGpios(&template_gp);
if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) { if (ValidGPIO(XdrvMailbox.index, template_gp.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) {
bool present = false; bool present = false;
for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) {
uint32_t midx = pgm_read_word(kGpioNiceList + i); uint32_t midx = pgm_read_word(kGpioNiceList + i);
if ((XdrvMailbox.payload >= (midx & 0xFFE0)) && (XdrvMailbox.payload < midx)) { uint32_t max_midx = ((midx & 0x001F) > 0) ? midx : midx +1;
if ((XdrvMailbox.payload >= (midx & 0xFFE0)) && (XdrvMailbox.payload < max_midx)) {
present = true; present = true;
break; break;
} }
} }
if (present) { if (present) {
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) { if (ValidGPIO(i, template_gp.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} }
} }
@ -1156,12 +1157,12 @@ void CmndGpio(void)
Response_P(PSTR("{")); Response_P(PSTR("{"));
bool jsflg = false; bool jsflg = false;
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i]) || ((255 == XdrvMailbox.payload) && !FlashPin(i))) { if (ValidGPIO(i, template_gp.io[i]) || ((255 == XdrvMailbox.payload) && !FlashPin(i))) {
if (jsflg) { ResponseAppend_P(PSTR(",")); } if (jsflg) { ResponseAppend_P(PSTR(",")); }
jsflg = true; jsflg = true;
uint32_t sensor_type = Settings.my_gp.io[i]; uint32_t sensor_type = Settings.my_gp.io[i];
if (!ValidGPIO(i, cmodule.io[i])) { if (!ValidGPIO(i, template_gp.io[i])) {
sensor_type = cmodule.io[i]; sensor_type = template_gp.io[i];
if (AGPIO(GPIO_USER) == sensor_type) { // A user GPIO equals a not connected (=GPIO_NONE) GPIO here if (AGPIO(GPIO_USER) == sensor_type) { // A user GPIO equals a not connected (=GPIO_NONE) GPIO here
sensor_type = GPIO_NONE; sensor_type = GPIO_NONE;
} }

View File

@ -1513,8 +1513,8 @@ void GpioInit(void)
} }
} }
myio def_gp; myio template_gp;
ModuleGpios(&def_gp); TemplateGpios(&template_gp);
for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if ((Settings.my_gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.my_gp.io[i] < AGPIO(GPIO_USER))) { if ((Settings.my_gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.my_gp.io[i] < AGPIO(GPIO_USER))) {
Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
@ -1522,8 +1522,8 @@ void GpioInit(void)
else if (Settings.my_gp.io[i] > GPIO_NONE) { else if (Settings.my_gp.io[i] > GPIO_NONE) {
TasmotaGlobal.my_module.io[i] = Settings.my_gp.io[i]; // Set User selected Module sensors TasmotaGlobal.my_module.io[i] = Settings.my_gp.io[i]; // Set User selected Module sensors
} }
if ((def_gp.io[i] > GPIO_NONE) && (def_gp.io[i] < AGPIO(GPIO_USER))) { if ((template_gp.io[i] > GPIO_NONE) && (template_gp.io[i] < AGPIO(GPIO_USER))) {
TasmotaGlobal.my_module.io[i] = def_gp.io[i]; // Force Template override TasmotaGlobal.my_module.io[i] = template_gp.io[i]; // Force Template override
} }
} }

View File

@ -1806,16 +1806,16 @@ void HandleTemplateConfiguration(void)
uint32_t module = atoi(stemp); uint32_t module = atoi(stemp);
uint32_t module_save = Settings.module; uint32_t module_save = Settings.module;
Settings.module = module; Settings.module = module;
myio cmodule; myio template_gp;
ModuleGpios(&cmodule); TemplateGpios(&template_gp);
gpio_flag flag = ModuleFlag(); gpio_flag flag = ModuleFlag();
Settings.module = module_save; Settings.module = module_save;
WSContentBegin(200, CT_PLAIN); WSContentBegin(200, CT_PLAIN);
WSContentSend_P(PSTR("%s}1"), AnyModuleName(module).c_str()); // NAME: Generic WSContentSend_P(PSTR("%s}1"), AnyModuleName(module).c_str()); // NAME: Generic
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
if (!FlashPin(i)) { if (!FlashPin(i)) {
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]); WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", template_gp.io[i]);
} }
} }
WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings.user_template_base); // FLAG: 1 BASE: 17 WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings.user_template_base); // FLAG: 1 BASE: 17
@ -1936,8 +1936,8 @@ void HandleModuleConfiguration(void)
char stemp[30]; // Sensor name char stemp[30]; // Sensor name
uint32_t midx; uint32_t midx;
myio cmodule; myio template_gp;
ModuleGpios(&cmodule); TemplateGpios(&template_gp);
WSContentStart_P(PSTR(D_CONFIGURE_MODULE)); WSContentStart_P(PSTR(D_CONFIGURE_MODULE));
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE); WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
@ -1958,8 +1958,8 @@ void HandleModuleConfiguration(void)
WSContentSendNiceLists(0); WSContentSendNiceLists(0);
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) { if (ValidGPIO(i, template_gp.io[i])) {
WSContentSend_P(PSTR("sk(%d,%d);"), TasmotaGlobal.my_module.io[i], i); // g0 - g17 WSContentSend_P(PSTR("sk(%d,%d);"), TasmotaGlobal.my_module.io[i], i); // g0 - g17
} }
} }
@ -1975,8 +1975,8 @@ void HandleModuleConfiguration(void)
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str()); WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str());
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) { if (ValidGPIO(i, template_gp.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(stemp, 3, PINS_WEMOS +i*2);
WSContentSend_P(PSTR("<tr><td style='width:116px'>%s <b>" D_GPIO "%d</b></td><td style='width:150px'><select id='g%d' onchange='ot(%d,this.value)'></select></td>"), WSContentSend_P(PSTR("<tr><td style='width:116px'>%s <b>" D_GPIO "%d</b></td><td style='width:150px'><select id='g%d' onchange='ot(%d,this.value)'></select></td>"),
(WEMOS==TasmotaGlobal.module_type)?stemp:"", i, i, i); (WEMOS==TasmotaGlobal.module_type)?stemp:"", i, i, i);
@ -1998,14 +1998,14 @@ void ModuleSaveSettings(void)
Settings.last_module = Settings.module; Settings.last_module = Settings.module;
Settings.module = new_module; Settings.module = new_module;
SetModuleType(); SetModuleType();
myio cmodule; myio template_gp;
ModuleGpios(&cmodule); TemplateGpios(&template_gp);
String gpios = ""; String gpios = "";
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) {
if (Settings.last_module != new_module) { if (Settings.last_module != new_module) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} else { } else {
if (ValidGPIO(i, cmodule.io[i])) { if (ValidGPIO(i, template_gp.io[i])) {
Settings.my_gp.io[i] = WebGetGpioArg(i); Settings.my_gp.io[i] = WebGetGpioArg(i);
gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]); gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]);
} }