Description
I am trying to use the lv calendar widget to set the current date (and time) manually, in case of lacking internet access (NTP/UDP).
Unfortunately my code crashes on my Arduino Giga
What MCU/Processor/Board and compiler are you using?
Arduino Giga WiFi R1 with GigaDisplay
What LVGL version are you using?
v9.1
What do you want to achieve?
I would like to simply set the today’s date (firstly in the widget, secondly - combined with time - my RTC). (I would expect the new date selected being shown as framed like the prior today’s date.)
What have you tried so far?
I used a simple sketch (follows) where the LV_EVENT_VALUE_CHANGED is used to get the selected date and call lv_calendar_set_today_date with the date received from lv_calendar_get_pressed_date.
When I do like shown in the code, the Arduino freezes, red led is blinking, so it crashed…
Code to reproduce
//
#include <Arduino.h>
#include <lvgl.h>
#include "Arduino_H7_Video.h"
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
#include "Arduino_GigaDisplayTouch.h"
Arduino_GigaDisplayTouch TouchDetector;
#define LV_FONT_LARGE &lv_font_montserrat_18
lv_obj_t *screen;
lv_obj_t *cal1;
lv_obj_t *cal1_header;
static void ca_event_handler(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *obj = (lv_obj_t *)lv_event_get_current_target(e);
if (code == LV_EVENT_VALUE_CHANGED) {
lv_calendar_date_t date;
if (lv_calendar_get_pressed_date(obj, &date)) {
lv_calendar_set_today_date(cal1, date.year, date.month, date.day);
}
}
}
void screen_init(void) {
lv_obj_t *screen = lv_obj_create(NULL);
lv_obj_set_size(screen, Display.width(), Display.height());
lv_obj_set_style_bg_color(screen, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(screen, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(screen, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(screen, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(screen, LV_FONT_LARGE, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_color(screen, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(screen, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_t *cal1 = lv_calendar_create(screen);
lv_obj_t *cal1_header = lv_calendar_header_dropdown_create(cal1);
lv_obj_set_width(cal1, 400);
lv_obj_set_height(cal1, 400);
lv_obj_set_x(cal1, 0);
lv_obj_set_y(cal1, 0);
lv_obj_set_align(cal1, LV_ALIGN_CENTER);
lv_calendar_set_today_date(cal1, 2024, 8, 30);
lv_calendar_set_showed_date(cal1, 2024, 8);
lv_obj_add_event_cb(cal1, ca_event_handler, LV_EVENT_ALL, NULL);
lv_disp_load_scr(screen);
}
void ui_init(void) {
lv_disp_t *dispp = lv_disp_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), false, LV_FONT_LARGE);
lv_disp_set_theme(dispp, theme);
}
void setup() {
Display.begin();
TouchDetector.begin();
Serial.begin(9600);
delay(2000);
ui_init();
screen_init();
}
void loop() {
lv_timer_handler();
}```