diff --git a/drivers/video/vnc/Kconfig b/drivers/video/vnc/Kconfig index 878ff13127..b17e55fa8f 100644 --- a/drivers/video/vnc/Kconfig +++ b/drivers/video/vnc/Kconfig @@ -139,6 +139,22 @@ config VNCSERVER_KBDENCODE Use a special encoding of keyboard characters as defined in include/nuttx/input/kbd_coded.h. +config VNCSERVER_TOUCH + bool "Enable touch input" + default n + select INPUT + select INPUT_TOUCHSCREEN + ---help--- + Use touchscreen based input driver + +config VNCSERVER_TOUCH_DEVNAME + string "Touch input device name prefix" + default "/dev/input" + depends on VNCSERVER_TOUCH + ---help--- + Touch device name prefix, final devi name is /dev/inputX by default, + X is display number + config VNCSERVER_INBUFFER_SIZE int "Input buffer size" default 80 diff --git a/drivers/video/vnc/Make.defs b/drivers/video/vnc/Make.defs index 36d8f11946..1af4fb9e36 100644 --- a/drivers/video/vnc/Make.defs +++ b/drivers/video/vnc/Make.defs @@ -23,6 +23,10 @@ ifeq ($(CONFIG_VNCSERVER),y) CSRCS += vnc_server.c vnc_negotiate.c vnc_updater.c vnc_receiver.c CSRCS += vnc_raw.c vnc_rre.c vnc_color.c vnc_fbdev.c vnc_keymap.c +ifeq ($(CONFIG_VNCSERVER_TOUCH),y) +CSRCS += vnc_touch.c +endif + DEPPATH += --dep-path video/vnc CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)video$(DELIM)vnc} VPATH += :video/vnc diff --git a/drivers/video/vnc/vnc_fbdev.c b/drivers/video/vnc/vnc_fbdev.c index 0aa62932fd..bed7ca1fc3 100644 --- a/drivers/video/vnc/vnc_fbdev.c +++ b/drivers/video/vnc/vnc_fbdev.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,7 @@ #include #include #include +#include #include "vnc_server.h" @@ -598,15 +600,48 @@ static inline int vnc_wait_start(int display) int up_fbinitialize(int display) { int ret; + FAR struct vnc_session_s *session; +#ifdef CONFIG_VNCSERVER_TOUCH + char devname[NAME_MAX]; +#endif DEBUGASSERT(display >= 0 && display < RFB_MAX_DISPLAYS); + /* Save the input callout function information in the session structure. */ + + session = g_vnc_sessions[display]; +#ifdef CONFIG_VNCSERVER_TOUCH + + ret = snprintf(devname, NAME_MAX, CONFIG_VNCSERVER_TOUCH_DEVNAME "%d", + display); + + if (ret < 0) + { + gerr("ERROR: Format vnc touch driver path failed.\n"); + return ret; + } + + ret = vnc_touch_register(devname, session); + + if (ret < 0) + { + gerr("ERROR: Initial vnc touch driver failed.\n"); + return ret; + } + + session->mouseout = vnc_touch_event; +#endif + session->arg = session; + /* Start the VNC server kernel thread. */ ret = vnc_start_server(display); if (ret < 0) { gerr("ERROR: vnc_start_server() failed: %d\n", ret); +#ifdef CONFIG_VNCSERVER_TOUCH + vnc_touch_unregister(session, devname); +#endif return ret; } @@ -795,9 +830,11 @@ FAR struct fb_vtable_s *up_fbgetvplane(int display, int vplane) void up_fbuninitialize(int display) { -#if 0 /* Do nothing */ FAR struct vnc_session_s *session; - FAR struct vnc_fbinfo_s *fbinfo; +#ifdef CONFIG_VNCSERVER_TOUCH + int ret; + char devname[NAME_MAX]; +#endif DEBUGASSERT(display >= 0 && display < RFB_MAX_DISPLAYS); session = g_vnc_sessions[display]; @@ -806,10 +843,17 @@ void up_fbuninitialize(int display) if (session != NULL) { - fbinfo = &g_fbinfo[display]; -#warning Missing logic - UNUSED(session); - UNUSED(fbinfo); - } +#ifdef CONFIG_VNCSERVER_TOUCH + ret = snprintf(devname, NAME_MAX, CONFIG_VNCSERVER_TOUCH_DEVNAME "%d", + display); + + if (ret < 0) + { + gerr("ERROR: Format vnc touch driver path failed.\n"); + return; + } + + vnc_touch_unregister(session, devname); #endif + } } diff --git a/drivers/video/vnc/vnc_server.h b/drivers/video/vnc/vnc_server.h index c40bafcc1b..88c25e19bb 100644 --- a/drivers/video/vnc/vnc_server.h +++ b/drivers/video/vnc/vnc_server.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -222,6 +223,10 @@ struct vnc_session_s vnc_mouseout_t mouseout; /* Callout when keyboard input is received */ FAR void *arg; /* Argument that accompanies the callouts */ +#ifdef CONFIG_VNCSERVER_TOUCH + FAR struct touch_lowerhalf_s touch; /* Touch driver instance */ +#endif + /* Updater information */ pthread_t updater; /* Updater thread ID */ @@ -503,6 +508,45 @@ int vnc_raw(FAR struct vnc_session_s *session, FAR struct fb_area_s *rect); void vnc_key_map(FAR struct vnc_session_s *session, uint16_t keysym, bool keydown); +#ifdef CONFIG_VNCSERVER_TOUCH + +/**************************************************************************** + * Name: vnc_touch_register + * + * Description: + * Register touch device to fetch touch event from VNC client. + * + * Returned Value: + * Driver instance + * + ****************************************************************************/ + +int vnc_touch_register(FAR const char *devpath, + FAR struct vnc_session_s *session); + +/**************************************************************************** + * Name: vnc_touch_register + * + * Description: + * Unregister touch device. + * + ****************************************************************************/ + +void vnc_touch_unregister(FAR struct vnc_session_s *session, + FAR const char *devpath); + +/**************************************************************************** + * Name: vnc_touch_event + * + * Description: + * Report a touch event from vnc client. + * + ****************************************************************************/ + +int vnc_touch_event(FAR void *arg, int16_t x, int16_t y, uint8_t buttons); + +#endif + /**************************************************************************** * Name: vnc_convert_rgbNN * diff --git a/drivers/video/vnc/vnc_touch.c b/drivers/video/vnc/vnc_touch.c new file mode 100644 index 0000000000..2535a79124 --- /dev/null +++ b/drivers/video/vnc/vnc_touch.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * drivers/video/vnc/vnc_touch.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "vnc_server.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: vnc_touch_register + ****************************************************************************/ + +int vnc_touch_register(FAR const char *devpath, + FAR struct vnc_session_s *session) +{ + int ret; + + ret = touch_register(&session->touch, devpath, 1); + + if (ret < 0) + { + return ret; + } + + return OK; +} + +/**************************************************************************** + * Name: vnc_touch_register + ****************************************************************************/ + +void vnc_touch_unregister(FAR struct vnc_session_s *session, + FAR const char *devpath) +{ + touch_unregister(&session->touch, devpath); +} + +/**************************************************************************** + * Name: vnc_touch_event + ****************************************************************************/ + +int vnc_touch_event(FAR void *arg, int16_t x, int16_t y, uint8_t buttons) +{ + struct touch_sample_s sample; + FAR struct vnc_session_s *session = arg; + + DEBUGASSERT(session); + + sample.npoints = 1; + sample.point[0].x = x; + sample.point[0].y = y; + + sample.point[0].flags = TOUCH_ID_VALID | TOUCH_POS_VALID; + + if ((buttons & MOUSE_BUTTON_1) != 0) + { + sample.point[0].flags |= TOUCH_DOWN; + } + else + { + sample.point[0].flags |= TOUCH_UP; + } + + touch_event(session->touch.priv, &sample); + return OK; +} +