sharandac / My-TTGO-Watch

A GUI named hedge for smartwatch like devices based on ESP32. Currently support for T-Watch2020 (V1,V2,V3), T-Watch2021, M5Paper, M5Core2 and native Linux support for testing.
GNU General Public License v2.0
524 stars 246 forks source link

Show sunrise/sunset times #343

Closed pavelmachek closed 2 years ago

pavelmachek commented 2 years ago

Would showing sunset/sunrise times be acceptable feature for the watch? I tweaked stopwatch applet to do that for me; code is at https://gitlab.com/tui/My-TTGO-Watch but it needs more polishing and I'm currently configuring user location in C code.

Crsarmv7l commented 2 years ago

BTW you can create your own widget through widget factory. Basically you integrate this stuff into something, probably whatever method you are using to parse/calculate the sunrise/sunset times:

#include "gui/widget.h"
#include "gui/widget_factory.h"
#include "gui/widget_styles.h"

icon_t *sunrisesunset_widget = NULL;

LV_IMG_DECLARE(sunrisesunset_64px);

sunrisesunset_widget = widget_register( "Sunrise/Sunset", sunrisesunset_64px), Callback here);

lv_label_set_text( sunrisesunset_widget->label, sunrise resolved string );
lv_label_set_text( sunrisesunset_widget->ext_label, sunset resolved string );
lv_obj_align( sunrisesunset_widget->label , sunrisesunset_widget->icon_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0 );
lv_obj_align( sunrisesunset_widget->ext_label , sunrisesunset_widget->icon_cont, LV_ALIGN_IN_TOP_MID, 0, 0 );
lv_label_set_align( sunrisesunset_widget->label, LV_LABEL_ALIGN_CENTER );
lv_label_set_align( sunrisesunset_widget->ext_label, LV_LABEL_ALIGN_CENTER );

You probably dont need the alignments, I think they are already outlined in the widget includes. You can get fancy and have it change the widget image (eg a rising sun in the morning and a setting sun at night), by re-purposing sharandac's src_icon code in bluetooth_message.cpp and using current time as an if.

I am at best a novice but I spent quite a while creating a BLE weather message widget with changing image based on the weather conditions, (didn't want to use wifi) so maybe this could help you.

The bluetooth_message.cpp is what I worked from since it has great examples.

Edit: Sorry I was using my implementation as an example and I didn't change all the appropriate stuff to fit the example