EDIT:
I have found the issue already, can’t believe I hadn’t tried this yet: it seems the pointer to the calendar via lv_event_get_target(e)
is incorrect, setting the calendar
argument in lv_calendar_get_pressed_date()
to the globally defined ui_Calendar
instead of the target of the event fixes my issue.
However, this means that the example provided here Calendar (lv_calendar) — LVGL documentation
is either incorrect or not compatible with SquareLine Studio.
ORIGINAL QUESTION
Hello,
I am using LVGL v 8.3.6 in combination with SquareLine Studio and I want to implement a calendar so a user can set the date of the application.
I have added a calendar widget and a function call on LV_VALUE_CHANGED
event via SquareLine Studio.
When I try reading the value of this calendar, my application crashes. My code look like this:
lv_obj_t* calendar = lv_event_get_target(e);
lv_calendar_date_t calendarDate;
if (lv_calendar_get_pressed_date(calendar, &calendarDate) == LV_RES_OK)
{
set_date(&date, (uint8_t)calendarDate.day,
(uint8_t)calendarDate.month,
calendarDate.year);
}
I use my own date_t
struct in the application, so that’s what set_date()
is for, it can be ignored.
The application crashes in the function lv_calendar_get_pressed_date()
.
Debugging tells me the following, first the calendar tries to get the current pressed button based on the button matrix associated with it.
IN LV_BTNMATRIX.C
uint16_t lv_btnmatrix_get_selected_btn(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
return btnm->btn_id_sel; <---btn_id_sel = 7772!!
}
Later on lv_btnmatrix_get_btn_text()
gets called:
IN LV_BTNMATRIX.C
const char * lv_btnmatrix_get_btn_text(const lv_obj_t * obj, uint16_t btn_id)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(btn_id == LV_BTNMATRIX_BTN_NONE) return NULL;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if(btn_id > btnm->btn_cnt) return NULL; <--- btn_cnt = 53052!!!
uint16_t txt_i = 0;
uint16_t btn_i = 0;
/*Search the text of btnm->btn_pr the buttons text in the map
*Skip "\n"-s*/
while(btn_i != btn_id) {
btn_i++;
txt_i++;
if(strcmp(btnm->map_p[txt_i], "\n") == 0) txt_i++; <--- This should go on until btn_i reaches btn_id (7772)
}
if(btn_i == btnm->btn_cnt) return NULL;
return btnm->map_p[txt_i];
}
The application crashes when btn_i
reaches 55
in the above function.
It seems to me there is something wrong with the data here, the matrix for the calendar (7x7 buttons) should not really reach a higher count than 49, right?
The btn_id
should not be 7772 either. Am I perhaps passing a variable incorrectly somewhere, have I (by using SLS) wrongly initialized the calendar?