Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/lvgldemo/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ config EXAMPLES_LVGLDEMO_INPUT_DEVPATH
---help---
The path to the touchscreen device. Default: "/dev/input0"

config EXAMPLES_LVGLDEMO_FBDEVPATH
string "Framebuffer device path"
default "/dev/fb0"
depends on !LV_USE_NUTTX_LCD
---help---
The path to the framebuffer device. Default: "/dev/fb0"

config EXAMPLES_LVGLDEMO_TOUCH_DIAGNOSTIC
bool "Show touchscreen diagnostic"
default n
depends on INPUT_TOUCHSCREEN
---help---
Show touchscreen open status, press state, and coordinates instead
of an LVGL demo. This can distinguish an unavailable touchscreen
device from incorrect coordinate mapping without a serial console.

endif # EXAMPLES_LVGLDEMO
88 changes: 75 additions & 13 deletions examples/lvgldemo/lvgldemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@
****************************************************************************/

#include <nuttx/config.h>

#include <stdio.h>
#include <unistd.h>
#include <sys/boardctl.h>

#include <lvgl/lvgl.h>
#include <lvgl/demos/lv_demos.h>
#ifdef CONFIG_LV_USE_NUTTX_LIBUV
#include <uv.h>
# include <uv.h>
#endif

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Private Types
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_EXAMPLES_LVGLDEMO_TOUCH_DIAGNOSTIC
static FAR lv_indev_t *g_touch_indev;
static FAR lv_obj_t *g_touch_label;
#endif

/****************************************************************************
* Private Functions
****************************************************************************/

#ifdef CONFIG_LV_USE_NUTTX_LIBUV
static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result)
static void lv_nuttx_uv_loop(FAR uv_loop_t *loop,
FAR lv_nuttx_result_t *result)
{
lv_nuttx_uv_t uv_info;
void *data;
FAR void *data;

uv_loop_init(loop);

lv_memset(&uv_info, 0, sizeof(uv_info));
uv_info.loop = loop;
uv_info.disp = result->disp;
uv_info.loop = loop;
uv_info.disp = result->disp;
uv_info.indev = result->indev;
#ifdef CONFIG_UINPUT_TOUCH
uv_info.uindev = result->utouch_indev;
Expand All @@ -72,6 +72,58 @@ static void lv_nuttx_uv_loop(uv_loop_t *loop, lv_nuttx_result_t *result)
}
#endif

#ifdef CONFIG_EXAMPLES_LVGLDEMO_TOUCH_DIAGNOSTIC
static void touch_diag_update(FAR lv_timer_t *timer)
{
char text[64];
lv_point_t point;
lv_indev_state_t state;

if (g_touch_indev == NULL)
{
return;
}

state = lv_indev_get_state(g_touch_indev);
lv_indev_get_point(g_touch_indev, &point);
snprintf(text, sizeof(text), "state: %s\nx: %d y: %d",
state == LV_INDEV_STATE_PRESSED ? "pressed" : "released",
(int)point.x, (int)point.y);
lv_label_set_text(g_touch_label, text);

(void)timer;
}

static void touch_diag_create(FAR lv_indev_t *indev)
{
FAR lv_obj_t *screen;
FAR lv_obj_t *title;

screen = lv_obj_create(NULL);
title = lv_label_create(screen);
lv_label_set_text(title, "Touchscreen diagnostic");
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 24);

g_touch_label = lv_label_create(screen);
lv_obj_align(g_touch_label, LV_ALIGN_CENTER, 0, 0);
g_touch_indev = indev;

if (indev == NULL)
{
lv_label_set_text(g_touch_label,
"Touchscreen device could not be opened");
}
else
{
lv_label_set_text(g_touch_label,
"Touch the display to inspect coordinates");
lv_timer_create(touch_diag_update, 50, NULL);
}

lv_scr_load(screen);
}
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -111,6 +163,8 @@ int main(int argc, FAR char *argv[])

#ifdef CONFIG_LV_USE_NUTTX_LCD
info.fb_path = "/dev/lcd0";
#else
info.fb_path = CONFIG_EXAMPLES_LVGLDEMO_FBDEVPATH;
#endif

#ifdef CONFIG_INPUT_TOUCHSCREEN
Expand All @@ -122,9 +176,14 @@ int main(int argc, FAR char *argv[])
if (result.disp == NULL)
{
LV_LOG_ERROR("lv_demos initialization failure!");
lv_nuttx_deinit(&result);
lv_deinit();
return 1;
}

#ifdef CONFIG_EXAMPLES_LVGLDEMO_TOUCH_DIAGNOSTIC
touch_diag_create(result.indev);
#else
if (!lv_demos_create(&argv[1], argc - 1))
{
lv_demos_show_help();
Expand All @@ -133,6 +192,7 @@ int main(int argc, FAR char *argv[])

goto demo_end;
}
#endif

#ifdef CONFIG_LV_USE_NUTTX_LIBUV
lv_nuttx_uv_loop(&ui_loop, &result);
Expand All @@ -149,7 +209,9 @@ int main(int argc, FAR char *argv[])
}
#endif

#ifndef CONFIG_EXAMPLES_LVGLDEMO_TOUCH_DIAGNOSTIC
demo_end:
#endif
lv_nuttx_deinit(&result);
lv_deinit();

Expand Down
Loading