Description
The simulator starts and closes after 2 seconds. The issue happens when using “lv_indev_drv_register”. I’m following the same steps in LVGL academy lessons and v8.0 documentation as well.
What MCU/Processor/Board and compiler are you using?
The issue happens on both Windows code blocks simulator and PC simulator on RPi 3B+
What LVGL version are you using?
Latest version - 8.0
What do you want to achieve?
clicking on the screen works fine to toggle the LED ON\OFF. Once adding the “my_indev = lv_indev_drv_register(&indev_drv);” line of code, the simulator crashes after 2 seconds of starting.
What have you tried so far?
Following the same instructions on LVGL academy and v8.0 documentation.
Code to reproduce
#include<stdio.h>
#include<string.h>
#include "lvgl/lvgl.h"
#include "external_button_on_screen.h"
static void btn_event_cb(lv_event_t* e);
static lv_led_t* _led;
static lv_btn_t* btn ;
int flag;
static lv_indev_t* my_indev;
static void gpio_init(void);
static bool button_read(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
void external_button_on_screen()
{
//calling the initializing the hardware GPIO - add initializing code to the function itself
gpio_init();//call the GPIO initializing function
//Creating the input device driver and all necessary declarations and functions
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
my_indev = lv_indev_drv_register(&indev_drv);//When adding this line the GUI crashes
//connecting the actual physical button press to a specific place on the screen
static lv_point_t points[4];
lv_indev_set_button_points(my_indev, points);
//Creating a button on the screen for testing
btn = lv_btn_create(lv_scr_act());
lv_label_t* label = lv_label_create(btn);
lv_label_set_text(label, "click me!");
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
//creating an LED on the screen for testing
_led = lv_led_create(lv_scr_act());
lv_obj_align(_led, LV_ALIGN_CENTER, 0, -50);
//lv_led_on(_led);
}
/*------------------------------------------------------*/
/*------------------------------------------------------*/
static void gpio_init(void)
{
//Initialize GPIO here
}
/*------------------------------------------------------*/
/*------------------------------------------------------*/
static bool button_read(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
//reading GPIO
if(rand() %20 == 1)
{
data->state = LV_INDEV_STATE_PR;//Either this
}
else
{
data->state = LV_INDEV_STATE_REL;//OR this
}
return false;
}
/*------------------------------------------------------*/
/*------------------------------------------------------*/
static void btn_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_CLICKED && flag == 0)
{
lv_obj_set_style_shadow_color(btn, lv_palette_main(LV_PALETTE_GREEN), 0);
lv_obj_set_style_shadow_width(btn, 20, 0);//first value is the shadow intensity and second value is the shadow selector ID
lv_obj_set_style_shadow_spread(btn, 10, 0);
lv_obj_set_style_shadow_ofs_x(btn, 0, 0);//to add x axis offset to the created shadow
lv_obj_set_style_shadow_ofs_y(btn, 0, 0);//set the Y axis offset
lv_obj_set_style_shadow_opa(btn, 100, 0);//set the opacity of the shadow
lv_led_on(_led);
flag = 1;
}
else if (code == LV_EVENT_CLICKED && flag == 1)
{
lv_obj_set_style_shadow_color(btn, lv_palette_main(LV_PALETTE_BLUE), 0);
lv_obj_set_style_shadow_width(btn, 20, 0);//first value is the shadow intensity and second value is the shadow selector ID
lv_obj_set_style_shadow_spread(btn, 10, 0);
lv_obj_set_style_shadow_ofs_x(btn, 0, 0);//to add x axis offset to the created shadow
lv_obj_set_style_shadow_ofs_y(btn, 0, 0);//set the Y axis offset
lv_obj_set_style_shadow_opa(btn, 100, 0);//set the opacity of the shadow
lv_led_off(_led);
flag = 0;
}
}