d/qwerty: Connect the debug UI to the Qwerty driver

It was necessary to add a list of xdevs to oxr_sdl2_hack_start and to
populate such list from its callees.
That includes sdl2_program.gui_program->xdevs which was not being filled
for the monado-service target.
This commit is contained in:
Mateo de Mayo 2021-03-11 12:49:42 -03:00
parent e6db1fae74
commit 12d52193da
6 changed files with 42 additions and 16 deletions

View file

@ -13,6 +13,8 @@
extern "C" {
#endif
typedef union SDL_Event SDL_Event;
/*!
* @defgroup drv_qwerty Qwerty driver
* @ingroup drv
@ -25,6 +27,13 @@ extern "C" {
struct xrt_auto_prober *
qwerty_create_auto_prober(void);
/*!
* Process an SDL_Event (like a key press) and dispatches a suitable action
* to the appropriate qwerty_device.
*/
void
qwerty_process_event(struct xrt_device **xdevs, size_t num_xdevs, SDL_Event event);
/*!
* @}
*/

View file

@ -7,6 +7,12 @@
* @ingroup drv_qwerty
*/
typedef int _silence_compiler_about_empty_translation_unit;
#include "xrt/xrt_device.h"
#include <SDL2/SDL.h>
// @todo
void
qwerty_process_event(struct xrt_device **xdevs, size_t num_xdevs, SDL_Event event)
{
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_w)
printf("W pressed and xdevs[0] = %s\n", xdevs[0]->str);
}

View file

@ -58,14 +58,6 @@ enum xrt_tracking_type
// The device(s) are tracked by external SLAM
XRT_TRACKING_TYPE_EXTERNAL_SLAM,
/* @remove: on next commit
Is it a good idea to add a new tracking type instead of using _NONE? Two reasons:
1. _NONE makes u_device_setup_tracking_origins modify tracking origins in
the app but this is not yet synced with the service
2. _NONE is not quite exact, for what I understand qwerty devices *are*
being tracked. Though I might be missunderstanding what tracking is.
*/
// The device(s) are tracked by other methods.
XRT_TRACKING_TYPE_OTHER,
};

View file

@ -44,7 +44,7 @@ extern int
oxr_sdl2_hack_create(void **out_hack);
extern void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst);
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_device **xdevs);
extern void
oxr_sdl2_hack_stop(void **hack_ptr);
@ -1074,8 +1074,13 @@ ipc_server_main(int argc, char **argv)
init_server_state(s);
struct xrt_device *xdevs[IPC_SERVER_NUM_XDEVS];
for (size_t i = 0; i < IPC_SERVER_NUM_XDEVS; i++) {
xdevs[i] = s->idevs[i].xdev;
}
/* ---- HACK ---- */
oxr_sdl2_hack_start(s->hack, s->xinst);
oxr_sdl2_hack_start(s->hack, s->xinst, xdevs);
/* ---- HACK ---- */
ret = main_loop(s);

View file

@ -57,7 +57,7 @@ extern int
oxr_sdl2_hack_create(void **out_hack);
extern void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst);
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_device **xdevs);
extern void
oxr_sdl2_hack_stop(void **hack_ptr);
@ -379,7 +379,7 @@ oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createIn
u_var_add_root((void *)inst, "XrInstance", true);
/* ---- HACK ---- */
oxr_sdl2_hack_start(inst->hack, inst->xinst);
oxr_sdl2_hack_start(inst->hack, inst->xinst, sys->xdevs);
/* ---- HACK ---- */
oxr_log(log,

View file

@ -27,7 +27,7 @@ oxr_sdl2_hack_create(void **out_hack)
}
void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst)
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_device **xdevs)
{}
void
@ -41,6 +41,8 @@ oxr_sdl2_hack_stop(void **hack)
#include "gui/gui_common.h"
#include "gui/gui_imgui.h"
#include "qwerty_interface.h"
#include <SDL2/SDL.h>
DEBUG_GET_ONCE_BOOL_OPTION(gui, "OXR_DEBUG_GUI", false)
@ -145,6 +147,9 @@ sdl2_loop(struct sdl2_program *p)
ImPlotContext *plot_ctx = ImPlot_CreateContext();
ImPlot_SetCurrentContext(plot_ctx);
// Setup qwerty driver usage
bool qwerty_enabled = true; // @todo: get from an env var
// Main loop
struct gui_imgui gui = {0};
gui.clear.r = 0.45f;
@ -162,6 +167,11 @@ sdl2_loop(struct sdl2_program *p)
while (SDL_PollEvent(&event)) {
igImGui_ImplSDL2_ProcessEvent(&event);
// Caution here, qwerty driver is being accessed by the main thread as well
if (qwerty_enabled) {
qwerty_process_event(p->base.xdevs, NUM_XDEVS, event);
}
if (event.type == SDL_QUIT) {
p->base.stopped = true;
}
@ -274,7 +284,7 @@ oxr_sdl2_hack_create(void **out_hack)
}
void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst)
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_device **xdevs)
{
struct sdl2_program *p = (struct sdl2_program *)hack;
if (p == NULL) {
@ -283,6 +293,10 @@ oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst)
xrt_instance_get_prober(xinst, &p->base.xp);
for (size_t i = 0; i < NUM_XDEVS; i++) {
p->base.xdevs[i] = xdevs[i];
}
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
U_LOG_E("Failed to init SDL2!");
return;