mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Change timer reset to 70 minutes
Change timer reset to 70 minutes (#6349)
This commit is contained in:
parent
8e657be6a9
commit
b2d1e385c0
@ -34,10 +34,13 @@ const char kCounterCommands[] PROGMEM = D_PRFX_COUNTER "|" // Prefix
|
|||||||
void (* const CounterCommand[])(void) PROGMEM =
|
void (* const CounterCommand[])(void) PROGMEM =
|
||||||
{ &CmndCounter, &CmndCounterType, &CmndCounterDebounce };
|
{ &CmndCounter, &CmndCounterType, &CmndCounterDebounce };
|
||||||
|
|
||||||
unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in micro seconds
|
struct COUNTER {
|
||||||
uint8_t counter_no_pullup = 0; // Counter input pullup flag (1 = No pullup)
|
uint32_t timer[MAX_COUNTERS]; // Last counter time in micro seconds
|
||||||
|
uint8_t no_pullup = 0; // Counter input pullup flag (1 = No pullup)
|
||||||
|
bool any_counter = false;
|
||||||
|
} Counter;
|
||||||
|
|
||||||
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception
|
#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception
|
||||||
void CounterUpdate(uint8_t index) ICACHE_RAM_ATTR;
|
void CounterUpdate(uint8_t index) ICACHE_RAM_ATTR;
|
||||||
void CounterUpdate1(void) ICACHE_RAM_ATTR;
|
void CounterUpdate1(void) ICACHE_RAM_ATTR;
|
||||||
void CounterUpdate2(void) ICACHE_RAM_ATTR;
|
void CounterUpdate2(void) ICACHE_RAM_ATTR;
|
||||||
@ -47,37 +50,36 @@ void CounterUpdate4(void) ICACHE_RAM_ATTR;
|
|||||||
|
|
||||||
void CounterUpdate(uint8_t index)
|
void CounterUpdate(uint8_t index)
|
||||||
{
|
{
|
||||||
unsigned long counter_debounce_time = micros() - last_counter_timer[index -1];
|
uint32_t time = micros();
|
||||||
if (counter_debounce_time > Settings.pulse_counter_debounce * 1000) {
|
uint32_t debounce_time = time - Counter.timer[index];
|
||||||
last_counter_timer[index -1] = micros();
|
if (debounce_time > Settings.pulse_counter_debounce * 1000) {
|
||||||
if (bitRead(Settings.pulse_counter_type, index -1)) {
|
Counter.timer[index] = time;
|
||||||
RtcSettings.pulse_counter[index -1] = counter_debounce_time;
|
if (bitRead(Settings.pulse_counter_type, index)) {
|
||||||
|
RtcSettings.pulse_counter[index] = debounce_time;
|
||||||
} else {
|
} else {
|
||||||
RtcSettings.pulse_counter[index -1]++;
|
RtcSettings.pulse_counter[index]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("CNTR: Interrupt %d"), index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CounterUpdate1(void)
|
void CounterUpdate1(void)
|
||||||
{
|
{
|
||||||
CounterUpdate(1);
|
CounterUpdate(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CounterUpdate2(void)
|
void CounterUpdate2(void)
|
||||||
{
|
{
|
||||||
CounterUpdate(2);
|
CounterUpdate(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CounterUpdate3(void)
|
void CounterUpdate3(void)
|
||||||
{
|
{
|
||||||
CounterUpdate(3);
|
CounterUpdate(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CounterUpdate4(void)
|
void CounterUpdate4(void)
|
||||||
{
|
{
|
||||||
CounterUpdate(4);
|
CounterUpdate(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
@ -85,7 +87,7 @@ void CounterUpdate4(void)
|
|||||||
bool CounterPinState(void)
|
bool CounterPinState(void)
|
||||||
{
|
{
|
||||||
if ((XdrvMailbox.index >= GPIO_CNTR1_NP) && (XdrvMailbox.index < (GPIO_CNTR1_NP + MAX_COUNTERS))) {
|
if ((XdrvMailbox.index >= GPIO_CNTR1_NP) && (XdrvMailbox.index < (GPIO_CNTR1_NP + MAX_COUNTERS))) {
|
||||||
bitSet(counter_no_pullup, XdrvMailbox.index - GPIO_CNTR1_NP);
|
bitSet(Counter.no_pullup, XdrvMailbox.index - GPIO_CNTR1_NP);
|
||||||
XdrvMailbox.index -= (GPIO_CNTR1_NP - GPIO_CNTR1);
|
XdrvMailbox.index -= (GPIO_CNTR1_NP - GPIO_CNTR1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -99,12 +101,27 @@ void CounterInit(void)
|
|||||||
|
|
||||||
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
||||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||||
pinMode(pin[GPIO_CNTR1 +i], bitRead(counter_no_pullup, i) ? INPUT : INPUT_PULLUP);
|
Counter.any_counter = true;
|
||||||
|
pinMode(pin[GPIO_CNTR1 +i], bitRead(Counter.no_pullup, i) ? INPUT : INPUT_PULLUP);
|
||||||
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
|
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CounterEverySecond(void)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
||||||
|
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||||
|
if (bitRead(Settings.pulse_counter_type, i)) {
|
||||||
|
uint32_t time = micros() - Counter.timer[i];
|
||||||
|
if (time > 4200000000) { // 70 minutes
|
||||||
|
RtcSettings.pulse_counter[i] = 4200000000; // Set Timer to max in case of no more interrupts due to stall of measured device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CounterSaveState(void)
|
void CounterSaveState(void)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
||||||
@ -147,9 +164,6 @@ void CounterShow(bool json)
|
|||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bitRead(Settings.pulse_counter_type, i)) {
|
|
||||||
RtcSettings.pulse_counter[i] = 0xFFFFFFFF; // Set Timer to max in case of no more interrupts due to stall of measured device
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (header) {
|
if (header) {
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
@ -204,28 +218,36 @@ bool Xsns01(uint8_t function)
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
if (Counter.any_counter) {
|
||||||
case FUNC_JSON_APPEND:
|
switch (function) {
|
||||||
CounterShow(1);
|
case FUNC_EVERY_SECOND:
|
||||||
break;
|
CounterEverySecond();
|
||||||
|
break;
|
||||||
|
case FUNC_JSON_APPEND:
|
||||||
|
CounterShow(1);
|
||||||
|
break;
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
CounterShow(0);
|
CounterShow(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
case FUNC_SAVE_BEFORE_RESTART:
|
case FUNC_SAVE_BEFORE_RESTART:
|
||||||
case FUNC_SAVE_AT_MIDNIGHT:
|
case FUNC_SAVE_AT_MIDNIGHT:
|
||||||
CounterSaveState();
|
CounterSaveState();
|
||||||
break;
|
break;
|
||||||
case FUNC_COMMAND:
|
case FUNC_COMMAND:
|
||||||
result = DecodeCommand(kCounterCommands, CounterCommand);
|
result = DecodeCommand(kCounterCommands, CounterCommand);
|
||||||
break;
|
break;
|
||||||
case FUNC_INIT:
|
}
|
||||||
CounterInit();
|
} else {
|
||||||
break;
|
switch (function) {
|
||||||
case FUNC_PIN_STATE:
|
case FUNC_INIT:
|
||||||
result = CounterPinState();
|
CounterInit();
|
||||||
break;
|
break;
|
||||||
|
case FUNC_PIN_STATE:
|
||||||
|
result = CounterPinState();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user