Description
I have gotten lvgl compiled and running using the linux frame buffer with my raspberry pi 4 and the smart pi 7" touch screen. I have looked at other posts and tried what was mentioned with no luck
What MCU/Processor/Board and compiler are you using?
I am using a Raspberry Pi 4
What LVGL version are you using?
latest master
What do you want to achieve?
Currently I have a button and am trying to make it to be able to be tapped, and when it is tapped to send data to another board over I2c
What have you tried so far?
Currently I followed the LVGL documentation and created an lv_indev object that has the LV_INDEV_POINTER type and set a call back function for it to use. When I run the code and put a printf statement in the callback, it does print out so I know the call back is being executed. However, code never get inside the if statement that says
data->state == LV_INDEV_STATE_PRESSED
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
Here is my main function with a simple button, my cmake file, and my lv_conf.h
main.c
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "lvgl/lvgl.h"
void lv_linux_run_loop(void)
{
uint32_t idle_time;
/*Handle LVGL tasks*/
while(1) {
idle_time = lv_timer_handler(); /*Returns the time to the next timer execution*/
usleep(idle_time * 1000);
}
}
void search_handler(lv_event_t *event);
void input_touch_event(lv_indev_t* indev, lv_indev_data_t* data);
int main(void) {
lv_init();
const char *device = getenv("LV_LINUX_FBDEV_DEVICE") ? : "/dev/fb0";
lv_display_t * disp = lv_linux_fbdev_create();
lv_linux_fbdev_set_file(disp, device);
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x161c20), LV_PART_MAIN);
/* Touchpad Monitor */
lv_indev_t *indev = lv_indev_create();
lv_indev_enable(indev, true);
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, input_touch_event);
/* LAYOUT */
/**/
lv_obj_t* label;
lv_obj_t *searchButton = lv_button_create(lv_screen_active());
lv_obj_align(searchButton, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_size(searchButton, lv_pct(20), lv_pct(10));
lv_obj_add_event_cb(searchButton, search_handler, LV_EVENT_ALL, NULL);
lv_obj_remove_flag(searchButton, LV_OBJ_FLAG_PRESS_LOCK);
lv_obj_add_flag(searchButton, LV_OBJ_FLAG_CLICKABLE);
label = lv_label_create(searchButton);
lv_label_set_text(label, "Search");
lv_obj_center(label);
/* STYLE */
static lv_style_t style;
lv_style_init(&style);
/*Set a background color and a radius*/
lv_style_set_bg_color(&style, lv_color_hex(0x2305cb));
lv_style_set_radius(&style, 25);
/*Add a shadow*/
lv_style_set_shadow_width(&style, 25);
lv_style_set_shadow_spread(&style, 1);
lv_style_set_shadow_color(&style, lv_color_white());
lv_style_set_shadow_offset_x(&style, 0);
lv_style_set_shadow_offset_y(&style, 0);
lv_obj_add_style(searchButton, &style, 0);
lv_linux_run_loop();
return 0;
}
void search_handler(lv_event_t *event) {
lv_event_code_t code = lv_event_get_code(event);
if(code == LV_EVENT_CLICKED) {
LV_LOG_USER("Clicked\n");
printf("Button Pressed\n");
}
}
void input_touch_event(lv_indev_t* indev, lv_indev_data_t* data) {
printf("Touch event %s\n", data->state);
if(data->state == LV_INDEV_STATE_PRESSED) {
printf("x: %i", data->point.x);
printf("y: %i", data->point.y);
}
}
#define LV_DEMO_EBIKE_PORTRAIT 0 /*0: for 480x270..480x320, 1: for 480x800..720x1280*/
#endif
/*--END OF LV_CONF_H--*/
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/
Here is the layout. It’s just a simple button at the moment