Skip to content

Commit

Permalink
Fix command gpio
Browse files Browse the repository at this point in the history
Fix command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)
  • Loading branch information
arendst committed Nov 24, 2020
1 parent 0e41e0b commit 547e5d9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
## [9.1.0.2]
### Added
- 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
- KNX DPT9 (16-bit float) to DPT14 (32-bit float) by Adrian Scillato (#9811, #9888)
Expand All @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.

### Fixed
- KNX ESP32 UDP mulicastpackage (#9811)
- Command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)

### Removed

Expand Down
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 support for Mi Door and Contact (#9759)
- Zigbee alarm persistence (#9785)
- Zigbee persistence of device/sensor data in EEPROM (only ZBBridge)
- Support for additional EZO sensors by Christopher Tremblay
- Support for AS608 optical and R503 capacitive fingerprint sensor
- Support for Shelly Dimmer 1 and 2 by James Turton (#9854)
Expand All @@ -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)

### Fixed
- Command ``gpio`` using non-indexed functions regression from v9.1.0 (#9962)
- NTP fallback server functionality (#9739)
- Telegram group chatid not supported (#9831)
- KNX buttons, switches and sensors detection regression from v9.1.0 (#9811)
Expand Down
2 changes: 1 addition & 1 deletion tasmota/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ void GetInternalTemplate(void* ptr, uint32_t module, uint32_t option) {
}
#endif // ESP8266

void ModuleGpios(myio *gp)
void TemplateGpios(myio *gp)
{
uint16_t *dest = (uint16_t *)gp;
uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)];
Expand Down
17 changes: 9 additions & 8 deletions tasmota/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1132,20 +1132,21 @@ void CmndModules(void)
void CmndGpio(void)
{
if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) {
myio cmodule;
ModuleGpios(&cmodule);
if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) {
myio template_gp;
TemplateGpios(&template_gp);
if (ValidGPIO(XdrvMailbox.index, template_gp.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) {
bool present = false;
for (uint32_t i = 0; i < ARRAY_SIZE(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;
break;
}
}
if (present) {
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;
}
}
Expand All @@ -1156,12 +1157,12 @@ void CmndGpio(void)
Response_P(PSTR("{"));
bool jsflg = false;
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(",")); }
jsflg = true;
uint32_t sensor_type = Settings.my_gp.io[i];
if (!ValidGPIO(i, cmodule.io[i])) {
sensor_type = cmodule.io[i];
if (!ValidGPIO(i, template_gp.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
sensor_type = GPIO_NONE;
}
Expand Down
8 changes: 4 additions & 4 deletions tasmota/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1513,17 +1513,17 @@ void GpioInit(void)
}
}

myio def_gp;
ModuleGpios(&def_gp);
myio template_gp;
TemplateGpios(&template_gp);
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))) {
Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
}
else if (Settings.my_gp.io[i] > GPIO_NONE) {
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))) {
TasmotaGlobal.my_module.io[i] = def_gp.io[i]; // Force Template override
if ((template_gp.io[i] > GPIO_NONE) && (template_gp.io[i] < AGPIO(GPIO_USER))) {
TasmotaGlobal.my_module.io[i] = template_gp.io[i]; // Force Template override
}
}

Expand Down
28 changes: 14 additions & 14 deletions tasmota/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1806,16 +1806,16 @@ void HandleTemplateConfiguration(void)
uint32_t module = atoi(stemp);
uint32_t module_save = Settings.module;
Settings.module = module;
myio cmodule;
ModuleGpios(&cmodule);
myio template_gp;
TemplateGpios(&template_gp);
gpio_flag flag = ModuleFlag();
Settings.module = module_save;

WSContentBegin(200, CT_PLAIN);
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)) {
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
Expand Down Expand Up @@ -1936,8 +1936,8 @@ void HandleModuleConfiguration(void)

char stemp[30]; // Sensor name
uint32_t midx;
myio cmodule;
ModuleGpios(&cmodule);
myio template_gp;
TemplateGpios(&template_gp);

WSContentStart_P(PSTR(D_CONFIGURE_MODULE));
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
Expand All @@ -1958,8 +1958,8 @@ void HandleModuleConfiguration(void)

WSContentSendNiceLists(0);

for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) {
for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) {
if (ValidGPIO(i, template_gp.io[i])) {
WSContentSend_P(PSTR("sk(%d,%d);"), TasmotaGlobal.my_module.io[i], i); // g0 - g17
}
}
Expand All @@ -1975,8 +1975,8 @@ void HandleModuleConfiguration(void)

WSContentSendStyle();
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str());
for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) {
for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) {
if (ValidGPIO(i, template_gp.io[i])) {
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>"),
(WEMOS==TasmotaGlobal.module_type)?stemp:"", i, i, i);
Expand All @@ -1998,14 +1998,14 @@ void ModuleSaveSettings(void)
Settings.last_module = Settings.module;
Settings.module = new_module;
SetModuleType();
myio cmodule;
ModuleGpios(&cmodule);
myio template_gp;
TemplateGpios(&template_gp);
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) {
Settings.my_gp.io[i] = GPIO_NONE;
} else {
if (ValidGPIO(i, cmodule.io[i])) {
if (ValidGPIO(i, template_gp.io[i])) {
Settings.my_gp.io[i] = WebGetGpioArg(i);
gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]);
}
Expand Down

0 comments on commit 547e5d9

Please sign in to comment.