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.
This commit is contained in:
Mateo de Mayo 2021-03-11 11:25:00 -03:00
parent 98886d5317
commit 0340ae3cc8
18 changed files with 208 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -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')

View file

@ -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 <mateodemayo@gmail.com>
* @ingroup drv_qwerty
*/
typedef int _silence_compiler_about_empty_translation_unit;
// @todo

View file

@ -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 <mateodemayo@gmail.com>
* @ingroup drv_qwerty
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/*!
* @addtogroup drv_qwerty
* @{
*/
// @todo
/*!
* @}
*/
#ifdef __cplusplus
}
#endif

View file

@ -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 <mateodemayo@gmail.com>
* @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

View file

@ -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 <mateodemayo@gmail.com>
* @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;
}

View file

@ -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 <mateodemayo@gmail.com>
* @ingroup drv_qwerty
*/
typedef int _silence_compiler_about_empty_translation_unit;
// @todo

View file

@ -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
#

View file

@ -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
};

View file

@ -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

View file

@ -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}

View file

@ -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

View file

@ -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}

View file

@ -24,6 +24,7 @@ if sdl2.found()
hack_libs += lib_st_gui
hack_incs += [
st_include,
drv_qwerty_include,
]
endif

View file

@ -29,6 +29,7 @@ if sdl2.found()
hack_libs += lib_st_gui
hack_incs += [
st_include,
drv_qwerty_include,
]
endif