The open source OpenXR runtime
0
fork

Configure Feed

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

d/survive: Port to vive_config parsing

authored by

Christoph Haag and committed by
Jakob Bornecrantz
b87c7d5e 152587d7

+103 -306
+66 -274
src/xrt/drivers/survive/survive_driver.c
··· 41 41 42 42 #include "math/m_predict.h" 43 43 44 + #include "vive_config.h" 45 + 44 46 // typically HMD config is available at around 2 seconds after init 45 47 #define WAIT_TIMEOUT 5.0 46 - 47 - // public documentation 48 - //! @todo move to vive_protocol 49 - #define INDEX_MIN_IPD 0.058 50 - #define INDEX_MAX_IPD 0.07 51 - 52 - #define DEFAULT_HAPTIC_FREQ 150.0f 53 - #define MIN_HAPTIC_DURATION 0.05f 54 48 55 49 #define SURVIVE_TRACE(d, ...) U_LOG_XDEV_IFL_T(&d->base, d->sys->ll, __VA_ARGS__) 56 50 #define SURVIVE_DEBUG(d, ...) U_LOG_XDEV_IFL_D(&d->base, d->sys->ll, __VA_ARGS__) ··· 105 99 106 100 static bool survive_already_initialized = false; 107 101 108 - enum VIVE_VARIANT 109 - { 110 - VIVE_UNKNOWN = 0, 111 - VIVE_VARIANT_VIVE, 112 - VIVE_VARIANT_PRO, 113 - VIVE_VARIANT_VALVE_INDEX, 114 - VIVE_VARIANT_HTC_VIVE_CONTROLLER, 115 - VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER, 116 - VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER, 117 - VIVE_VARIANT_TRACKER_V1, 118 - VIVE_VARIANT_TRACKER_v2 119 - }; 120 - 121 102 /*! 122 103 * @implements xrt_device 123 104 */ ··· 131 112 132 113 int num; 133 114 134 - enum VIVE_VARIANT variant; 135 115 136 116 union { 137 117 struct 138 118 { 139 119 float proximity; // [0,1] 140 120 float ipd; 141 - struct xrt_quat rot[2]; 121 + 122 + enum VIVE_VARIANT variant; 123 + struct vive_config config; 142 124 } hmd; 143 125 144 126 struct ··· 146 128 float curl[XRT_FINGER_COUNT]; 147 129 uint64_t curl_ts[XRT_FINGER_COUNT]; 148 130 struct u_hand_tracking hand_tracking; 131 + 132 + enum VIVE_CONTROLLER_VARIANT variant; 133 + struct vive_controller_config config; 149 134 } ctrl; 150 135 }; 151 - struct u_vive_values distortion[2]; 152 136 }; 153 137 154 138 //! @todo support more devices (trackers, ...) ··· 447 431 } 448 432 449 433 450 - bool left = survive->variant == VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER; 434 + bool left = survive->ctrl.variant == CONTROLLER_INDEX_LEFT; 451 435 enum xrt_hand hand = left ? XRT_HAND_LEFT : XRT_HAND_RIGHT; 452 436 453 437 float thumb_curl = 0.0f; ··· 489 473 bool adjust = view_index == 0; 490 474 491 475 struct survive_device *survive = (struct survive_device *)xdev; 492 - pose.orientation = survive->hmd.rot[view_index]; 476 + pose.orientation = survive->hmd.config.display.rot[view_index]; 493 477 pose.position.x = eye_relation->x / 2.0f; 494 478 pose.position.y = eye_relation->y / 2.0f; 495 479 pose.position.z = eye_relation->z / 2.0f; ··· 831 815 return false; 832 816 } 833 817 834 - void 835 - print_vec3(const char *title, struct xrt_vec3 *vec) 836 - { 837 - U_LOG_D("%s = %f %f %f", title, (double)vec->x, (double)vec->y, (double)vec->z); 838 - } 839 - 840 - static long long 841 - _json_to_int(const cJSON *item) 842 - { 843 - if (item != NULL) { 844 - return item->valueint; 845 - } else { 846 - return 0; 847 - } 848 - } 849 - 850 - static bool 851 - _json_get_matrix_3x3(const cJSON *json, const char *name, struct xrt_matrix_3x3 *result) 852 - { 853 - const cJSON *vec3_arr = cJSON_GetObjectItemCaseSensitive(json, name); 854 - 855 - // Some sanity checking. 856 - if (vec3_arr == NULL || cJSON_GetArraySize(vec3_arr) != 3) { 857 - return false; 858 - } 859 - 860 - size_t total = 0; 861 - const cJSON *vec = NULL; 862 - cJSON_ArrayForEach(vec, vec3_arr) 863 - { 864 - assert(cJSON_GetArraySize(vec) == 3); 865 - const cJSON *elem = NULL; 866 - cJSON_ArrayForEach(elem, vec) 867 - { 868 - // Just in case. 869 - if (total >= 9) { 870 - break; 871 - } 872 - 873 - assert(cJSON_IsNumber(elem)); 874 - result->v[total++] = (float)elem->valuedouble; 875 - } 876 - } 877 - 878 - return true; 879 - } 880 - 881 - static float 882 - _json_get_float(const cJSON *json, const char *name) 883 - { 884 - const cJSON *item = cJSON_GetObjectItemCaseSensitive(json, name); 885 - return (float)item->valuedouble; 886 - } 887 - 888 - static long long 889 - _json_get_int(const cJSON *json, const char *name) 890 - { 891 - const cJSON *item = cJSON_GetObjectItemCaseSensitive(json, name); 892 - return _json_to_int(item); 893 - } 894 - 895 - static void 896 - _get_color_coeffs(struct u_vive_values *values, const cJSON *coeffs, uint8_t eye, uint8_t channel) 897 - { 898 - // For Vive this is 8 with only 3 populated. 899 - // For Index this is 4 with all values populated. 900 - const cJSON *item = NULL; 901 - size_t i = 0; 902 - cJSON_ArrayForEach(item, coeffs) 903 - { 904 - values->coefficients[channel][i] = (float)item->valuedouble; 905 - ++i; 906 - if (i == 4) { 907 - break; 908 - } 909 - } 910 - } 911 - 912 - static void 913 - get_distortion_properties(struct survive_device *d, const cJSON *eye_transform_json, uint8_t eye) 914 - { 915 - const cJSON *eye_json = cJSON_GetArrayItem(eye_transform_json, eye); 916 - if (eye_json == NULL) { 917 - return; 918 - } 919 - 920 - struct xrt_matrix_3x3 rot = {0}; 921 - if (_json_get_matrix_3x3(eye_json, "eye_to_head", &rot)) { 922 - math_quat_from_matrix_3x3(&rot, &d->hmd.rot[eye]); 923 - } 924 - 925 - // TODO: store grow_for_undistort per eye 926 - // clang-format off 927 - d->distortion[eye].grow_for_undistort = _json_get_float(eye_json, "grow_for_undistort"); 928 - d->distortion[eye].undistort_r2_cutoff = _json_get_float(eye_json, "undistort_r2_cutoff"); 929 - // clang-format on 930 - 931 - const char *names[3] = { 932 - "distortion_red", 933 - "distortion", 934 - "distortion_blue", 935 - }; 936 - 937 - for (int i = 0; i < 3; i++) { 938 - const cJSON *distortion = cJSON_GetObjectItemCaseSensitive(eye_json, names[i]); 939 - if (distortion == NULL) { 940 - continue; 941 - } 942 - 943 - d->distortion[eye].center[i].x = _json_get_float(distortion, "center_x"); 944 - d->distortion[eye].center[i].y = _json_get_float(distortion, "center_y"); 945 - 946 - const cJSON *coeffs = cJSON_GetObjectItemCaseSensitive(distortion, "coeffs"); 947 - if (coeffs != NULL) { 948 - _get_color_coeffs(&d->distortion[eye], coeffs, eye, i); 949 - } 950 - } 951 - } 952 - 953 818 static bool 954 819 compute_distortion(struct xrt_device *xdev, int view, float u, float v, struct xrt_uv_triplet *result) 955 820 { 956 821 struct survive_device *d = (struct survive_device *)xdev; 957 - return u_compute_distortion_vive(&d->distortion[view], u, v, result); 822 + return u_compute_distortion_vive(&d->hmd.config.distortion[view], u, v, result); 958 823 } 959 824 960 825 static bool ··· 965 830 int outputs = 0; 966 831 967 832 struct survive_device *survive = U_DEVICE_ALLOCATE(struct survive_device, flags, inputs, outputs); 833 + 968 834 sys->hmd = survive; 969 835 survive->sys = sys; 970 836 survive->survive_obj = sso; 971 - survive->variant = variant; 837 + survive->hmd.variant = variant; 972 838 973 839 survive->base.name = XRT_DEVICE_GENERIC_HMD; 974 840 snprintf(survive->base.str, XRT_DEVICE_NAME_LEN, "Survive HMD"); ··· 983 849 survive->base.hmd->blend_mode = XRT_BLEND_MODE_OPAQUE; 984 850 985 851 char *json_string = survive_get_json_config(survive->survive_obj); 986 - cJSON *json = cJSON_Parse(json_string); 987 - if (!cJSON_IsObject(json)) { 988 - SURVIVE_ERROR(survive, "Could not parse JSON data."); 989 - return false; 990 - } 991 852 853 + survive->hmd.config.ll = survive->sys->ll; 854 + // usb connected HMD variant is known because of USB id, config parsing relies on it. 855 + survive->hmd.config.variant = survive->hmd.variant; 856 + vive_config_parse(&survive->hmd.config, json_string); 992 857 993 858 // TODO: Replace hard coded values from OpenHMD with config 994 859 double w_meters = 0.122822 / 2.0; 995 860 double h_meters = 0.068234; 996 861 double lens_horizontal_separation = 0.057863; 997 862 double eye_to_screen_distance = 0.023226876441867737; 998 - if (survive->variant == VIVE_VARIANT_VALVE_INDEX) { 999 - lens_horizontal_separation = 0.06; 1000 - h_meters = 0.07; 1001 - // eye relief knob adjusts this around [0.0255(near)-0.275(far)] 1002 - eye_to_screen_distance = 0.0255; 1003 - } 1004 863 1005 - 1006 - double fov = 2 * atan2(w_meters - lens_horizontal_separation / 2.0, eye_to_screen_distance); 1007 - 1008 - for (int view = 0; view < 2; view++) { 1009 - survive->distortion[view].aspect_x_over_y = 0.89999997615814209f; 1010 - survive->distortion[view].grow_for_undistort = 0.5f; 1011 - survive->distortion[view].undistort_r2_cutoff = 1.0f; 1012 - } 1013 - 1014 - survive->hmd.rot[0].w = 1.0f; 1015 - survive->hmd.rot[1].w = 1.0f; 1016 - 1017 - //! @todo: use IPD for FOV 1018 - survive->hmd.ipd = 0.063; 1019 - survive->hmd.proximity = 0; 864 + uint32_t w_pixels = survive->hmd.config.display.eye_target_width_in_pixels; 865 + uint32_t h_pixels = survive->hmd.config.display.eye_target_height_in_pixels; 1020 866 1021 - uint16_t w_pixels = 1080; 1022 - uint16_t h_pixels = 1200; 1023 - const cJSON *device_json = cJSON_GetObjectItemCaseSensitive(json, "device"); 1024 - if (device_json) { 1025 - if (survive->variant != VIVE_VARIANT_VALVE_INDEX) { 1026 - survive->distortion[0].aspect_x_over_y = 1027 - _json_get_float(device_json, "physical_aspect_x_over_y"); 1028 - survive->distortion[1].aspect_x_over_y = survive->distortion[0].aspect_x_over_y; 1029 - 1030 - //! @todo: fov calculation needs to be fixed, only works 1031 - //! with hardcoded value 1032 - // lens_horizontal_separation = _json_get_double(json, 1033 - // "lens_separation"); 1034 - } 1035 - h_pixels = (uint16_t)_json_get_int(device_json, "eye_target_height_in_pixels"); 1036 - w_pixels = (uint16_t)_json_get_int(device_json, "eye_target_width_in_pixels"); 1037 - } 1038 - 1039 - const cJSON *eye_transform_json = cJSON_GetObjectItemCaseSensitive(json, "tracking_to_eye_transform"); 1040 - if (eye_transform_json) { 1041 - for (uint8_t eye = 0; eye < 2; eye++) { 1042 - get_distortion_properties(survive, eye_transform_json, eye); 1043 - } 1044 - } 1045 - 1046 - SURVIVE_INFO(survive, "Survive eye resolution %dx%d", w_pixels, h_pixels); 1047 - 1048 - cJSON_Delete(json); 867 + SURVIVE_DEBUG(survive, "display: %dx%d", w_pixels, h_pixels); 1049 868 1050 869 // Main display. 1051 870 survive->base.hmd->screens[0].w_pixels = (int)w_pixels * 2; 1052 871 survive->base.hmd->screens[0].h_pixels = (int)h_pixels; 1053 872 1054 - if (survive->variant == VIVE_VARIANT_VALVE_INDEX) 873 + if (survive->hmd.variant == VIVE_VARIANT_INDEX) { 874 + lens_horizontal_separation = 0.06; 875 + h_meters = 0.07; 876 + // eye relief knob adjusts this around [0.0255(near)-0.275(far)] 877 + eye_to_screen_distance = 0.0255; 878 + 1055 879 survive->base.hmd->screens[0].nominal_frame_interval_ns = (uint64_t)time_s_to_ns(1.0f / 144.0f); 1056 - else 880 + } else { 1057 881 survive->base.hmd->screens[0].nominal_frame_interval_ns = (uint64_t)time_s_to_ns(1.0f / 90.0f); 882 + } 883 + 884 + double fov = 2 * atan2(w_meters - lens_horizontal_separation / 2.0, eye_to_screen_distance); 1058 885 1059 886 struct xrt_vec2 lens_center[2]; 1060 887 ··· 1160 987 } while (0) 1161 988 1162 989 static bool 1163 - _create_controller_device(struct survive_system *sys, const SurviveSimpleObject *sso, enum VIVE_VARIANT variant) 990 + _create_controller_device(struct survive_system *sys, 991 + const SurviveSimpleObject *sso, 992 + struct vive_controller_config *config) 1164 993 { 1165 994 1166 - enum u_device_alloc_flags flags = 0; 1167 - 1168 - int inputs = VIVE_CONTROLLER_MAX_INDEX; 1169 - int outputs = 1; 1170 - struct survive_device *survive = U_DEVICE_ALLOCATE(struct survive_device, flags, inputs, outputs); 995 + enum VIVE_CONTROLLER_VARIANT variant = config->variant; 1171 996 1172 997 int idx = -1; 1173 - if (variant == VIVE_VARIANT_HTC_VIVE_CONTROLLER) { 998 + if (variant == CONTROLLER_VIVE_WAND) { 1174 999 if (sys->controllers[SURVIVE_LEFT_CONTROLLER] == NULL) { 1175 1000 idx = SURVIVE_LEFT_CONTROLLER; 1176 1001 } else if (sys->controllers[SURVIVE_RIGHT_CONTROLLER] == NULL) { 1177 1002 idx = SURVIVE_RIGHT_CONTROLLER; 1178 1003 } else { 1179 - SURVIVE_ERROR(survive, "Only creating 2 controllers!"); 1004 + U_LOG_IFL_E(sys->ll, "Only creating 2 controllers!"); 1180 1005 return false; 1181 1006 } 1182 - } else if (variant == VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER) { 1007 + } else if (variant == CONTROLLER_INDEX_LEFT) { 1183 1008 if (sys->controllers[SURVIVE_LEFT_CONTROLLER] == NULL) { 1184 1009 idx = SURVIVE_LEFT_CONTROLLER; 1185 1010 } else { 1186 - SURVIVE_ERROR(survive, "Only creating 1 left controller!"); 1011 + U_LOG_IFL_E(sys->ll, "Only creating 1 left controller!"); 1187 1012 return false; 1188 1013 } 1189 - } else if (variant == VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER) { 1014 + } else if (variant == CONTROLLER_INDEX_RIGHT) { 1190 1015 if (sys->controllers[SURVIVE_RIGHT_CONTROLLER] == NULL) { 1191 1016 idx = SURVIVE_RIGHT_CONTROLLER; 1192 1017 } else { 1193 - SURVIVE_ERROR(survive, "Only creating 1 right controller!"); 1018 + U_LOG_IFL_E(sys->ll, "Only creating 1 right controller!"); 1194 1019 return false; 1195 1020 } 1196 1021 } 1022 + 1023 + if (idx == -1) { 1024 + U_LOG_IFL_E(sys->ll, "Skipping survive device we couldn't assign: %s!", config->firmware.model_number); 1025 + return false; 1026 + } 1027 + 1028 + enum u_device_alloc_flags flags = 0; 1029 + 1030 + int inputs = VIVE_CONTROLLER_MAX_INDEX; 1031 + int outputs = 1; 1032 + struct survive_device *survive = U_DEVICE_ALLOCATE(struct survive_device, flags, inputs, outputs); 1033 + survive->ctrl.config = *config; 1034 + 1197 1035 sys->controllers[idx] = survive; 1198 1036 survive->sys = sys; 1199 - survive->variant = variant; 1037 + survive->ctrl.variant = variant; 1200 1038 survive->survive_obj = sso; 1201 1039 1202 1040 survive->num = idx; ··· 1209 1047 1210 1048 //! @todo: May use Vive Wands + Index HMDs or Index Controllers + Vive 1211 1049 //! HMD 1212 - if (variant == VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER || 1213 - variant == VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER) { 1050 + if (variant == CONTROLLER_INDEX_LEFT || variant == CONTROLLER_INDEX_RIGHT) { 1214 1051 survive->base.name = XRT_DEVICE_INDEX_CONTROLLER; 1215 1052 snprintf(survive->base.str, XRT_DEVICE_NAME_LEN, "Survive Valve Index Controller %d", idx); 1216 1053 ··· 1236 1073 SET_INDEX_INPUT(AIM_POSE, AIM_POSE); 1237 1074 SET_INDEX_INPUT(GRIP_POSE, GRIP_POSE); 1238 1075 1239 - if (variant == VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER) { 1076 + if (variant == CONTROLLER_INDEX_LEFT) { 1240 1077 survive->base.device_type = XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER; 1241 1078 survive->base.inputs[VIVE_CONTROLLER_HAND_TRACKING].name = XRT_INPUT_GENERIC_HAND_TRACKING_LEFT; 1242 - } else if (variant == VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER) { 1079 + } else if (variant == CONTROLLER_INDEX_RIGHT) { 1243 1080 survive->base.device_type = XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER; 1244 1081 survive->base.inputs[VIVE_CONTROLLER_HAND_TRACKING].name = 1245 1082 XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT; ··· 1260 1097 1261 1098 survive->base.hand_tracking_supported = true; 1262 1099 1263 - } else if (survive->variant == VIVE_VARIANT_HTC_VIVE_CONTROLLER) { 1100 + } else if (survive->ctrl.variant == CONTROLLER_VIVE_WAND) { 1264 1101 survive->base.name = XRT_DEVICE_VIVE_WAND; 1265 1102 snprintf(survive->base.str, XRT_DEVICE_NAME_LEN, "Survive Vive Wand Controller %d", idx); 1266 1103 ··· 1300 1137 switch (product_id) { 1301 1138 case VIVE_PID: return VIVE_VARIANT_VIVE; 1302 1139 case VIVE_PRO_MAINBOARD_PID: return VIVE_VARIANT_PRO; 1303 - case VIVE_PRO_LHR_PID: return VIVE_VARIANT_VALVE_INDEX; 1140 + case VIVE_PRO_LHR_PID: return VIVE_VARIANT_INDEX; 1304 1141 default: U_LOG_W("No product ids matched %.4x", product_id); return VIVE_UNKNOWN; 1305 1142 } 1306 1143 } 1307 1144 1308 - #define JSON_STRING(a, b, c) u_json_get_string_into_array(u_json_get(a, b), c, sizeof(c)) 1309 - 1310 - static enum VIVE_VARIANT 1311 - get_variant_from_json(struct survive_system *ss, cJSON *json) 1312 - { 1313 - char model_number[32]; 1314 - 1315 - if (u_json_get(json, "model_number")) { 1316 - JSON_STRING(json, "model_number", model_number); 1317 - } else { 1318 - JSON_STRING(json, "model_name", model_number); 1319 - } 1320 - 1321 - enum VIVE_VARIANT variant = VIVE_UNKNOWN; 1322 - 1323 - if (strcmp(model_number, "Vive. Controller MV") == 0) { 1324 - variant = VIVE_VARIANT_HTC_VIVE_CONTROLLER; 1325 - U_LOG_D("Found Vive Wand controller"); 1326 - } else if (strcmp(model_number, "Knuckles Right") == 0) { 1327 - variant = VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER; 1328 - U_LOG_D("Found Knuckles Right controller"); 1329 - } else if (strcmp(model_number, "Knuckles Left") == 0) { 1330 - variant = VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER; 1331 - U_LOG_D("Found Knuckles Left controller"); 1332 - } else if (strcmp(model_number, "Vive Tracker PVT") == 0) { 1333 - variant = VIVE_VARIANT_TRACKER_V1; 1334 - U_LOG_D("Found Gen 1 tracker."); 1335 - } else if (strcmp(model_number, "VIVE Tracker Pro MV") == 0) { 1336 - variant = VIVE_VARIANT_TRACKER_v2; 1337 - U_LOG_D("Found Gen 2 tracker."); 1338 - } else if (strcmp(model_number, "Utah MP") == 0) { 1339 - U_LOG_W("Found Utah MP (Index HMD), not a controller!"); 1340 - } else { 1341 - U_LOG_E("Failed to parse controller variant: %s", model_number); 1342 - } 1343 - 1344 - return variant; 1345 - } 1346 - 1347 1145 int 1348 1146 survive_found(struct xrt_prober *xp, 1349 1147 struct xrt_prober_device **devices, ··· 1414 1212 _create_hmd_device(ss, variant, it); 1415 1213 } else if (type == SurviveSimpleObject_OBJECT) { 1416 1214 char *json_string = survive_get_json_config(it); 1417 - cJSON *json = cJSON_Parse(json_string); 1418 - if (!cJSON_IsObject(json)) { 1419 - U_LOG_IFL_E(ss->ll, "Could not parse JSON data."); 1420 - cJSON_Delete(json); 1421 - continue; 1422 - } 1423 1215 1424 - enum VIVE_VARIANT variant = get_variant_from_json(ss, json); 1216 + struct vive_controller_config config = {.ll = ss->ll}; 1217 + vive_config_parse_controller(&config, json_string); 1425 1218 1426 - switch (variant) { 1427 - case VIVE_VARIANT_HTC_VIVE_CONTROLLER: 1428 - case VIVE_VARIANT_VALVE_INDEX_LEFT_CONTROLLER: 1429 - case VIVE_VARIANT_VALVE_INDEX_RIGHT_CONTROLLER: 1219 + switch (config.variant) { 1220 + case CONTROLLER_VIVE_WAND: 1221 + case CONTROLLER_INDEX_LEFT: 1222 + case CONTROLLER_INDEX_RIGHT: 1430 1223 U_LOG_IFL_D(ss->ll, "Adding controller."); 1431 - _create_controller_device(ss, it, variant); 1224 + _create_controller_device(ss, it, &config); 1432 1225 break; 1433 1226 default: 1434 1227 U_LOG_IFL_D(ss->ll, "Skip non controller obj."); 1435 1228 U_LOG_IFL_T(ss->ll, "json: %s", json_string); 1436 1229 break; 1437 1230 } 1438 - cJSON_Delete(json); 1439 1231 } else { 1440 1232 U_LOG_IFL_D(ss->ll, "Skip non OBJECT obj."); 1441 1233 }
+29
src/xrt/drivers/vive/vive_config.c
··· 176 176 U_LOG_D("%s = %f %f %f", title, (double)vec->x, (double)vec->y, (double)vec->z); 177 177 } 178 178 179 + static void 180 + vive_init_defaults(struct vive_config *d) 181 + { 182 + d->display.eye_target_width_in_pixels = 1080; 183 + d->display.eye_target_height_in_pixels = 1200; 184 + 185 + d->display.rot[0].w = 1.0f; 186 + d->display.rot[1].w = 1.0f; 187 + 188 + d->imu.gyro_range = 8.726646f; 189 + d->imu.acc_range = 39.226600f; 190 + 191 + d->imu.acc_scale.x = 1.0f; 192 + d->imu.acc_scale.y = 1.0f; 193 + d->imu.acc_scale.z = 1.0f; 194 + 195 + d->imu.gyro_scale.x = 1.0f; 196 + d->imu.gyro_scale.y = 1.0f; 197 + d->imu.gyro_scale.z = 1.0f; 198 + 199 + for (int view = 0; view < 2; view++) { 200 + d->distortion[view].aspect_x_over_y = 0.89999997615814209f; 201 + d->distortion[view].grow_for_undistort = 0.5f; 202 + d->distortion[view].undistort_r2_cutoff = 1.0f; 203 + } 204 + } 205 + 179 206 bool 180 207 vive_config_parse(struct vive_config *d, char *json_string) 181 208 { 209 + vive_init_defaults(d); 210 + 182 211 VIVE_DEBUG(d, "JSON config:\n%s", json_string); 183 212 184 213 cJSON *json = cJSON_Parse(json_string);
+8
src/xrt/drivers/vive/vive_config.h
··· 15 15 #include "util/u_logging.h" 16 16 #include "util/u_distortion_mesh.h" 17 17 18 + // public documentation 19 + #define INDEX_MIN_IPD 0.058 20 + #define INDEX_MAX_IPD 0.07 21 + 22 + // arbitrary default values 23 + #define DEFAULT_HAPTIC_FREQ 150.0f 24 + #define MIN_HAPTIC_DURATION 0.05f 25 + 18 26 enum VIVE_VARIANT 19 27 { 20 28 VIVE_UNKNOWN = 0,
-32
src/xrt/drivers/vive/vive_device.c
··· 716 716 return NULL; 717 717 } 718 718 719 - void 720 - vive_init_defaults(struct vive_device *d) 721 - { 722 - d->config.display.eye_target_width_in_pixels = 1080; 723 - d->config.display.eye_target_height_in_pixels = 1200; 724 - 725 - d->config.display.rot[0].w = 1.0f; 726 - d->config.display.rot[1].w = 1.0f; 727 - 728 - d->config.imu.gyro_range = 8.726646f; 729 - d->config.imu.acc_range = 39.226600f; 730 - 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; 734 - 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; 738 - 739 - d->rot_filtered.w = 1.0f; 740 - 741 - for (int view = 0; view < 2; view++) { 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; 745 - } 746 - } 747 - 748 - 749 719 static bool 750 720 compute_distortion(struct xrt_device *xdev, int view, float u, float v, struct xrt_uv_triplet *result) 751 721 { ··· 779 749 d->base.hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE; 780 750 d->base.hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE; 781 751 d->base.compute_distortion = compute_distortion; 782 - 783 - vive_init_defaults(d); 784 752 785 753 switch (variant) { 786 754 case VIVE_VARIANT_VIVE: snprintf(d->base.str, XRT_DEVICE_NAME_LEN, "HTC Vive"); break;