The open source OpenXR runtime
0
fork

Configure Feed

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

d/wmr: Set default camera gain

Add API for gain control on headset cameras,
and use it to set a mid-range default exposure gain

authored by

Jan Schmidt and committed by
Jakob Bornecrantz
6bb29724 0da1bd74

+55 -8
+51 -8
src/xrt/drivers/wmr/wmr_camera.c
··· 32 32 33 33 #define NUM_XFERS 2 34 34 35 - struct wmr_camera_cmd 35 + #define WMR_CAMERA_CMD_GAIN 0x80 36 + #define WMR_CAMERA_CMD_ON 0x81 37 + #define WMR_CAMERA_CMD_OFF 0x82 38 + 39 + #define DEFAULT_GAIN 0x60 40 + 41 + struct wmr_camera_active_cmd 36 42 { 37 43 __le32 magic; 38 44 __le32 len; 39 45 __le32 cmd; 40 46 } __attribute__((packed)); 41 47 48 + struct wmr_camera_gain_cmd 49 + { 50 + __le32 magic; 51 + __le32 len; 52 + __le16 cmd; 53 + __le16 camera_id; 54 + __le16 const_6000; 55 + __le16 gain; /* observed 82 to 255 */ 56 + __le16 camera_id2; /* same as camera_id */ 57 + } __attribute__((packed)); 58 + 42 59 struct wmr_camera 43 60 { 44 61 libusb_context *ctx; ··· 186 203 } 187 204 188 205 static int 189 - wmr_set_active(struct wmr_camera *cam, bool active) 206 + wmr_camera_set_active(struct wmr_camera *cam, bool active) 190 207 { 191 - struct wmr_camera_cmd cmd = {.magic = __cpu_to_le32(WMR_MAGIC), 192 - .len = __cpu_to_le32(sizeof(struct wmr_camera_cmd)), 193 - .cmd = __cpu_to_le32(active ? 0x81 : 0x82)}; 208 + struct wmr_camera_active_cmd cmd = {.magic = __cpu_to_le32(WMR_MAGIC), 209 + .len = __cpu_to_le32(sizeof(struct wmr_camera_active_cmd)), 210 + .cmd = __cpu_to_le32(active ? WMR_CAMERA_CMD_ON : WMR_CAMERA_CMD_OFF)}; 194 211 195 212 return wmr_camera_send(cam, (uint8_t *)&cmd, sizeof(cmd)); 196 213 } ··· 351 368 goto fail; 352 369 } 353 370 354 - res = wmr_set_active(cam, false); 371 + res = wmr_camera_set_active(cam, false); 355 372 if (res < 0) 356 373 goto fail; 357 374 358 - res = wmr_set_active(cam, true); 375 + res = wmr_camera_set_active(cam, true); 359 376 if (res < 0) 360 377 goto fail; 378 + 379 + for (i = 0; i < cam->n_configs; i++) { 380 + struct wmr_camera_config *config = cam->configs + i; 381 + if (config->purpose != WMR_CAMERA_PURPOSE_HEAD_TRACKING) 382 + continue; 383 + 384 + res = wmr_camera_set_gain(cam, config->location, DEFAULT_GAIN); 385 + if (res < 0) { 386 + WMR_CAM_ERROR(cam, "Failed to set initial gain for camera %d", i); 387 + goto fail; 388 + } 389 + } 361 390 362 391 for (i = 0; i < NUM_XFERS; i++) { 363 392 uint8_t *recv_buf = malloc(cam->xfer_size); ··· 395 424 libusb_cancel_transfer(cam->xfers[i]); 396 425 } 397 426 398 - res = wmr_set_active(cam, false); 427 + res = wmr_camera_set_active(cam, false); 399 428 if (res < 0) 400 429 goto fail; 401 430 ··· 408 437 WMR_CAM_ERROR(cam, "Error stopping camera input: %s", libusb_error_name(res)); 409 438 return false; 410 439 } 440 + 441 + int 442 + wmr_camera_set_gain(struct wmr_camera *cam, uint8_t camera_id, uint8_t gain) 443 + { 444 + struct wmr_camera_gain_cmd cmd = {.magic = __cpu_to_le32(WMR_MAGIC), 445 + .len = __cpu_to_le32(sizeof(struct wmr_camera_gain_cmd)), 446 + .cmd = __cpu_to_le16(WMR_CAMERA_CMD_GAIN), 447 + .camera_id = __cpu_to_le16(camera_id), 448 + .const_6000 = __cpu_to_le16(6000), 449 + .gain = __cpu_to_le16(gain), 450 + .camera_id2 = __cpu_to_le16(camera_id)}; 451 + 452 + return wmr_camera_send(cam, (uint8_t *)&cmd, sizeof(cmd)); 453 + }
+4
src/xrt/drivers/wmr/wmr_camera.h
··· 31 31 wmr_camera_start(struct wmr_camera *cam, struct wmr_camera_config *cam_configs, int n_configs); 32 32 bool 33 33 wmr_camera_stop(struct wmr_camera *cam); 34 + int 35 + wmr_camera_set_gain(struct wmr_camera *cam, uint8_t camera_id, uint8_t exposure); 36 + 34 37 #else 35 38 36 39 /* Stubs to disable camera functions without libusb */ ··· 38 41 #define wmr_camera_free(cam) 39 42 #define wmr_camera_start(cam, cam_configs, n_configs) false 40 43 #define wmr_camera_stop(cam) false 44 + #define wmr_camera_set_gain(cam, camera_id, exposure) -1 41 45 42 46 #endif 43 47