Go Down

Topic: Time Library added to Playground (Read 39 times) previous topic - next topic

mem

A library called Time that provides timekeeping functionality for Arduino has been added to the playground.

This library is derived from the playground DateTime code but has a different API that is intended to be more flexible and easier to use.

This is the first full release of the Library.  The API and examples have changed slightly from prototype code posted at the end of December and anyone using the prototype code is encouraged to download the playground version.

See the Playground article for more on using the Time library.

AlphaBeta

This looks very good!

Clean and readable code.


Now, I have only one (okay maybe two...) request(s)/concern(s):

I think you should (continue to) prefix your defines with dt or t.
All your macros listed under /* Useful Macros for getting elapsed time */ Time.h line 53+ are potential user defined function names.

Such as elapsedDays, this might be a function name in a sketch that wats to use you Time library, but it's functionality might differ from your macro (so a userdefined function is necessary).

On a more pickyer (is that even a word?) note, I'd also like your tmElements_t to be renamed to a more Arduinoesque TimeElements and that all of its member fields start lowercase.
This could sure be of use for the users of your library.


Good work!

mem

AlhpaBeta, thanks for the (as always) thoughtful suggestions.

Prefixing the macros does reduce the likelihood of name collision but it makes them less Arduino like.

I could change them to inline functions so the compiler will warn if the user provides a function with a similar name. Lets see if there other opinions on how best to address this.

The name tmElements_t was chosen because this structure was really intended for programmers writing time provider code rather than use in a sketch (I wanted to keep the tm prefix to remind programmers that its derived from the C tm structure).  But I can certainly change the name if it looks like TimeElements could be useful in a sketch.

AlphaBeta

Quote
Prefixing the macros does reduce the likelihood of name collision but it makes them less Arduino like.

I could change them to inline functions so the compiler will warn if the user provides a function with a similar name. Lets see if there other opinions on how best to address this.

I did not think that the macros might be useful for the library user, then I think your inline function suggestion is the way to go :)

Quote

The name tmElements_t was chosen because this structure was really intended for programmers writing time provider code rather than use in a sketch (I wanted to keep the tm prefix to remind programmers that its derived from the C tm structure).  But I can certainly change the name if it looks like TimeElements could be useful in a sketch.

Well, all ideas I can think of (beyond the helloworldlike clock use-case) would've used such a TimeElements structure.

Maybe a timelapse photo that follows a predetermined 'most traffic of the day' time. Then a day of week, and a time of day datarepresentation would be useful. Your tmElements_t would be a perfect storage container.

Or a simple alarm/eventgenerator with alarms/events triggering each year, each month, each day of week, each hour etc etc..

I can think of many more use-cases, but now. Enough from me, I'll let someone else speak their mind :)

Veronica

Hi mem,

Thanks for this new library!  One small problem (at least on Ubuntu 9.04), the

Code: [Select]

#include <time.h>


in Time.cpp should have a capital T e.g.

Code: [Select]

#include <Time.h>


otherwise the examples won't compile as they complain about a missing time.h file.  

Regards

Ver

Go Up