[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

setTime and getTime RSS feed
Forum Index » tcMenu Arduinio library
Author Message
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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();
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
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?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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);
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
I used your solution
setChanged(True)

it seems more correct .
setEditing (true)

needs
setEditing (false)

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


Joined: Jan 19, 2019
Messages: 686
Offline
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.
Andrea


Joined: Apr 29, 2021
Messages: 12
Offline
As long as it works for you then all is good.


smilie

Ok thanks!
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.