Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » setTime and getTime

Author: Andrea
29/04/2021 06:56:47
Hi,
first of all.. great work!! smilie

I'm working with esp32 and ILI9341 tft display, I've tested tcMenuDesigner on Linux and it work well, thanks.

I'm trying to get correct time and date on display but I've some problem to understand the correct way.
I'm using 'time.h' lib, so I have time and date in byte format or String format(if needed) , but it's not clear (for me!) how to implement in sketch, function to get correct time and date .

Could you provide a very basic example explanation of it?

thanks

Author: davetcc
29/04/2021 13:06:34
Thanks for the vote of confidence!

I'm assuming that you want to set the time on a time menu item from a time_t structure using the standard time functions.

On mbed we do this using the standard C library time functions, here is an example:

https://github.com/davetcc/tcMenuLib/blob/d1c070d5d983aa1cc91e09dd06c890e63ff6e8bb/examples/stm32f4mbed/tcmenu_main.cpp#L184

Basically, the time structure that backs the date and time menu items has fields for each unit, such as hours, minutes, and seconds. The example above uses the gmtime function to convert a time_t into its constituents. They are then set one at a time onto the date and time menu items

The time library used by ESP32 is documented here: https://sourceware.org/newlib/libc.html#Timefns

Thanks,
Dave

Author: Andrea
01/05/2021 07:59:53
Thank's for you answer

I've forgot to write that I'm under Arduino core..
So I've solved in this way about setTime :

menuOra.setTime(TimeStorage(hTime,mTime));


where hTime and mTime are:
hTime = timeinfo.tm_hour;
  mTime = timeinfo.tm_min;


from a 'struct tm' based on 'time.h' library of Esp32 Arduino core example.

But now the problem is to refresh display ( possibly partially) and/or update time in real time.
I've tested a schedule but nothing change.
something like this in setup(), before setupMenu() :
taskManager.scheduleFixedRate(1000,[] {
       menuOra.setTime(TimeStorage(hTime,mTime));});


time is updated only if I move encoder and generate interrupt.
There's a way to update time without move encoder ?
thanks

Author: Andrea
01/05/2021 08:41:57
I've solved in this way ( please tell me if is the right way):

taskManager.scheduleFixedRate(1000,[] {
       printLocalTime();
       if(sTime == 0){
         Serial.println("UPDATE TIME FROM task");
         menuOra.setTime(TimeStorage(hTime,mTime));
         menuData.setDate(DateStorage(dayTime,monthTime,(yearTime+1900)));
         menuOra.setEditing(true);
         menuData.setEditing(true);
         menuOra.setEditing(false);
         menuData.setEditing(false);
       }
    });


task run every second and control time, if senconds = 0, I can update field.

Author: davetcc
01/05/2021 17:53:59
menuOra.setTime(TimeStorage(hTime,mTime));
         menuData.setDate(DateStorage(dayTime,monthTime,(yearTime+1900)));


Yes, this looks good to me, setting the values using the date and time types.

menuOra.setEditing(true);
         menuData.setEditing(true);
         menuOra.setEditing(false);
         menuData.setEditing(false);


I'm not really sure what this is doing though, if you want to mark it updated you could just:

menuOra.setChanged(true);
menuOra.setSendRemoteNeededAll();

Author: Andrea
01/05/2021 20:35:11
I find out now the correct function! thank you!
I modify and verify immediately.

when I call 'menuOra.setEditing (true)' I get an automatic positioning of the gray bar on the corresponding menu and an update of the time as desired.
I must, however, declare it 'false' immediately afterwards so as not to be 'blocked'. I haven't parsed the library and I'm probably not using it right, but it works!
In MenuItem class Reference , setEditing(bool active) description is ‘sets this item as the currently being edited, so that the renderer shows it as being edited’.

what do you think about it?

Author: davetcc
04/05/2021 06:47:47
Oh I think I see, you want it active as well, IE it becomes the active item in the menu..

in the case you would just need to add:

menuOra.setActive(true);

Author: Andrea
04/05/2021 10:18:32
I used your solution
setChanged(True)

it seems more correct .
setEditing (true)

needs
setEditing (false)

otherwise I get stuck (if I remember correctly!).

Author: davetcc
04/05/2021 17:30:21
Yep, that will update the field if that's all you need to do.

As long as it works for you then all is good.

Author: Andrea
04/05/2021 17:38:37
 
As long as it works for you then all is good.


smilie

Ok thanks!




Register / Login  |  Desktop view  |  Jump to top of page