Add initial touch screen support

This commit is contained in:
Rafał Kołucki 2026-05-25 22:45:47 +02:00
parent 85ae941c19
commit cf9dc33ca6
4 changed files with 189 additions and 1 deletions

View file

@ -4,6 +4,12 @@
#include <3ds.h>
#include "lvgl.h"
#include "lv_ctr_disp.h"
#include "lv_ctr_indev.h"
static lv_obj_t * cursor;
static lv_obj_t * label;
static lv_obj_t * label2;
long unsigned int sys_tick(void)
@ -23,16 +29,59 @@ void sys_free(void)
gfxExit();
}
static void cursor_timer_cb(lv_timer_t * t)
{
LV_UNUSED(t);
lv_indev_t * indev = lv_indev_get_next(NULL);
if (!indev)
return;
lv_point_t p;
lv_indev_get_point(indev, &p);
if (lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) {
lv_obj_set_pos(cursor, p.x - 5, p.y - 5);
lv_obj_clear_flag(cursor, LV_OBJ_FLAG_HIDDEN);
lv_label_set_text_fmt(label2,
"x: %d\ny: %d",
p.x,
p.y);
}
else {
lv_obj_add_flag(cursor, LV_OBJ_FLAG_HIDDEN);
}
}
int main(int argc, char* argv[])
{
sys_init();
lv_init();
lv_ctr_disp_init();
lv_ctr_indev_init();
lv_tick_set_cb(sys_tick);
lv_obj_t * label = lv_label_create(lv_screen_active());
label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hello world");
lv_obj_center(label);
/* Cursor */
cursor = lv_obj_create(lv_screen_active());
lv_obj_set_size(cursor, 10, 10);
lv_obj_set_style_radius(cursor, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_bg_color(cursor, lv_palette_main(LV_PALETTE_RED), 0);
lv_obj_set_style_border_width(cursor, 0, 0);
/* Coord label */
label2 = lv_label_create(lv_screen_active());
lv_obj_align(label2, LV_ALIGN_TOP_LEFT, 4, 4);
/* Main loop UI update timer */
lv_timer_create(cursor_timer_cb, 16, NULL);
lv_obj_invalidate(lv_screen_active());
// Main loop