The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/vive: Port logging to u_logging.

+57 -56
+1 -1
src/xrt/drivers/vive/vive_config.c
··· 318 318 VIVE_DEBUG(d, "eye_target_height_in_pixels: %d", d->display.eye_target_height_in_pixels); 319 319 VIVE_DEBUG(d, "eye_target_width_in_pixels: %d", d->display.eye_target_width_in_pixels); 320 320 321 - if (d->print_debug) { 321 + if (d->ll >= U_LOGGING_DEBUG) { 322 322 _print_vec3("acc_bias", &d->imu.acc_bias); 323 323 _print_vec3("acc_scale", &d->imu.acc_scale); 324 324 _print_vec3("gyro_bias", &d->imu.gyro_bias);
+2 -4
src/xrt/drivers/vive/vive_device.c
··· 30 30 31 31 #define VIVE_CLOCK_FREQ 48e6 // 48 MHz 32 32 33 - DEBUG_GET_ONCE_BOOL_OPTION(vive_spew, "VIVE_PRINT_SPEW", false) 34 - DEBUG_GET_ONCE_BOOL_OPTION(vive_debug, "VIVE_PRINT_DEBUG", false) 33 + DEBUG_GET_ONCE_LOG_OPTION(vive_log, "VIVE_LOG", U_LOGGING_WARN) 35 34 36 35 static bool 37 36 vive_mainboard_power_off(struct vive_device *d); ··· 566 565 d->base.name = XRT_DEVICE_GENERIC_HMD; 567 566 d->mainboard_dev = mainboard_dev; 568 567 d->sensors_dev = sensors_dev; 569 - d->print_spew = debug_get_bool_option_vive_spew(); 570 - d->print_debug = debug_get_bool_option_vive_debug(); 568 + d->ll = debug_get_log_option_vive_log(); 571 569 d->variant = variant; 572 570 573 571 vive_init_defaults(d);
+12 -4
src/xrt/drivers/vive/vive_device.h
··· 12 12 #include "xrt/xrt_device.h" 13 13 #include "math/m_imu_3dof.h" 14 14 #include "os/os_threading.h" 15 + #include "util/u_logging.h" 15 16 16 17 #ifdef __cplusplus 17 18 extern "C" { ··· 125 126 126 127 struct xrt_quat rot_filtered; 127 128 128 - bool print_spew; 129 - bool print_debug; 129 + enum u_logging_level ll; 130 130 bool disconnect_notified; 131 131 132 132 struct ··· 149 149 150 150 #define VIVE_SPEW(p, ...) \ 151 151 do { \ 152 - if (p->print_spew) { \ 152 + if (p->ll <= U_LOGGING_TRACE) { \ 153 153 fprintf(stderr, "%s - ", __func__); \ 154 154 fprintf(stderr, __VA_ARGS__); \ 155 155 fprintf(stderr, "\n"); \ ··· 157 157 } while (false) 158 158 #define VIVE_DEBUG(p, ...) \ 159 159 do { \ 160 - if (p->print_debug) { \ 160 + if (p->ll <= U_LOGGING_DEBUG) { \ 161 161 fprintf(stderr, "%s - ", __func__); \ 162 162 fprintf(stderr, __VA_ARGS__); \ 163 163 fprintf(stderr, "\n"); \ ··· 170 170 fprintf(stderr, __VA_ARGS__); \ 171 171 fprintf(stderr, "\n"); \ 172 172 } while (false) 173 + 174 + // clang-format off 175 + //#define VIVE_TRACE(p, ...) U_LOG_XDEV_IFL_T(&p->base, p->log_level, __VA_ARGS__) 176 + //#define VIVE_DEBUG(p, ...) U_LOG_XDEV_IFL_D(&p->base, p->log_level, __VA_ARGS__) 177 + //#define VIVE_INFO (p, ...) U_LOG_XDEV_IFL_I(&p->base, p->log_level, __VA_ARGS__) 178 + //#define VIVE_WARN (p, ...) U_LOG_XDEV_IFL_W(&p->base, p->log_level, __VA_ARGS__) 179 + //#define VIVE_ERROR(p, ...) U_LOG_XDEV_IFL_E(&p->base, p->log_level, __VA_ARGS__) 180 + // clang-format on 173 181 174 182 #ifdef __cplusplus 175 183 }
+42 -47
src/xrt/drivers/vive/vive_prober.c
··· 22 22 static const char VALVE_INDEX_MANUFACTURER_STRING[] = "Valve"; 23 23 static const char VIVE_MANUFACTURER_STRING[] = "HTC"; 24 24 25 - DEBUG_GET_ONCE_BOOL_OPTION(vive_debug, "VIVE_PRINT_DEBUG", false) 25 + DEBUG_GET_ONCE_LOG_OPTION(vive_log, "VIVE_LOG", U_LOGGING_WARN) 26 26 27 27 static int 28 28 _print_prober_string(struct xrt_prober *xp, ··· 32 32 unsigned char s[256] = {0}; 33 33 int len = xrt_prober_get_string_descriptor(xp, dev, type, s, sizeof(s)); 34 34 if (len > 0) 35 - printf("%s: %s\n", xrt_prober_string_to_string(type), s); 35 + U_LOG_I("%s: %s", xrt_prober_string_to_string(type), s); 36 36 return len; 37 37 } 38 38 39 39 static void 40 - _print_device_info(struct xrt_prober *xp, struct xrt_prober_device *dev) 40 + _print_device_info(enum u_logging_level log_level, 41 + struct xrt_prober *xp, 42 + struct xrt_prober_device *dev) 41 43 { 42 - printf("========================\n"); 43 - printf("vive: Probing Device\n"); 44 - printf("vive: Vendor %04x\n", dev->vendor_id); 45 - printf("vive: Product %04x\n", dev->product_id); 46 - printf("vive: Class %d\n", dev->usb_dev_class); 47 - printf("vive: %s\n", xrt_bus_type_to_string(dev->bus)); 44 + if (log_level > U_LOGGING_INFO) 45 + return; 46 + 47 + U_LOG_I("========================"); 48 + U_LOG_I("vive: Probing Device"); 49 + U_LOG_I("vive: Vendor %04x", dev->vendor_id); 50 + U_LOG_I("vive: Product %04x", dev->product_id); 51 + U_LOG_I("vive: Class %d", dev->usb_dev_class); 52 + U_LOG_I("vive: %s", xrt_bus_type_to_string(dev->bus)); 48 53 _print_prober_string(xp, dev, XRT_PROBER_STRING_MANUFACTURER); 49 54 _print_prober_string(xp, dev, XRT_PROBER_STRING_PRODUCT); 50 55 _print_prober_string(xp, dev, XRT_PROBER_STRING_SERIAL_NUMBER); 51 - printf("========================\n"); 56 + U_LOG_I("========================"); 52 57 } 53 58 54 59 static int ··· 56 61 struct xrt_prober_device *dev, 57 62 struct xrt_prober_device **devices, 58 63 size_t num_devices, 59 - bool print_debug, 64 + enum u_logging_level ll, 60 65 struct xrt_device **out_xdev) 61 66 { 62 - if (print_debug) 63 - _print_device_info(xp, dev); 67 + _print_device_info(ll, xp, dev); 64 68 65 69 if (!xrt_prober_match_string(xp, dev, XRT_PROBER_STRING_MANUFACTURER, 66 70 VIVE_MANUFACTURER_STRING) || ··· 77 81 d->product_id != VIVE_LIGHTHOUSE_FPGA_RX) 78 82 continue; 79 83 80 - if (print_debug) 81 - _print_device_info(xp, d); 84 + _print_device_info(ll, xp, d); 82 85 83 86 int result = 84 87 xrt_prober_open_hid_interface(xp, d, 0, &sensors_dev); 85 88 if (result != 0) { 86 - VIVE_ERROR("Could not open Vive sensors device."); 89 + U_LOG_E("Could not open Vive sensors device."); 87 90 return -1; 88 91 } 89 92 break; 90 93 } 91 94 92 95 if (sensors_dev == NULL) { 93 - VIVE_ERROR("Could not find Vive sensors device."); 96 + U_LOG_E("Could not find Vive sensors device."); 94 97 return -1; 95 98 } 96 99 ··· 98 101 99 102 int result = xrt_prober_open_hid_interface(xp, dev, 0, &mainboard_dev); 100 103 if (result != 0) { 101 - VIVE_ERROR("Could not open Vive mainboard device."); 104 + U_LOG_E("Could not open Vive mainboard device."); 102 105 free(sensors_dev); 103 106 return -1; 104 107 } ··· 120 123 struct xrt_prober_device *dev, 121 124 struct xrt_prober_device **devices, 122 125 size_t num_devices, 123 - bool print_debug, 126 + enum u_logging_level ll, 124 127 struct xrt_device **out_xdev) 125 128 { 126 - if (print_debug) 127 - _print_device_info(xp, dev); 129 + _print_device_info(ll, xp, dev); 128 130 129 131 if (!xrt_prober_match_string(xp, dev, XRT_PROBER_STRING_MANUFACTURER, 130 132 VIVE_MANUFACTURER_STRING) || 131 133 !xrt_prober_match_string(xp, dev, XRT_PROBER_STRING_PRODUCT, 132 134 VIVE_PRO_PRODUCT_STRING)) { 133 - if (print_debug) 134 - printf("Vive Pro manufacturer string did not match.\n"); 135 + U_LOG_D("Vive Pro manufacturer string did not match."); 135 136 return -1; 136 137 } 137 138 ··· 143 144 d->product_id != VIVE_PRO_LHR_PID) 144 145 continue; 145 146 146 - if (print_debug) 147 - _print_device_info(xp, d); 147 + _print_device_info(ll, xp, d); 148 148 149 149 int result = 150 150 xrt_prober_open_hid_interface(xp, d, 0, &sensors_dev); 151 151 if (result != 0) { 152 - VIVE_ERROR("Could not open Vive sensors device."); 152 + U_LOG_E("Could not open Vive sensors device."); 153 153 return -1; 154 154 } 155 155 break; 156 156 } 157 157 158 158 if (sensors_dev == NULL) { 159 - VIVE_ERROR("Could not find Vive Pro sensors device."); 159 + U_LOG_E("Could not find Vive Pro sensors device."); 160 160 return -1; 161 161 } 162 162 ··· 164 164 165 165 int result = xrt_prober_open_hid_interface(xp, dev, 0, &mainboard_dev); 166 166 if (result != 0) { 167 - VIVE_ERROR("Could not open Vive mainboard device."); 167 + U_LOG_E("Could not open Vive mainboard device."); 168 168 free(sensors_dev); 169 169 return -1; 170 170 } ··· 186 186 struct xrt_prober_device *dev, 187 187 struct xrt_prober_device **devices, 188 188 size_t num_devices, 189 - bool print_debug, 189 + enum u_logging_level ll, 190 190 struct xrt_device **out_xdev) 191 191 { 192 - if (print_debug) 193 - _print_device_info(xp, dev); 192 + _print_device_info(ll, xp, dev); 194 193 195 194 if (!xrt_prober_match_string(xp, dev, XRT_PROBER_STRING_MANUFACTURER, 196 195 VALVE_INDEX_MANUFACTURER_STRING) || 197 196 !xrt_prober_match_string(xp, dev, XRT_PROBER_STRING_PRODUCT, 198 197 VALVE_INDEX_PRODUCT_STRING)) { 199 - if (print_debug) 200 - printf( 201 - "Valve Index manufacturer string did not match.\n"); 198 + U_LOG_D("Valve Index manufacturer string did not match."); 202 199 return -1; 203 200 } 204 201 205 202 struct os_hid_device *sensors_dev = NULL; 206 203 int result = xrt_prober_open_hid_interface(xp, dev, 0, &sensors_dev); 207 204 if (result != 0) { 208 - VIVE_ERROR("Could not open Index sensors device."); 205 + U_LOG_E("Could not open Index sensors device."); 209 206 return -1; 210 207 } 211 208 struct vive_device *d = ··· 229 226 { 230 227 struct xrt_prober_device *dev = devices[index]; 231 228 232 - bool print_debug = debug_get_bool_option_vive_debug(); 229 + enum u_logging_level ll = debug_get_log_option_vive_log(); 233 230 234 - if (print_debug) 235 - _print_device_info(xp, dev); 231 + _print_device_info(ll, xp, dev); 236 232 237 233 if (!xrt_prober_can_open(xp, dev)) { 238 - VIVE_ERROR("Could not open Vive device."); 234 + U_LOG_E("Could not open Vive device."); 239 235 return -1; 240 236 } 241 237 242 238 switch (dev->product_id) { 243 239 case VIVE_PID: 244 - return init_vive1(xp, dev, devices, num_devices, print_debug, 245 - out_xdev); 240 + return init_vive1(xp, dev, devices, num_devices, ll, out_xdev); 246 241 case VIVE_PRO_MAINBOARD_PID: 247 - return init_vive_pro(xp, dev, devices, num_devices, print_debug, 242 + return init_vive_pro(xp, dev, devices, num_devices, ll, 248 243 out_xdev); 249 244 case VIVE_PRO_LHR_PID: 250 - return init_valve_index(xp, dev, devices, num_devices, 251 - print_debug, out_xdev); 245 + return init_valve_index(xp, dev, devices, num_devices, ll, 246 + out_xdev); 252 247 default: 253 - VIVE_ERROR("No product ids matched %.4x\n", dev->product_id); 248 + U_LOG_E("No product ids matched %.4x", dev->product_id); 254 249 return -1; 255 250 } 256 251 ··· 273 268 struct os_hid_device *controller_hid = NULL; 274 269 ret = xp->open_hid_interface(xp, dev, 0, &controller_hid); 275 270 if (ret != 0) { 276 - VIVE_ERROR("Could not open Vive controller device."); 271 + U_LOG_E("Could not open Vive controller device."); 277 272 return -1; 278 273 } 279 274 ··· 285 280 dev->product_id == VIVE_WATCHMAN_DONGLE_GEN2) { 286 281 gen = WATCHMAN_GEN2; 287 282 } else { 288 - VIVE_ERROR("Unknown watchman gen"); 283 + U_LOG_E("Unknown watchman gen"); 289 284 } 290 285 291 286 struct vive_controller_device *d =