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 controller config into separate struct

authored by

Christoph Haag and committed by
Jakob Bornecrantz
a2e7e1c3 e4b0e628

+82 -60
+1 -1
src/xrt/drivers/vive/vive_config.c
··· 287 287 } 288 288 289 289 bool 290 - vive_config_parse_controller(struct vive_controller_device *d, char *json_string) 290 + vive_config_parse_controller(struct vive_controller_config *d, char *json_string) 291 291 { 292 292 VIVE_DEBUG(d, "JSON config:\n%s", json_string); 293 293
+43 -1
src/xrt/drivers/vive/vive_config.h
··· 23 23 VIVE_VARIANT_INDEX 24 24 }; 25 25 26 + enum VIVE_CONTROLLER_VARIANT 27 + { 28 + CONTROLLER_VIVE_WAND, 29 + CONTROLLER_INDEX_LEFT, 30 + CONTROLLER_INDEX_RIGHT, 31 + CONTROLLER_TRACKER_GEN1, 32 + CONTROLLER_TRACKER_GEN2, 33 + CONTROLLER_UNKNOWN 34 + }; 35 + 26 36 /*! 27 37 * A single lighthouse senosor point and normal, in IMU space. 28 38 */ ··· 98 108 struct lh_model lh; 99 109 }; 100 110 111 + struct vive_controller_config 112 + { 113 + enum u_logging_level ll; 114 + 115 + enum VIVE_CONTROLLER_VARIANT variant; 116 + 117 + struct 118 + { 119 + uint32_t firmware_version; 120 + uint8_t hardware_revision; 121 + uint8_t hardware_version_micro; 122 + uint8_t hardware_version_minor; 123 + uint8_t hardware_version_major; 124 + char mb_serial_number[32]; 125 + char model_number[32]; 126 + char device_serial_number[32]; 127 + } firmware; 128 + 129 + struct 130 + { 131 + double acc_range; 132 + double gyro_range; 133 + struct xrt_vec3 acc_bias; 134 + struct xrt_vec3 acc_scale; 135 + struct xrt_vec3 gyro_bias; 136 + struct xrt_vec3 gyro_scale; 137 + 138 + //! IMU position in tracking space. 139 + struct xrt_pose trackref; 140 + } imu; 141 + }; 142 + 101 143 bool 102 144 vive_config_parse(struct vive_config *d, char *json_string); 103 145 ··· 105 147 struct vive_controller_device; 106 148 107 149 bool 108 - vive_config_parse_controller(struct vive_controller_device *d, char *json_string); 150 + vive_config_parse_controller(struct vive_controller_config *d, char *json_string);
+33 -26
src/xrt/drivers/vive/vive_controller.c
··· 543 543 __le16_to_cpu(sample->gyro[2]), 544 544 }; 545 545 546 - float scale = (float)d->imu.acc_range / 32768.0f; 546 + float scale = (float)d->config.imu.acc_range / 32768.0f; 547 547 struct xrt_vec3 acceleration = { 548 - scale * d->imu.acc_scale.x * acc[0] - d->imu.acc_bias.x, 549 - scale * d->imu.acc_scale.y * acc[1] - d->imu.acc_bias.y, 550 - scale * d->imu.acc_scale.z * acc[2] - d->imu.acc_bias.z, 548 + scale * d->config.imu.acc_scale.x * acc[0] - d->config.imu.acc_bias.x, 549 + scale * d->config.imu.acc_scale.y * acc[1] - d->config.imu.acc_bias.y, 550 + scale * d->config.imu.acc_scale.z * acc[2] - d->config.imu.acc_bias.z, 551 551 }; 552 552 553 - scale = (float)d->imu.gyro_range / 32768.0f; 553 + scale = (float)d->config.imu.gyro_range / 32768.0f; 554 554 struct xrt_vec3 angular_velocity = { 555 - scale * d->imu.gyro_scale.x * gyro[0] - d->imu.gyro_bias.x, 556 - scale * d->imu.gyro_scale.y * gyro[1] - d->imu.gyro_bias.y, 557 - scale * d->imu.gyro_scale.z * gyro[2] - d->imu.gyro_bias.z, 555 + scale * d->config.imu.gyro_scale.x * gyro[0] - d->config.imu.gyro_bias.x, 556 + scale * d->config.imu.gyro_scale.y * gyro[1] - d->config.imu.gyro_bias.y, 557 + scale * d->config.imu.gyro_scale.z * gyro[2] - d->config.imu.gyro_bias.z, 558 558 }; 559 559 560 560 VIVE_TRACE(d, "ACC %f %f %f", acceleration.x, acceleration.y, acceleration.z); ··· 1030 1030 m_imu_3dof_init(&d->fusion, M_IMU_3DOF_USE_GRAVITY_DUR_20MS); 1031 1031 1032 1032 /* default values, will be queried from device */ 1033 - d->imu.gyro_range = 8.726646f; 1034 - d->imu.acc_range = 39.226600f; 1033 + d->config.imu.gyro_range = 8.726646f; 1034 + d->config.imu.acc_range = 39.226600f; 1035 1035 1036 - d->imu.acc_scale.x = 1.0f; 1037 - d->imu.acc_scale.y = 1.0f; 1038 - d->imu.acc_scale.z = 1.0f; 1039 - d->imu.gyro_scale.x = 1.0f; 1040 - d->imu.gyro_scale.y = 1.0f; 1041 - d->imu.gyro_scale.z = 1.0f; 1036 + d->config.imu.acc_scale.x = 1.0f; 1037 + d->config.imu.acc_scale.y = 1.0f; 1038 + d->config.imu.acc_scale.z = 1.0f; 1039 + d->config.imu.gyro_scale.x = 1.0f; 1040 + d->config.imu.gyro_scale.y = 1.0f; 1041 + d->config.imu.gyro_scale.z = 1.0f; 1042 1042 1043 - d->imu.acc_bias.x = 0.0f; 1044 - d->imu.acc_bias.y = 0.0f; 1045 - d->imu.acc_bias.z = 0.0f; 1046 - d->imu.gyro_bias.x = 0.0f; 1047 - d->imu.gyro_bias.y = 0.0f; 1048 - d->imu.gyro_bias.z = 0.0f; 1043 + d->config.imu.acc_bias.x = 0.0f; 1044 + d->config.imu.acc_bias.y = 0.0f; 1045 + d->config.imu.acc_bias.z = 0.0f; 1046 + d->config.imu.gyro_bias.x = 0.0f; 1047 + d->config.imu.gyro_bias.y = 0.0f; 1048 + d->config.imu.gyro_bias.z = 0.0f; 1049 1049 1050 1050 d->controller_hid = controller_hid; 1051 1051 ··· 1058 1058 d->index = controller_num; 1059 1059 1060 1060 //! @todo: reading range report fails for powered off controller 1061 - if (vive_get_imu_range_report(d->controller_hid, &d->imu.gyro_range, &d->imu.acc_range) != 0) { 1061 + if (vive_get_imu_range_report(d->controller_hid, &d->config.imu.gyro_range, &d->config.imu.acc_range) != 0) { 1062 1062 VIVE_ERROR(d, "Could not get watchman IMU range packet!"); 1063 1063 free(d); 1064 1064 return 0; 1065 1065 } 1066 1066 1067 - VIVE_DEBUG(d, "Vive controller gyroscope range %f", d->imu.gyro_range); 1068 - VIVE_DEBUG(d, "Vive controller accelerometer range %f", d->imu.acc_range); 1067 + VIVE_DEBUG(d, "Vive controller gyroscope range %f", d->config.imu.gyro_range); 1068 + VIVE_DEBUG(d, "Vive controller accelerometer range %f", d->config.imu.acc_range); 1069 1069 1070 1070 // successful config parsing determines d->variant 1071 1071 char *config = vive_read_config(d->controller_hid); 1072 + 1073 + d->config.ll = d->ll; 1074 + 1072 1075 if (config != NULL) { 1073 - vive_config_parse_controller(d, config); 1076 + vive_config_parse_controller(&d->config, config); 1074 1077 free(config); 1075 1078 } else { 1076 1079 VIVE_ERROR(d, "Could not get Vive controller config\n"); 1077 1080 free(d); 1078 1081 return 0; 1079 1082 } 1083 + 1084 + // watchman rf connected device variant is read from config json 1085 + //! @todo usb connected controllers 1086 + d->variant = d->config.variant; 1080 1087 1081 1088 if (d->variant == CONTROLLER_VIVE_WAND) { 1082 1089 d->base.name = XRT_DEVICE_VIVE_WAND;
+5 -32
src/xrt/drivers/vive/vive_controller.h
··· 20 20 21 21 #include "util/u_hand_tracking.h" 22 22 23 + #include "vive_config.h" 24 + 23 25 #ifdef __cplusplus 24 26 extern "C" { 25 27 #endif ··· 36 38 WATCHMAN_GEN_UNKNOWN 37 39 }; 38 40 39 - enum controller_variant 40 - { 41 - CONTROLLER_VIVE_WAND, 42 - CONTROLLER_INDEX_LEFT, 43 - CONTROLLER_INDEX_RIGHT, 44 - CONTROLLER_TRACKER_GEN1, 45 - CONTROLLER_TRACKER_GEN2, 46 - CONTROLLER_UNKNOWN 47 - }; 48 - 49 41 /*! 50 42 * A Vive Controller device, representing just a single controller. 51 43 * ··· 63 55 { 64 56 uint64_t time_ns; 65 57 uint32_t last_sample_time_raw; 66 - double acc_range; 67 - double gyro_range; 68 - struct xrt_vec3 acc_bias; 69 - struct xrt_vec3 acc_scale; 70 - struct xrt_vec3 gyro_bias; 71 - struct xrt_vec3 gyro_scale; 72 - 73 - //! IMU position in tracking space. 74 - struct xrt_pose trackref; 75 58 } imu; 76 59 77 60 struct m_imu_3dof fusion; ··· 113 96 uint8_t battery; 114 97 } state; 115 98 116 - struct 117 - { 118 - uint32_t firmware_version; 119 - uint8_t hardware_revision; 120 - uint8_t hardware_version_micro; 121 - uint8_t hardware_version_minor; 122 - uint8_t hardware_version_major; 123 - char mb_serial_number[32]; 124 - char model_number[32]; 125 - char device_serial_number[32]; 126 - } firmware; 127 - 128 99 enum watchman_gen watchman_gen; 129 - enum controller_variant variant; 100 + enum VIVE_CONTROLLER_VARIANT variant; 130 101 131 102 struct u_hand_tracking hand_tracking; 103 + 104 + struct vive_controller_config config; 132 105 }; 133 106 134 107 struct vive_controller_device *