From 0340ae3cc874ddbe4608b650fcf84473d5c1ed83 Mon Sep 17 00:00:00 2001 From: Mateo de Mayo Date: Thu, 11 Mar 2021 11:25:00 -0300 Subject: [PATCH] d/qwerty: Add Qwerty driver initial boilerplate The Qwerty driver will emulate an HMD and controllers through the use of mouse and keyboard, and in particular, using the SDL key events generated from the debug GUI. --- CMakeLists.txt | 3 ++ meson.build | 4 ++ meson_options.txt | 2 +- src/xrt/drivers/CMakeLists.txt | 17 ++++++++ src/xrt/drivers/meson.build | 16 +++++++ src/xrt/drivers/qwerty/qwerty_device.c | 12 ++++++ src/xrt/drivers/qwerty/qwerty_device.h | 28 +++++++++++++ src/xrt/drivers/qwerty/qwerty_interface.h | 40 ++++++++++++++++++ src/xrt/drivers/qwerty/qwerty_prober.c | 51 +++++++++++++++++++++++ src/xrt/drivers/qwerty/qwerty_sdl.c | 12 ++++++ src/xrt/targets/common/CMakeLists.txt | 4 ++ src/xrt/targets/common/target_lists.c | 9 ++++ src/xrt/targets/meson.build | 4 ++ src/xrt/targets/openxr/CMakeLists.txt | 2 + src/xrt/targets/openxr/meson.build | 3 +- src/xrt/targets/service/CMakeLists.txt | 1 + src/xrt/targets/service/meson.build | 1 + tests/meson.build | 1 + 18 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 src/xrt/drivers/qwerty/qwerty_device.c create mode 100644 src/xrt/drivers/qwerty/qwerty_device.h create mode 100644 src/xrt/drivers/qwerty/qwerty_interface.h create mode 100644 src/xrt/drivers/qwerty/qwerty_prober.c create mode 100644 src/xrt/drivers/qwerty/qwerty_sdl.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c27637604..337183880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,6 +198,7 @@ cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF) cmake_dependent_option(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" ON "ANDROID" OFF) +cmake_dependent_option(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" ON "XRT_HAVE_SDL2" OFF) # You can set this from a superproject to add a driver # All drivers must be listed in here to be included in the generated header! @@ -220,6 +221,7 @@ list(APPEND AVAILABLE_DRIVERS "V4L2" "VF" "VIVE" + "QWERTY" ) @@ -356,6 +358,7 @@ message(STATUS "# DRIVER_REMOTE: ${XRT_BUILD_DRIVER_REMOTE}") message(STATUS "# DRIVER_SURVIVE: ${XRT_BUILD_DRIVER_SURVIVE}") message(STATUS "# DRIVER_VF: ${XRT_BUILD_DRIVER_VF}") message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") +message(STATUS "# DRIVER_QWERTY: ${XRT_BUILD_DRIVER_QWERTY}") message(STATUS "#####----- Config -----#####") if(XRT_FEATURE_SERVICE AND NOT XRT_FEATURE_OPENXR) diff --git a/meson.build b/meson.build index 48d4bb4ae..11b31f8ff 100644 --- a/meson.build +++ b/meson.build @@ -221,6 +221,10 @@ if not get_option('dbus').disabled() and dbus.found() endif endif +if sdl2.found() and ('auto' in drivers and 'qwerty' not in drivers) + drivers += ['qwerty'] +endif + if drivers.length() == 0 or drivers == ['auto'] error('You must enable at least one driver.') endif diff --git a/meson_options.txt b/meson_options.txt index db96cb415..58562047e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,7 +3,7 @@ option('drivers', type: 'array', - choices: ['auto', 'dummy', 'hdk', 'hydra', 'ns', 'ohmd', 'psmv', 'psvr', 'rs', 'v4l2', 'vf', 'vive', 'survive', 'daydream', 'arduino', 'remote', 'handtracking'], + choices: ['auto', 'dummy', 'hdk', 'hydra', 'ns', 'ohmd', 'psmv', 'psvr', 'rs', 'v4l2', 'vf', 'vive', 'survive', 'daydream', 'arduino', 'remote', 'handtracking', 'qwerty'], value: ['auto'], description: 'Set of drivers to build') diff --git a/src/xrt/drivers/CMakeLists.txt b/src/xrt/drivers/CMakeLists.txt index dd3988fdd..d0e3033cc 100644 --- a/src/xrt/drivers/CMakeLists.txt +++ b/src/xrt/drivers/CMakeLists.txt @@ -43,6 +43,23 @@ if(XRT_BUILD_DRIVER_DUMMY) list(APPEND ENABLED_HEADSET_DRIVERS dummy) endif() +if(XRT_BUILD_DRIVER_QWERTY) + set(QWERTY_SOURCE_FILES + qwerty/qwerty_device.c + qwerty/qwerty_device.h + qwerty/qwerty_interface.h + qwerty/qwerty_prober.c + qwerty/qwerty_sdl.c + ) + + add_library(drv_qwerty STATIC ${QWERTY_SOURCE_FILES}) + target_link_libraries(drv_qwerty PRIVATE xrt-interfaces aux_util ${SDL2_LIBRARIES}) + list(APPEND ENABLED_DRIVERS qwerty) + + add_library(drv_qwerty_includes INTERFACE) + target_include_directories(drv_qwerty_includes INTERFACE qwerty) +endif() + if(XRT_BUILD_DRIVER_HDK) set(HDK_SOURCE_FILES hdk/hdk_device.cpp diff --git a/src/xrt/drivers/meson.build b/src/xrt/drivers/meson.build index 320a13216..18b6a6a87 100644 --- a/src/xrt/drivers/meson.build +++ b/src/xrt/drivers/meson.build @@ -241,3 +241,19 @@ lib_drv_multi = static_library( dependencies: [aux], build_by_default: true, ) + +lib_drv_qwerty = static_library( + 'drv_qwerty', + files( + 'qwerty/qwerty_device.c', + 'qwerty/qwerty_device.h', + 'qwerty/qwerty_interface.h', + 'qwerty/qwerty_prober.c', + 'qwerty/qwerty_sdl.c', + ), + include_directories: xrt_include, + dependencies: [aux, sdl2], + build_by_default: 'qwerty' in drivers, +) + +drv_qwerty_include = include_directories('qwerty') diff --git a/src/xrt/drivers/qwerty/qwerty_device.c b/src/xrt/drivers/qwerty/qwerty_device.c new file mode 100644 index 000000000..5f8a9c4bf --- /dev/null +++ b/src/xrt/drivers/qwerty/qwerty_device.c @@ -0,0 +1,12 @@ +// Copyright 2021, Mateo de Mayo. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Implementation of qwerty_device related methods. + * @author Mateo de Mayo + * @ingroup drv_qwerty + */ + +typedef int _silence_compiler_about_empty_translation_unit; + +// @todo diff --git a/src/xrt/drivers/qwerty/qwerty_device.h b/src/xrt/drivers/qwerty/qwerty_device.h new file mode 100644 index 000000000..103f9ce4b --- /dev/null +++ b/src/xrt/drivers/qwerty/qwerty_device.h @@ -0,0 +1,28 @@ +// Copyright 2021, Mateo de Mayo. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Internal header for qwerty_device and its friends. + * @author Mateo de Mayo + * @ingroup drv_qwerty + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @addtogroup drv_qwerty + * @{ + */ + +// @todo + +/*! + * @} + */ + +#ifdef __cplusplus +} +#endif diff --git a/src/xrt/drivers/qwerty/qwerty_interface.h b/src/xrt/drivers/qwerty/qwerty_interface.h new file mode 100644 index 000000000..97a3d2a10 --- /dev/null +++ b/src/xrt/drivers/qwerty/qwerty_interface.h @@ -0,0 +1,40 @@ +// Copyright 2021, Mateo de Mayo. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Interface to @ref drv_qwerty. + * @author Mateo de Mayo + * @ingroup drv_qwerty + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * @defgroup drv_qwerty Qwerty driver + * @ingroup drv + * + * @brief Driver for emulated HMD and controllers through keyboard and mouse. + * @{ + */ + +//! Create an auto prober for qwerty devices. +struct xrt_auto_prober * +qwerty_create_auto_prober(void); + +/*! + * @} + */ + +/*! + * @dir drivers/qwerty + * + * @brief @ref drv_qwerty files. + */ + +#ifdef __cplusplus +} +#endif diff --git a/src/xrt/drivers/qwerty/qwerty_prober.c b/src/xrt/drivers/qwerty/qwerty_prober.c new file mode 100644 index 000000000..3b60215ce --- /dev/null +++ b/src/xrt/drivers/qwerty/qwerty_prober.c @@ -0,0 +1,51 @@ +// Copyright 2021, Mateo de Mayo. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Qwerty devices @ref xrt_auto_prober "autoprober". + * @author Mateo de Mayo + * @ingroup drv_qwerty + */ + +#include "util/u_misc.h" +#include "xrt/xrt_prober.h" + +struct qwerty_prober +{ + struct xrt_auto_prober base; +}; + +static struct qwerty_prober * +qwerty_prober(struct xrt_auto_prober *p) +{ + return (struct qwerty_prober *)p; +} + +static void +qwerty_prober_destroy(struct xrt_auto_prober *p) +{ + struct qwerty_prober *qp = qwerty_prober(p); + free(qp); +} + +static int +qwerty_prober_autoprobe(struct xrt_auto_prober *xap, + cJSON *attached_data, + bool no_hmds, + struct xrt_prober *xp, + struct xrt_device **out_xdevs) +{ + // @todo + return 0; +} + +struct xrt_auto_prober * +qwerty_create_auto_prober() +{ + struct qwerty_prober *qp = U_TYPED_CALLOC(struct qwerty_prober); + qp->base.name = "Qwerty"; + qp->base.destroy = qwerty_prober_destroy; + qp->base.lelo_dallas_autoprobe = qwerty_prober_autoprobe; + + return &qp->base; +} diff --git a/src/xrt/drivers/qwerty/qwerty_sdl.c b/src/xrt/drivers/qwerty/qwerty_sdl.c new file mode 100644 index 000000000..81f4bf80a --- /dev/null +++ b/src/xrt/drivers/qwerty/qwerty_sdl.c @@ -0,0 +1,12 @@ +// Copyright 2021, Mateo de Mayo. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Connection between user-generated SDL events and qwerty devices. + * @author Mateo de Mayo + * @ingroup drv_qwerty + */ + +typedef int _silence_compiler_about_empty_translation_unit; + +// @todo diff --git a/src/xrt/targets/common/CMakeLists.txt b/src/xrt/targets/common/CMakeLists.txt index 3f0f9e5c4..30d048686 100644 --- a/src/xrt/targets/common/CMakeLists.txt +++ b/src/xrt/targets/common/CMakeLists.txt @@ -94,6 +94,10 @@ endif() target_link_libraries(target_lists PRIVATE drv_multi) +if(XRT_BUILD_DRIVER_QWERTY) + target_link_libraries(target_lists PRIVATE drv_qwerty) +endif() + #### # Instance # diff --git a/src/xrt/targets/common/target_lists.c b/src/xrt/targets/common/target_lists.c index 0a7aa5711..8b51cdbd8 100644 --- a/src/xrt/targets/common/target_lists.c +++ b/src/xrt/targets/common/target_lists.c @@ -70,6 +70,10 @@ #include "realsense/rs_interface.h" #endif +#ifdef XRT_BUILD_DRIVER_QWERTY +#include "qwerty/qwerty_interface.h" +#endif + /*! * Each entry should be a vendor ID (VID), product ID (PID), a "found" function, * and a string literal name. @@ -162,10 +166,15 @@ xrt_auto_prober_creator target_auto_list[] = { rs_create_auto_prober, #endif +#ifdef XRT_BUILD_DRIVER_QWERTY + qwerty_create_auto_prober, +#endif + #ifdef XRT_BUILD_DRIVER_DUMMY // Dummy headset driver last. dummy_create_auto_prober, #endif + NULL, // Terminate }; diff --git a/src/xrt/targets/meson.build b/src/xrt/targets/meson.build index e063908e8..d3ebd476f 100644 --- a/src/xrt/targets/meson.build +++ b/src/xrt/targets/meson.build @@ -73,6 +73,10 @@ if 'arduino' in drivers driver_libs += [lib_drv_arduino] endif +if 'qwerty' in drivers + driver_libs += [lib_drv_qwerty] +endif + if 'remote' in drivers driver_libs += [lib_drv_remote] endif diff --git a/src/xrt/targets/openxr/CMakeLists.txt b/src/xrt/targets/openxr/CMakeLists.txt index 1d51db251..516ed71c0 100644 --- a/src/xrt/targets/openxr/CMakeLists.txt +++ b/src/xrt/targets/openxr/CMakeLists.txt @@ -42,6 +42,8 @@ if(XRT_HAVE_SDL2) st_gui imgui_impl_sdl ${SDL2_LIBRARIES} + drv_qwerty + drv_qwerty_includes ) target_include_directories(${RUNTIME_TARGET} PRIVATE ${SDL2_INCLUDE_DIRS} diff --git a/src/xrt/targets/openxr/meson.build b/src/xrt/targets/openxr/meson.build index 351070d9d..ad850f6fd 100644 --- a/src/xrt/targets/openxr/meson.build +++ b/src/xrt/targets/openxr/meson.build @@ -31,9 +31,10 @@ if sdl2.found() '../../../external/imgui/imgui/imgui_impl_sdl.cpp', '../../../external/imgui/imgui/imgui_impl_sdl.h', ] - hack_libs += lib_st_gui + hack_libs += [lib_st_gui, lib_drv_qwerty] hack_incs += [ st_include, + drv_qwerty_include, ] endif diff --git a/src/xrt/targets/service/CMakeLists.txt b/src/xrt/targets/service/CMakeLists.txt index b0c27823e..020e7a6f9 100644 --- a/src/xrt/targets/service/CMakeLists.txt +++ b/src/xrt/targets/service/CMakeLists.txt @@ -86,6 +86,7 @@ if(XRT_HAVE_SDL2) imgui_impl_sdl ${SDL2_LIBRARIES} aux_ogl + drv_qwerty_includes ) target_include_directories(monado-service PRIVATE ${SDL2_INCLUDE_DIRS} diff --git a/src/xrt/targets/service/meson.build b/src/xrt/targets/service/meson.build index 3709c5f66..b66865531 100644 --- a/src/xrt/targets/service/meson.build +++ b/src/xrt/targets/service/meson.build @@ -24,6 +24,7 @@ if sdl2.found() hack_libs += lib_st_gui hack_incs += [ st_include, + drv_qwerty_include, ] endif diff --git a/tests/meson.build b/tests/meson.build index 7502b751d..fdffbdffc 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -29,6 +29,7 @@ if sdl2.found() hack_libs += lib_st_gui hack_incs += [ st_include, + drv_qwerty_include, ] endif