The open source OpenXR runtime
0
fork

Configure Feed

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

d/vive: Factor out config into separate struct

authored by

Christoph Haag and committed by
Jakob Bornecrantz
e4b0e628 8c6075e3

+149 -130
+5 -5
src/xrt/drivers/vive/vive.h
··· 16 16 * 17 17 */ 18 18 19 - #define VIVE_TRACE(d, ...) U_LOG_XDEV_IFL_T(&d->base, d->ll, __VA_ARGS__) 20 - #define VIVE_DEBUG(d, ...) U_LOG_XDEV_IFL_D(&d->base, d->ll, __VA_ARGS__) 21 - #define VIVE_INFO(d, ...) U_LOG_XDEV_IFL_I(&d->base, d->ll, __VA_ARGS__) 22 - #define VIVE_WARN(d, ...) U_LOG_XDEV_IFL_W(&d->base, d->ll, __VA_ARGS__) 23 - #define VIVE_ERROR(d, ...) U_LOG_XDEV_IFL_E(&d->base, d->ll, __VA_ARGS__) 19 + #define VIVE_TRACE(d, ...) U_LOG_IFL_T(d->ll, __VA_ARGS__) 20 + #define VIVE_DEBUG(d, ...) U_LOG_IFL_D(d->ll, __VA_ARGS__) 21 + #define VIVE_INFO(d, ...) U_LOG_IFL_I(d->ll, __VA_ARGS__) 22 + #define VIVE_WARN(d, ...) U_LOG_IFL_W(d->ll, __VA_ARGS__) 23 + #define VIVE_ERROR(d, ...) U_LOG_IFL_E(d->ll, __VA_ARGS__)
+3 -3
src/xrt/drivers/vive/vive_config.c
··· 56 56 } 57 57 58 58 static void 59 - _get_distortion_properties(struct vive_device *d, const cJSON *eye_transform_json, uint8_t eye) 59 + _get_distortion_properties(struct vive_config *d, const cJSON *eye_transform_json, uint8_t eye) 60 60 { 61 61 const cJSON *eye_json = cJSON_GetArrayItem(eye_transform_json, eye); 62 62 if (eye_json == NULL) { ··· 97 97 } 98 98 99 99 static void 100 - _get_lighthouse(struct vive_device *d, const cJSON *json) 100 + _get_lighthouse(struct vive_config *d, const cJSON *json) 101 101 { 102 102 const cJSON *lh = cJSON_GetObjectItemCaseSensitive(json, "lighthouse_config"); 103 103 if (lh == NULL) { ··· 177 177 } 178 178 179 179 bool 180 - vive_config_parse(struct vive_device *d, char *json_string) 180 + vive_config_parse(struct vive_config *d, char *json_string) 181 181 { 182 182 VIVE_DEBUG(d, "JSON config:\n%s", json_string); 183 183
+87 -2
src/xrt/drivers/vive/vive_config.h
··· 11 11 12 12 #include <stdbool.h> 13 13 14 - struct vive_device; 14 + #include "xrt/xrt_defines.h" 15 + #include "util/u_logging.h" 16 + #include "util/u_distortion_mesh.h" 17 + 18 + enum VIVE_VARIANT 19 + { 20 + VIVE_UNKNOWN = 0, 21 + VIVE_VARIANT_VIVE, 22 + VIVE_VARIANT_PRO, 23 + VIVE_VARIANT_INDEX 24 + }; 25 + 26 + /*! 27 + * A single lighthouse senosor point and normal, in IMU space. 28 + */ 29 + struct lh_sensor 30 + { 31 + struct xrt_vec3 pos; 32 + uint32_t _pad0; 33 + struct xrt_vec3 normal; 34 + uint32_t _pad1; 35 + }; 36 + 37 + /*! 38 + * A lighthouse consisting of sensors. 39 + * 40 + * All sensors are placed in IMU space. 41 + */ 42 + struct lh_model 43 + { 44 + struct lh_sensor *sensors; 45 + size_t num_sensors; 46 + }; 47 + 48 + struct vive_config 49 + { 50 + //! log level accessed by the config parser 51 + enum u_logging_level ll; 52 + 53 + enum VIVE_VARIANT variant; 54 + 55 + struct 56 + { 57 + double acc_range; 58 + double gyro_range; 59 + struct xrt_vec3 acc_bias; 60 + struct xrt_vec3 acc_scale; 61 + struct xrt_vec3 gyro_bias; 62 + struct xrt_vec3 gyro_scale; 63 + 64 + //! IMU position in tracking space. 65 + struct xrt_pose trackref; 66 + } imu; 67 + 68 + struct 69 + { 70 + double lens_separation; 71 + double persistence; 72 + int eye_target_height_in_pixels; 73 + int eye_target_width_in_pixels; 74 + 75 + struct xrt_quat rot[2]; 76 + 77 + //! Head position in tracking space. 78 + struct xrt_pose trackref; 79 + //! Head position in IMU space. 80 + struct xrt_pose imuref; 81 + } display; 82 + 83 + struct 84 + { 85 + uint32_t display_firmware_version; 86 + uint32_t firmware_version; 87 + uint8_t hardware_revision; 88 + uint8_t hardware_version_micro; 89 + uint8_t hardware_version_minor; 90 + uint8_t hardware_version_major; 91 + char mb_serial_number[32]; 92 + char model_number[32]; 93 + char device_serial_number[32]; 94 + } firmware; 95 + 96 + struct u_vive_values distortion[2]; 97 + 98 + struct lh_model lh; 99 + }; 15 100 16 101 bool 17 - vive_config_parse(struct vive_device *d, char *json_string); 102 + vive_config_parse(struct vive_config *d, char *json_string); 18 103 19 104 20 105 struct vive_controller_device;
+52 -49
src/xrt/drivers/vive/vive_device.c
··· 26 26 #include "vive.h" 27 27 #include "vive_device.h" 28 28 #include "vive_protocol.h" 29 - #include "vive_config.h" 30 29 31 30 32 31 #define VIVE_CLOCK_FREQ 48e6 // 48 MHz ··· 71 70 d->watchman_dev = NULL; 72 71 } 73 72 74 - if (d->lh.sensors != NULL) { 75 - free(d->lh.sensors); 76 - d->lh.sensors = NULL; 77 - d->lh.num_sensors = 0; 73 + if (d->config.lh.sensors != NULL) { 74 + free(d->config.lh.sensors); 75 + d->config.lh.sensors = NULL; 76 + d->config.lh.num_sensors = 0; 78 77 } 79 78 80 79 // Remove the variable tracking. ··· 137 136 struct xrt_pose pose = {{0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f}}; 138 137 bool adjust = view_index == 0; 139 138 140 - pose.orientation = d->display.rot[view_index]; 139 + pose.orientation = d->config.display.rot[view_index]; 141 140 pose.position.x = eye_relation->x / 2.0f; 142 141 pose.position.y = eye_relation->y / 2.0f; 143 142 pose.position.z = eye_relation->z / 2.0f; ··· 178 177 179 178 edid_vid = __be16_to_cpu(report.edid_vid); 180 179 181 - d->firmware.display_firmware_version = __le32_to_cpu(report.display_firmware_version); 180 + d->config.firmware.display_firmware_version = __le32_to_cpu(report.display_firmware_version); 182 181 183 182 VIVE_INFO(d, "EDID Manufacturer ID: %c%c%c, Product code: 0x%04x", '@' + (edid_vid >> 10), 184 183 '@' + ((edid_vid >> 5) & 0x1f), '@' + (edid_vid & 0x1f), __le16_to_cpu(report.edid_pid)); 185 - VIVE_INFO(d, "Display firmware version: %u", d->firmware.display_firmware_version); 184 + VIVE_INFO(d, "Display firmware version: %u", d->config.firmware.display_firmware_version); 186 185 187 186 return 0; 188 187 } ··· 316 315 (int16_t)__le16_to_cpu(sample->acc[2]), 317 316 }; 318 317 319 - scale = (float)d->imu.acc_range / 32768.0f; 318 + scale = (float)d->config.imu.acc_range / 32768.0f; 320 319 struct xrt_vec3 acceleration = { 321 - scale * d->imu.acc_scale.x * acc[0] - d->imu.acc_bias.x, 322 - scale * d->imu.acc_scale.y * acc[1] - d->imu.acc_bias.y, 323 - scale * d->imu.acc_scale.z * acc[2] - d->imu.acc_bias.z, 320 + scale * d->config.imu.acc_scale.x * acc[0] - d->config.imu.acc_bias.x, 321 + scale * d->config.imu.acc_scale.y * acc[1] - d->config.imu.acc_bias.y, 322 + scale * d->config.imu.acc_scale.z * acc[2] - d->config.imu.acc_bias.z, 324 323 }; 325 324 326 325 int16_t gyro[3] = { ··· 329 328 (int16_t)__le16_to_cpu(sample->gyro[2]), 330 329 }; 331 330 332 - scale = (float)d->imu.gyro_range / 32768.0f; 331 + scale = (float)d->config.imu.gyro_range / 32768.0f; 333 332 struct xrt_vec3 angular_velocity = { 334 - scale * d->imu.gyro_scale.x * gyro[0] - d->imu.gyro_bias.x, 335 - scale * d->imu.gyro_scale.y * gyro[1] - d->imu.gyro_bias.y, 336 - scale * d->imu.gyro_scale.z * gyro[2] - d->imu.gyro_bias.z, 333 + scale * d->config.imu.gyro_scale.x * gyro[0] - d->config.imu.gyro_bias.x, 334 + scale * d->config.imu.gyro_scale.y * gyro[1] - d->config.imu.gyro_bias.y, 335 + scale * d->config.imu.gyro_scale.z * gyro[2] - d->config.imu.gyro_bias.z, 337 336 }; 338 337 339 338 VIVE_TRACE(d, "ACC %f %f %f", acceleration.x, acceleration.y, acceleration.z); ··· 720 719 void 721 720 vive_init_defaults(struct vive_device *d) 722 721 { 723 - d->display.eye_target_width_in_pixels = 1080; 724 - d->display.eye_target_height_in_pixels = 1200; 722 + d->config.display.eye_target_width_in_pixels = 1080; 723 + d->config.display.eye_target_height_in_pixels = 1200; 725 724 726 - d->display.rot[0].w = 1.0f; 727 - d->display.rot[1].w = 1.0f; 725 + d->config.display.rot[0].w = 1.0f; 726 + d->config.display.rot[1].w = 1.0f; 728 727 729 - d->imu.gyro_range = 8.726646f; 730 - d->imu.acc_range = 39.226600f; 728 + d->config.imu.gyro_range = 8.726646f; 729 + d->config.imu.acc_range = 39.226600f; 731 730 732 - d->imu.acc_scale.x = 1.0f; 733 - d->imu.acc_scale.y = 1.0f; 734 - d->imu.acc_scale.z = 1.0f; 731 + d->config.imu.acc_scale.x = 1.0f; 732 + d->config.imu.acc_scale.y = 1.0f; 733 + d->config.imu.acc_scale.z = 1.0f; 735 734 736 - d->imu.gyro_scale.x = 1.0f; 737 - d->imu.gyro_scale.y = 1.0f; 738 - d->imu.gyro_scale.z = 1.0f; 735 + d->config.imu.gyro_scale.x = 1.0f; 736 + d->config.imu.gyro_scale.y = 1.0f; 737 + d->config.imu.gyro_scale.z = 1.0f; 739 738 740 739 d->rot_filtered.w = 1.0f; 741 740 742 741 for (int view = 0; view < 2; view++) { 743 - d->distortion[view].aspect_x_over_y = 0.89999997615814209f; 744 - d->distortion[view].grow_for_undistort = 0.5f; 745 - d->distortion[view].undistort_r2_cutoff = 1.0f; 742 + d->config.distortion[view].aspect_x_over_y = 0.89999997615814209f; 743 + d->config.distortion[view].grow_for_undistort = 0.5f; 744 + d->config.distortion[view].undistort_r2_cutoff = 1.0f; 746 745 } 747 746 } 748 747 ··· 751 750 compute_distortion(struct xrt_device *xdev, int view, float u, float v, struct xrt_uv_triplet *result) 752 751 { 753 752 struct vive_device *d = vive_device(xdev); 754 - return u_compute_distortion_vive(&d->distortion[view], u, v, result); 753 + return u_compute_distortion_vive(&d->config.distortion[view], u, v, result); 755 754 } 756 755 757 756 struct vive_device * ··· 794 793 vive_mainboard_power_on(d); 795 794 vive_mainboard_get_device_info(d); 796 795 } 797 - vive_read_firmware(d->sensors_dev, &d->firmware.firmware_version, &d->firmware.hardware_revision, 798 - &d->firmware.hardware_version_micro, &d->firmware.hardware_version_minor, 799 - &d->firmware.hardware_version_major); 796 + vive_read_firmware(d->sensors_dev, &d->config.firmware.firmware_version, &d->config.firmware.hardware_revision, 797 + &d->config.firmware.hardware_version_micro, &d->config.firmware.hardware_version_minor, 798 + &d->config.firmware.hardware_version_major); 800 799 801 800 /* 802 801 VIVE_INFO(d, "Firmware version %u %s@%s FPGA %u.%u", ··· 804 803 report.fpga_version_major, report.fpga_version_minor); 805 804 */ 806 805 807 - VIVE_INFO(d, "Firmware version %u", d->firmware.firmware_version); 808 - VIVE_INFO(d, "Hardware revision: %d rev %d.%d.%d", d->firmware.hardware_revision, 809 - d->firmware.hardware_version_major, d->firmware.hardware_version_minor, 810 - d->firmware.hardware_version_micro); 806 + VIVE_INFO(d, "Firmware version %u", d->config.firmware.firmware_version); 807 + VIVE_INFO(d, "Hardware revision: %d rev %d.%d.%d", d->config.firmware.hardware_revision, 808 + d->config.firmware.hardware_version_major, d->config.firmware.hardware_version_minor, 809 + d->config.firmware.hardware_version_micro); 811 810 812 - vive_get_imu_range_report(d->sensors_dev, &d->imu.gyro_range, &d->imu.acc_range); 813 - VIVE_INFO(d, "Vive gyroscope range %f", d->imu.gyro_range); 814 - VIVE_INFO(d, "Vive accelerometer range %f", d->imu.acc_range); 811 + vive_get_imu_range_report(d->sensors_dev, &d->config.imu.gyro_range, &d->config.imu.acc_range); 812 + VIVE_INFO(d, "Vive gyroscope range %f", d->config.imu.gyro_range); 813 + VIVE_INFO(d, "Vive accelerometer range %f", d->config.imu.acc_range); 815 814 816 815 char *config = vive_read_config(d->sensors_dev); 816 + 817 + d->config.ll = d->ll; 818 + // usb connected HMD variant is known because of USB id, config parsing relies on it. 819 + d->config.variant = d->variant; 817 820 if (config != NULL) { 818 - vive_config_parse(d, config); 821 + vive_config_parse(&d->config, config); 819 822 free(config); 820 823 } 821 824 ··· 825 828 double lens_horizontal_separation = 0.057863; 826 829 double eye_to_screen_distance = 0.023226876441867737; 827 830 828 - uint32_t w_pixels = d->display.eye_target_width_in_pixels; 829 - uint32_t h_pixels = d->display.eye_target_height_in_pixels; 831 + uint32_t w_pixels = d->config.display.eye_target_width_in_pixels; 832 + uint32_t h_pixels = d->config.display.eye_target_height_in_pixels; 830 833 831 834 // Main display. 832 835 d->base.hmd->screens[0].w_pixels = (int)w_pixels * 2; ··· 882 885 883 886 u_var_add_root(d, "Vive Device", true); 884 887 u_var_add_gui_header(d, &d->gui.calibration, "Calibration"); 885 - u_var_add_vec3_f32(d, &d->imu.acc_scale, "acc_scale"); 886 - u_var_add_vec3_f32(d, &d->imu.acc_bias, "acc_bias"); 887 - u_var_add_vec3_f32(d, &d->imu.gyro_scale, "gyro_scale"); 888 - u_var_add_vec3_f32(d, &d->imu.gyro_bias, "gyro_bias"); 888 + u_var_add_vec3_f32(d, &d->config.imu.acc_scale, "acc_scale"); 889 + u_var_add_vec3_f32(d, &d->config.imu.acc_bias, "acc_bias"); 890 + u_var_add_vec3_f32(d, &d->config.imu.gyro_scale, "gyro_scale"); 891 + u_var_add_vec3_f32(d, &d->config.imu.gyro_bias, "gyro_bias"); 889 892 u_var_add_gui_header(d, &d->gui.last, "Last data"); 890 893 u_var_add_vec3_f32(d, &d->last.acc, "acc"); 891 894 u_var_add_vec3_f32(d, &d->last.gyro, "gyro");
+2 -71
src/xrt/drivers/vive/vive_device.h
··· 16 16 #include "util/u_distortion_mesh.h" 17 17 18 18 #include "vive_lighthouse.h" 19 + #include "vive_config.h" 19 20 20 21 #ifdef __cplusplus 21 22 extern "C" { 22 23 #endif 23 24 24 - 25 - /*! 26 - * A lighthouse consisting of sensors. 27 - * 28 - * All sensors are placed in IMU space. 29 - */ 30 - struct lh_model 31 - { 32 - struct lh_sensor *sensors; 33 - size_t num_sensors; 34 - }; 35 - 36 - /*! 37 - * A single lighthouse senosor point and normal, in IMU space. 38 - */ 39 - struct lh_sensor 40 - { 41 - struct xrt_vec3 pos; 42 - uint32_t _pad0; 43 - struct xrt_vec3 normal; 44 - uint32_t _pad1; 45 - }; 46 - 47 - enum VIVE_VARIANT 48 - { 49 - VIVE_UNKNOWN = 0, 50 - VIVE_VARIANT_VIVE, 51 - VIVE_VARIANT_PRO, 52 - VIVE_VARIANT_INDEX 53 - }; 54 - 55 25 /*! 56 26 * @implements xrt_device 57 27 */ ··· 70 40 struct os_thread_helper watchman_thread; 71 41 struct os_thread_helper mainboard_thread; 72 42 73 - struct lh_model lh; 74 - 75 43 struct 76 44 { 77 45 uint64_t time_ns; 78 46 uint8_t sequence; 79 47 uint32_t last_sample_time_raw; 80 - double acc_range; 81 - double gyro_range; 82 - struct xrt_vec3 acc_bias; 83 - struct xrt_vec3 acc_scale; 84 - struct xrt_vec3 gyro_bias; 85 - struct xrt_vec3 gyro_scale; 86 - 87 - //! IMU position in tracking space. 88 - struct xrt_pose trackref; 89 48 } imu; 90 49 91 50 struct m_imu_3dof fusion; ··· 98 57 99 58 struct 100 59 { 101 - double lens_separation; 102 - double persistence; 103 - int eye_target_height_in_pixels; 104 - int eye_target_width_in_pixels; 105 - 106 - struct xrt_quat rot[2]; 107 - 108 - //! Head position in tracking space. 109 - struct xrt_pose trackref; 110 - //! Head position in IMU space. 111 - struct xrt_pose imuref; 112 - } display; 113 - 114 - struct 115 - { 116 60 uint16_t ipd; 117 61 uint16_t lens_separation; 118 62 uint16_t proximity; 119 63 uint8_t button; 120 64 } board; 121 65 122 - struct 123 - { 124 - uint32_t display_firmware_version; 125 - uint32_t firmware_version; 126 - uint8_t hardware_revision; 127 - uint8_t hardware_version_micro; 128 - uint8_t hardware_version_minor; 129 - uint8_t hardware_version_major; 130 - char mb_serial_number[32]; 131 - char model_number[32]; 132 - char device_serial_number[32]; 133 - } firmware; 134 - 135 66 struct xrt_quat rot_filtered; 136 67 137 68 enum u_logging_level ll; ··· 143 74 bool last; 144 75 } gui; 145 76 146 - struct u_vive_values distortion[2]; 77 + struct vive_config config; 147 78 }; 148 79 149 80 struct vive_device *