From a89c8309c7a50198f1172062d9eaf1e4bd33b20e Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 20 Aug 2021 13:02:49 +0100 Subject: [PATCH] u/vive: Pass in logging level to parse function --- src/xrt/auxiliary/vive/vive_config.c | 6 ++++-- src/xrt/auxiliary/vive/vive_config.h | 4 ++-- src/xrt/drivers/survive/survive_driver.c | 18 ++++++++++-------- src/xrt/drivers/vive/vive_controller.c | 6 ++---- src/xrt/drivers/vive/vive_device.c | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/xrt/auxiliary/vive/vive_config.c b/src/xrt/auxiliary/vive/vive_config.c index 8ce77c5bc..f133d3b08 100644 --- a/src/xrt/auxiliary/vive/vive_config.c +++ b/src/xrt/auxiliary/vive/vive_config.c @@ -208,8 +208,9 @@ vive_init_defaults(struct vive_config *d) } bool -vive_config_parse(struct vive_config *d, char *json_string) +vive_config_parse(struct vive_config *d, char *json_string, enum u_logging_level ll) { + d->ll = ll; vive_init_defaults(d); VIVE_DEBUG(d, "JSON config:\n%s", json_string); @@ -355,8 +356,9 @@ vive_config_teardown(struct vive_config *config) } bool -vive_config_parse_controller(struct vive_controller_config *d, char *json_string) +vive_config_parse_controller(struct vive_controller_config *d, char *json_string, enum u_logging_level ll) { + d->ll = ll; VIVE_DEBUG(d, "JSON config:\n%s", json_string); cJSON *json = cJSON_Parse(json_string); diff --git a/src/xrt/auxiliary/vive/vive_config.h b/src/xrt/auxiliary/vive/vive_config.h index 94daa246f..9b81cf6b7 100644 --- a/src/xrt/auxiliary/vive/vive_config.h +++ b/src/xrt/auxiliary/vive/vive_config.h @@ -149,7 +149,7 @@ struct vive_controller_config }; bool -vive_config_parse(struct vive_config *d, char *json_string); +vive_config_parse(struct vive_config *d, char *json_string, enum u_logging_level ll); /*! * Free any allocated resources on this config. @@ -160,4 +160,4 @@ vive_config_teardown(struct vive_config *d); struct vive_controller_device; bool -vive_config_parse_controller(struct vive_controller_config *d, char *json_string); +vive_config_parse_controller(struct vive_controller_config *d, char *json_string, enum u_logging_level ll); diff --git a/src/xrt/drivers/survive/survive_driver.c b/src/xrt/drivers/survive/survive_driver.c index bc1294fc5..3d805ab43 100644 --- a/src/xrt/drivers/survive/survive_driver.c +++ b/src/xrt/drivers/survive/survive_driver.c @@ -796,14 +796,20 @@ compute_distortion(struct xrt_device *xdev, int view, float u, float v, struct x } static bool -_create_hmd_device(struct survive_system *sys, const struct SurviveSimpleObject *sso, struct vive_config *config) +_create_hmd_device(struct survive_system *sys, const struct SurviveSimpleObject *sso, char *conf_str) { + enum u_device_alloc_flags flags = (enum u_device_alloc_flags)U_DEVICE_ALLOC_HMD; int inputs = 1; int outputs = 0; struct survive_device *survive = U_DEVICE_ALLOCATE(struct survive_device, flags, inputs, outputs); + if (!vive_config_parse(&survive->hmd.config, conf_str, sys->ll)) { + free(survive); + return false; + } + sys->hmd = survive; survive->sys = sys; survive->survive_obj = sso; @@ -822,8 +828,6 @@ _create_hmd_device(struct survive_system *sys, const struct SurviveSimpleObject survive->base.hmd->blend_modes[idx++] = XRT_BLEND_MODE_OPAQUE; survive->base.hmd->num_blend_modes = idx; - survive->hmd.config = *config; - switch (survive->hmd.config.variant) { case VIVE_VARIANT_VIVE: snprintf(survive->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive (libsurvive)"); break; case VIVE_VARIANT_PRO: snprintf(survive->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive Pro (libsurvive)"); break; @@ -1150,13 +1154,11 @@ add_device(struct survive_system *ss, const struct SurviveSimpleConfigEvent *e) if (type == SurviveSimpleObject_HMD) { - struct vive_config config = {.ll = ss->ll}; - vive_config_parse(&config, conf_str); - _create_hmd_device(ss, sso, &config); + _create_hmd_device(ss, sso, conf_str); } else if (type == SurviveSimpleObject_OBJECT) { - struct vive_controller_config config = {.ll = ss->ll}; - vive_config_parse_controller(&config, conf_str); + struct vive_controller_config config = {0}; + vive_config_parse_controller(&config, conf_str, ss->ll); switch (config.variant) { case CONTROLLER_VIVE_WAND: diff --git a/src/xrt/drivers/vive/vive_controller.c b/src/xrt/drivers/vive/vive_controller.c index feb8bcb01..6c401daca 100644 --- a/src/xrt/drivers/vive/vive_controller.c +++ b/src/xrt/drivers/vive/vive_controller.c @@ -1,5 +1,5 @@ -// Copyright 2020, Collabora, Ltd. // Copyright 2016 Philipp Zabel +// Copyright 2020-2021, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -1086,10 +1086,8 @@ vive_controller_create(struct os_hid_device *controller_hid, enum watchman_gen w // successful config parsing determines d->config.variant char *config = vive_read_config(d->controller_hid); - d->config.ll = d->ll; - if (config != NULL) { - vive_config_parse_controller(&d->config, config); + vive_config_parse_controller(&d->config, config, d->ll); free(config); } else { VIVE_ERROR(d, "Could not get Vive controller config\n"); diff --git a/src/xrt/drivers/vive/vive_device.c b/src/xrt/drivers/vive/vive_device.c index 0866fdf97..23d13b0ff 100644 --- a/src/xrt/drivers/vive/vive_device.c +++ b/src/xrt/drivers/vive/vive_device.c @@ -777,7 +777,7 @@ vive_device_create(struct os_hid_device *mainboard_dev, d->config.ll = d->ll; // usb connected HMD variant is known because of USB id, config parsing relies on it. if (config != NULL) { - vive_config_parse(&d->config, config); + vive_config_parse(&d->config, config, d->ll); free(config); }