diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 0fbcbb615..054d830cc 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -969,6 +969,9 @@ void Every250mSeconds(void) SettingsSave(1); // Free flash for OTA update } if (ota_state_flag <= 0) { +#ifdef USE_COUNTER + CounterInterruptDisable(true); // Prevent OTA failures on 100Hz counter interrupts +#endif // USE_COUNTER #ifdef USE_WEBSERVER if (Settings.webserver) StopWebserver(); #endif // USE_WEBSERVER @@ -1000,15 +1003,6 @@ void Every250mSeconds(void) char *bch = strrchr(mqtt_data, '/'); // Only consider filename after last backslash prevent change of urls having "-" in it if (bch == nullptr) { bch = mqtt_data; } // No path found so use filename only -/* - char *ech = strrchr(bch, '.'); // Find file type in filename (none, .bin or .gz) - if ((ech != nullptr) && (0 == strncasecmp_P(ech, PSTR(".GZ"), 3))) { - char *fch = ech; - *fch = '\0'; - ech = strrchr(bch, '.'); // Find file type .bin.gz - *fch = '.'; - } -*/ char *ech = strchr(bch, '.'); // Find file type in filename (none, .ino.bin, .ino.bin.gz, .bin, .bin.gz or .gz) if (ech == nullptr) { ech = mqtt_data + strlen(mqtt_data); } // Point to '/0' at end of mqtt_data becoming an empty string @@ -1055,6 +1049,9 @@ void Every250mSeconds(void) ResponseAppend_P(PSTR("\"}")); // restart_flag = 2; // Restart anyway to keep memory clean webserver MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_UPGRADE)); +#ifdef USE_COUNTER + CounterInterruptDisable(false); +#endif // USE_COUNTER } } break; diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 112b9ac7f..b94a2a902 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2600,7 +2600,7 @@ void HandleUploadDone(void) MqttRetryCounter(0); #ifdef USE_COUNTER CounterInterruptDisable(false); -#endif +#endif // USE_COUNTER WSContentStart_P(S_INFORMATION); if (!Web.upload_error) { @@ -2677,8 +2677,8 @@ void HandleUploadLoop(void) } else { MqttRetryCounter(60); #ifdef USE_COUNTER - CounterInterruptDisable(true); -#endif + CounterInterruptDisable(true); // Prevent OTA failures on 100Hz counter interrupts +#endif // USE_COUNTER #ifdef USE_EMULATION UdpDisconnect(); #endif // USE_EMULATION @@ -2876,7 +2876,7 @@ void HandleUploadLoop(void) MqttRetryCounter(0); #ifdef USE_COUNTER CounterInterruptDisable(false); -#endif +#endif // USE_COUNTER Web.upload_error = 7; // Upload aborted if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); } } diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 73c19322e..5b6de4e4c 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -49,7 +49,6 @@ struct COUNTER { uint32_t last_cycle; uint32_t cycle_time; -//void ICACHE_RAM_ATTR CounterUpdate(uint8_t index) { void ICACHE_RAM_ATTR CounterIsrArg(void *arg) { uint32_t index = *static_cast(arg); @@ -94,15 +93,15 @@ void ICACHE_RAM_ATTR CounterIsrArg(void *arg) { // add 100.000 cpu ticks to ensure right step calculation uint32_t steps = (current_cycle-last_cycle+100000)/(clockCyclesPerMicrosecond() * 10000); cycle_time = (current_cycle-last_cycle)/steps; - #ifdef ESP8266 +#ifdef ESP8266 pinMode(Pin(GPIO_PWM1, index), OUTPUT); uint32_t high = (cycle_time * 5) / 1023; uint32_t low = cycle_time - high; // Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t startWaveformClockCycles(Pin(GPIO_PWM1, index), high, low, 0, -1, 0, true); - #else +#else // ESP32 analogWrite(Pin(GPIO_PWM1, index), 5); - #endif +#endif // ESP8266 - ESP32 } last_cycle = current_cycle; } @@ -120,27 +119,7 @@ void ICACHE_RAM_ATTR CounterIsrArg(void *arg) { } } } -/* -void ICACHE_RAM_ATTR CounterUpdate1(void) -{ - CounterUpdate(0); -} -void ICACHE_RAM_ATTR CounterUpdate2(void) -{ - CounterUpdate(1); -} - -void ICACHE_RAM_ATTR CounterUpdate3(void) -{ - CounterUpdate(2); -} - -void ICACHE_RAM_ATTR CounterUpdate4(void) -{ - CounterUpdate(3); -} -*/ /********************************************************************************************/ void CounterInterruptDisable(bool state) { @@ -172,20 +151,15 @@ bool CounterPinState(void) void CounterInit(void) { -// typedef void (*function) () ; -// function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 }; - for (uint32_t i = 0; i < MAX_COUNTERS; i++) { if (PinUsed(GPIO_CNTR1, i)) { Counter.any_counter = true; pinMode(Pin(GPIO_CNTR1, i), bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP); if ((0 == Settings.pulse_counter_debounce_low) && (0 == Settings.pulse_counter_debounce_high) && !Settings.flag4.zerocross_dimmer) { Counter.pin_state = 0; -// attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], FALLING); attachInterruptArg(Pin(GPIO_CNTR1, i), CounterIsrArg, &ctr_index[i], FALLING); } else { Counter.pin_state = 0x8f; -// attachInterrupt(Pin(GPIO_CNTR1, i), counter_callbacks[i], CHANGE); attachInterruptArg(Pin(GPIO_CNTR1, i), CounterIsrArg, &ctr_index[i], CHANGE); } }