d/psvr: Switch to logging API

This commit is contained in:
Jakob Bornecrantz 2020-10-26 22:41:49 +00:00
parent 6fd1e7b36c
commit d72776b82c
3 changed files with 18 additions and 50 deletions

View file

@ -42,6 +42,8 @@
*/
DEBUG_GET_ONCE_BOOL_OPTION(psvr_disco, "PSVR_DISCO", false)
#define PSVR_DEBUG(p, ...) U_LOG_XDEV_IFL_D(&p->base, p->log_level, __VA_ARGS__)
#define PSVR_ERROR(p, ...) U_LOG_XDEV_IFL_E(&p->base, p->log_level, __VA_ARGS__)
#define FEATURE_BUFFER_SIZE 256
@ -85,8 +87,7 @@ struct psvr_device
bool powered_on;
bool in_vr_mode;
bool print_spew;
bool print_debug;
enum u_logging_level log_level;
struct
{
@ -1010,8 +1011,7 @@ struct xrt_device *
psvr_device_create(struct hid_device_info *hmd_handle_info,
struct hid_device_info *hmd_control_info,
struct xrt_prober *xp,
bool print_spew,
bool print_debug)
enum u_logging_level log_level)
{
enum u_device_alloc_flags flags = (enum u_device_alloc_flags)(
U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE);
@ -1019,8 +1019,7 @@ psvr_device_create(struct hid_device_info *hmd_handle_info,
U_DEVICE_ALLOCATE(struct psvr_device, flags, 1, 0);
int ret;
psvr->print_spew = print_spew;
psvr->print_debug = print_debug;
psvr->log_level = log_level;
psvr->base.update_inputs = psvr_device_update_inputs;
psvr->base.get_tracked_pose = psvr_device_get_tracked_pose;
psvr->base.get_view_pose = psvr_device_get_view_pose;
@ -1136,15 +1135,14 @@ psvr_device_create(struct hid_device_info *hmd_handle_info,
u_var_add_u8(psvr, &psvr->wants.leds[6], "Led G");
u_var_add_u8(psvr, &psvr->wants.leds[7], "Led H");
u_var_add_u8(psvr, &psvr->wants.leds[8], "Led I");
u_var_add_bool(psvr, &psvr->print_debug, "Debug");
u_var_add_bool(psvr, &psvr->print_spew, "Spew");
u_var_add_log_level(psvr, &psvr->log_level, "Log level");
// clang-format on
/*
* Finishing touches.
*/
if (psvr->print_debug) {
if (psvr->log_level <= U_LOGGING_DEBUG) {
u_device_dump_config(&psvr->base, __func__, "Sony PSVR");
}

View file

@ -15,6 +15,8 @@
#include "xrt/xrt_device.h"
#include "xrt/xrt_prober.h"
#include "util/u_logging.h"
#include <hidapi.h>
@ -125,8 +127,7 @@ struct xrt_device *
psvr_device_create(struct hid_device_info *hmd_handle_info,
struct hid_device_info *hmd_control_info,
struct xrt_prober *xp,
bool print_spew,
bool print_debug);
enum u_logging_level log_level);
bool
psvr_parse_sensor_packet(struct psvr_parsed_sensor *sensor,
@ -139,37 +140,6 @@ psvr_parse_status_packet(struct psvr_parsed_status *status,
int size);
/*
*
* Printing functions.
*
*/
#define PSVR_SPEW(p, ...) \
do { \
if (p->print_spew) { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (false)
#define PSVR_DEBUG(p, ...) \
do { \
if (p->print_debug) { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (false)
#define PSVR_ERROR(p, ...) \
do { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (false)
#ifdef __cplusplus
}
#endif

View file

@ -17,6 +17,7 @@
#include "util/u_misc.h"
#include "util/u_debug.h"
#include "util/u_logging.h"
#include "psvr_interface.h"
#include "psvr_device.h"
@ -30,8 +31,9 @@
// Should the experimental PSVR driver be enabled.
DEBUG_GET_ONCE_BOOL_OPTION(psvr_enable, "PSVR_ENABLE", true)
DEBUG_GET_ONCE_BOOL_OPTION(psvr_spew, "PSVR_PRINT_SPEW", false)
DEBUG_GET_ONCE_BOOL_OPTION(psvr_debug, "PSVR_PRINT_DEBUG", false)
DEBUG_GET_ONCE_LOG_OPTION(psvr_log, "DUMMY_LOG", U_LOGGING_WARN)
#define PSVR_DEBUG(p, ...) U_LOG_IFL_D(p->log_level, __VA_ARGS__)
/*!
* PSVR prober struct.
@ -43,9 +45,9 @@ struct psvr_prober
{
struct xrt_auto_prober base;
bool print_spew;
bool print_debug;
bool enabled;
enum u_logging_level log_level;
};
@ -104,8 +106,7 @@ psvr_prober_autoprobe(struct xrt_auto_prober *xap,
if (info_control != NULL && info_handle != NULL) {
if (ppsvr->enabled) {
dev = psvr_device_create(info_handle, info_control, xp,
ppsvr->print_spew,
ppsvr->print_debug);
ppsvr->log_level);
} else {
PSVR_DEBUG(ppsvr,
"Found a PSVR hmd but driver is disabled");
@ -132,8 +133,7 @@ psvr_create_auto_prober(void)
ppsvr->base.destroy = psvr_prober_destroy;
ppsvr->base.lelo_dallas_autoprobe = psvr_prober_autoprobe;
ppsvr->enabled = debug_get_bool_option_psvr_enable();
ppsvr->print_spew = debug_get_bool_option_psvr_spew();
ppsvr->print_debug = debug_get_bool_option_psvr_debug();
ppsvr->log_level = debug_get_log_option_psvr_log();
return &ppsvr->base;
}