Go Down

Topic: VirtualDelay (Read 5144 times) previous topic - next topic

avandalen

#15
Sep 04, 2017, 05:01 pm Last Edit: Sep 05, 2017, 08:46 am by avandalen
----- IMPORTANT -----

The library has been completely rewritten because there was a bug in the function proceed(). see:
http://www.avdweb.nl/arduino/libraries/virtualdelay.html

rhubka

Thanks avandalen

I've downloaded your updated Delay library from Github
Github

I'm going to start playing with it.

The thought of the Delay() stopping code execution drives me crazy. >:(

Cheers

Rick Hubka


sechen

Hi!
Does it work with Leonardo?
According description it's great but can't compile

avandalen

Thanks avandalen

I've downloaded your updated Delay library from Github
Github

I'm going to start playing with it.

The thought of the Delay() stopping code execution drives me crazy. >:(

Cheers

Rick Hubka
try the new version, everything is tested


avandalen

Hi!
Does it work with Leonardo?
According description it's great but can't compile
yes AVR and SAMD21

TonyWilk

Hi,
I'm sure we're in 'better mousetrap' territory here and these things are prone to personal preferences, but here's my view...

On your linked page, you ought to have several examples of your library which tries to show how it simplifies the code and makes it more readable.

At the moment it seems to show how much of an unreadable nightmare you can create.

In your post you give:

void loop()
{ if(virtualDelay.done(500)) digitalWrite(ledPin, b=!b); // the LED blinks on and off
}

and on the page:

void loop()
{ singleDelay.start(400); // calls while running are ignored
  if(singleDelay.elapsed()) digitalWrite(ledPin, b=!b); // blink the onboard LED 400ms, 400ms off
}

...which just highlights to me that there is a problem in using this library and making it obvious and readable.
Having hidden functionality and/or side-effects to methods which requires you to comment it just to save a line of code is not a good idea.

I'd prefer:

if( singleDelay.stopped() )
  singleDelay.setRepeatingInterval(400);
if( singleDelay.elapsed() )
  //do the LED thing


Yours,
  TonyWilk



avandalen

Dear Tony

Thank you for your comments, I always like to hear if something can be improved

There is no virtualDelay.done  function anymore in the new version:
http://www.avdweb.nl/arduino/libraries/virtualdelay.html

>> I'd prefer:
if( singleDelay.stopped() )
  singleDelay.setRepeatingInterval(400);
if( singleDelay.elapsed() )
  //do the LED thing


Yes, that looks good, but I have no time to rewrite the library. Maybe we can change just the names of some functions to make it better understandable?

TonyWilk

Hi,
Maybe we can change just the names of some functions to make it better understandable?
Yes, I think that the actual names of methods can make a great deal of difference to the usability of a class.

In some cases it might be handy to simply provide some aliases for different use-cases (I know there are different opinions on this)
for example:

myclass.setTimeout( 250 );
if( myclass.hasTimedOut() )
...

myclass.setRepeatingInterval( 100 );
if( myclass.intervalHasElapsed() )
...

... could be that hasTimedOut() and intervalHasElapsed() are internally identical.

Yours,
 TonyWilk





avandalen

Hi,
Yes, I think that the actual names of methods can make a great deal of difference to the usability of a class.

In some cases it might be handy to simply provide some aliases for different use-cases (I know there are different opinions on this)
for example:

myclass.setTimeout( 250 );
if( myclass.hasTimedOut() )
...

myclass.setRepeatingInterval( 100 );
if( myclass.intervalHasElapsed() )
...

... could be that hasTimedOut() and intervalHasElapsed() are internally identical.

Note that DO_ONCE is still needed sometimes.
Can you please change the 5 examples with your function names?
Hi,
Yes, I think that the actual names of methods can make a great deal of difference to the usability of a class.

In some cases it might be handy to simply provide some aliases for different use-cases (I know there are different opinions on this)
for example:

myclass.setTimeout( 250 );
if( myclass.hasTimedOut() )
...

myclass.setRepeatingInterval( 100 );
if( myclass.intervalHasElapsed() )
...

... could be that hasTimedOut() and intervalHasElapsed() are internally identical.
I'm curious how your idea will work with the 5 examples in:
http://www.avdweb.nl/arduino/libraries/virtualdelay.html
Can you test it with the 5 examples? (Note that DO_ONCE is still needed sometimes)

Go Up