Clock hangs after 25 days

More
6 months 6 days ago #9723 by judge
Replied by judge on topic Clock hangs after 25 days
Here is some code that uses it:
void ledTimerHandler() {
...
}

void eepromUpdate() {
...
}

SoftMSTimer::TimerInfo ledTimer = {
		60000,
		0,
		true,
		ledTimerHandler
};

SoftMSTimer::TimerInfo eepromUpdateTimer = {
		60000,
		0,
		true,
		eepromUpdate
};

SoftMSTimer::TimerInfo *infos[] = {
		&ledTimer,
		&eepromUpdateTimer,
                0
}

SoftMSTimer timedFunctions(infos);

void loop() {
	timedFunctions.loop();
}

@Torsten: Several good points:
  1. The check of 0 was just a way of forcing the timer handler to be called immediately the first time. It would be more sensible to use a separate boolean flag for that.
  2. The loss of precision by missing ticks was not a factor for me. It is not intended to replace the use of interrupts,
    just to replace fairly common code in the Arduino environment where such things are checked in the Arduino loop() method.

Please Log in or Create an account to join the conversation.

More
6 months 6 days ago #9724 by judge
Replied by judge on topic Clock hangs after 25 days
@Ty, if you don't want the timers to go off on the first call to loop(), just initialize lastCalltick to 1. Or you could modify the code to not treat 0 as a special value.

Please Log in or Create an account to join the conversation.

More
6 months 6 days ago - 6 months 6 days ago #9726 by MikeS
Replied by MikeS on topic Clock hangs after 25 days
Easy fix for all:
if ( millis() > 4000000000) { ESP.restart(); }
:woohoo:

(sorry, been working on the wifi stuff, but I'm sure there's an equivalent for AVR)
Last edit: 6 months 6 days ago by MikeS.

Please Log in or Create an account to join the conversation.

More
6 months 6 days ago #9728 by Ty_Eeberfest
@Judge: Thanks for the example code - obviously C++ is not my forte. As for the 0 case, yes I'll probably remove that condition. I just wanted to hear the reasoning behind it before hacking away ib case I was missing something.

@Mike: Nice but I prefer to use:

weapons.nukes.detonate(ALL);

Look into it later when the dust is clearing off the crater.

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #9830 by MikeS
Replied by MikeS on topic Clock hangs after 25 days
While searching for something else, I came across PolledTimeout , which is a solution to this which was recently added to the ESP core. According to the author-

It encapsulates the correct way to do millis() based timing calculations, including correctness for rollover.

Please Log in or Create an account to join the conversation.

Moderators: AccutronTy_EeberfestIan
Time to create page: 0.218 seconds

Search

Tube Suppliers

Go to top
JSN Boot template designed by JoomlaShine.com