Hello
I have simple application that allows keyboard input and blinking cursor. How to disable keyboard input and remove cursor?
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include "lv_drivers/indev/mouse.h"
#include <stdio.h>
#include <unistd.h>
#include "lv_examples/lv_examples.h"
#include <time.h>
#include <sys/time.h>
#define DISP_BUF_SIZE 800 * 600 * 4UL // If smaller than screen memory, draw will occur in chunks
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
printf("Clicked\n");
} else if(event == LV_EVENT_VALUE_CHANGED) {
printf("Toggled\n");
}
}
void lv_ex_btn_1(void)
{
lv_obj_t * label;
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(btn1, event_handler);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -100);
lv_obj_set_size(btn1, 300, 200);
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button");
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(btn2, event_handler);
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 100);
lv_btn_set_checkable(btn2, true);
lv_btn_toggle(btn2);
lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
lv_obj_set_size(btn2, 300, 200);
label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Toggled");
}
int main(void)
{
lv_init();
fbdev_init();
/*Small buffers for LittlevGL to draw the screen's content with double-buffering*/
static lv_color_t buf1[DISP_BUF_SIZE];
static lv_color_t buf2[DISP_BUF_SIZE];
/*Initialize a descriptor for the buffer, with double buffering*/
static lv_disp_buf_t disp_buf;
lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE);
/*Initialize and register a display driver*/
// Here we use the special callback function specific for the Linux Framebuffer Driver
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = fbdev_flush;
lv_disp_drv_register(&disp_drv);
// Initialize EVDEV input for the 52pi touchscreen,
// which luckily is supported as an "event input device" by the kernel
evdev_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = evdev_read;
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); /*Create an image object for the cursor */
lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/
lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label1, "Function 1");
lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label2, "Section A");
// Alignment
// NULL = align on parent (the screen)
lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
lv_obj_align(label2, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
// Add a button
lv_ex_btn_1();
/*Handle LitlevGL tasks (tickless mode)*/
// Mandatory, otherwise nothing will be displayed
// It allows the callback functions to operate (for example to actually transfer bytes to screen framebuffer)
while(1) {
lv_tick_inc(5);
lv_task_handler();
usleep(5000);
}
return 0;
}
uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if(start_ms == 0) {
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
}
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t now_ms;
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
uint32_t time_ms = now_ms - start_ms;
return time_ms;
}