Hi Rohit,

On Wed, Dec 26, 2018 at 11:55:56PM +0530, Rohit Gujarathi wrote:
> Hi Everyone,
> 
> I wanted to make a desktop clock using mynewt and am stuck at setting the
> time. I read the os_timeval part but How do i set time in mynewt and
> display it human form? I am using the nrf52840 which has a RTC, how can i
> use that? has anyone used the __DATE__ and __TIME__ macro?

The __DATE__ and __TIME__ macros are useful when you need to know when a
program was built.  Since you are interested in the actual real time
(independent of the build time), these macros won't help you.

I would look at the following two functions:

    os_gettimeofday()
    
(http://mynewt.apache.org/latest/os/core_os/time/os_time.html#c.os_gettimeofday)

    os_settimeofday()
    
(http://mynewt.apache.org/latest/os/core_os/time/os_time.html#c.os_settimeofday)

When the device boots up, set its time using `os_settimeofday()`.  To
display the current time, call `os_gettimeofday()` and convert the
result to a human readable format.

These functions deal in UNIX time, i.e., seconds since 1970/01/01.
I'm afraid converting this number to a human readable format is not
trivial due to pesky human factors such as time zones, leap years, etc.
Luckily, these functions use the POSIX time data structures, so there
should be a lot of free code avialable online that does this conversion.

I am not very familiar with the nRF52 RTC.  Maybe others who are more
knowledgable can chime in.

Chris

Reply via email to