d/vive: Use VIVE_ERROR when vive_device is available.

This commit is contained in:
Lubosz Sarnecki 2020-07-09 14:11:35 +02:00
parent a074c6ebe1
commit 499751e4fa
2 changed files with 18 additions and 13 deletions

View file

@ -220,7 +220,7 @@ vive_config_parse(struct vive_device *d, char *json_string)
cJSON *json = cJSON_Parse(json_string); cJSON *json = cJSON_Parse(json_string);
if (!cJSON_IsObject(json)) { if (!cJSON_IsObject(json)) {
U_LOG_E("Could not parse JSON data."); VIVE_ERROR(d, "Could not parse JSON data.");
return false; return false;
} }
@ -263,7 +263,7 @@ vive_config_parse(struct vive_device *d, char *json_string)
d->display.imuref = imu_to_head; d->display.imuref = imu_to_head;
} break; } break;
default: U_LOG_E("Unknown Vive variant."); return false; default: VIVE_ERROR(d, "Unknown Vive variant."); return false;
} }
JSON_STRING(json, "model_number", d->firmware.model_number); JSON_STRING(json, "model_number", d->firmware.model_number);

View file

@ -388,7 +388,7 @@ update_imu(struct vive_device *d, struct vive_imu_report *report)
angular_velocity_fixed.z = -angular_velocity.z; angular_velocity_fixed.z = -angular_velocity.z;
angular_velocity = angular_velocity_fixed; angular_velocity = angular_velocity_fixed;
} break; } break;
default: U_LOG_E("Unhandled Vive variant"); return; default: VIVE_ERROR(d, "Unhandled Vive variant"); return;
} }
d->imu.time_ns += dt_ns; d->imu.time_ns += dt_ns;
@ -421,20 +421,23 @@ vive_mainboard_read_one_msg(struct vive_device *d)
return true; return true;
} }
if (ret < 0) { if (ret < 0) {
U_LOG_E("Failed to read device '%i'!", ret); VIVE_ERROR(d, "Failed to read device '%i'!", ret);
return false; return false;
} }
switch (buffer[0]) { switch (buffer[0]) {
case VIVE_MAINBOARD_STATUS_REPORT_ID: case VIVE_MAINBOARD_STATUS_REPORT_ID:
if (ret != sizeof(struct vive_mainboard_status_report)) { if (ret != sizeof(struct vive_mainboard_status_report)) {
U_LOG_E("Mainboard status report has invalid size."); VIVE_ERROR(d,
"Mainboard status report has invalid size.");
return false; return false;
} }
vive_mainboard_decode_message( vive_mainboard_decode_message(
d, (struct vive_mainboard_status_report *)buffer); d, (struct vive_mainboard_status_report *)buffer);
break; break;
default: U_LOG_E("Unknown mainboard message type %d", buffer[0]); break; default:
VIVE_ERROR(d, "Unknown mainboard message type %d", buffer[0]);
break;
} }
return true; return true;
@ -478,19 +481,21 @@ vive_sensors_read_one_msg(struct vive_device *d)
return true; return true;
} }
if (ret < 0) { if (ret < 0) {
U_LOG_E("Failed to read device '%i'!", ret); VIVE_ERROR(d, "Failed to read device '%i'!", ret);
return false; return false;
} }
switch (buffer[0]) { switch (buffer[0]) {
case VIVE_IMU_REPORT_ID: case VIVE_IMU_REPORT_ID:
if (ret != 52) { if (ret != 52) {
U_LOG_E("Wrong IMU report size: %d", ret); VIVE_ERROR(d, "Wrong IMU report size: %d", ret);
return false; return false;
} }
update_imu(d, (struct vive_imu_report *)buffer); update_imu(d, (struct vive_imu_report *)buffer);
break; break;
default: U_LOG_E("Unknown sensor message type %d", buffer[0]); break; default:
VIVE_ERROR(d, "Unknown sensor message type %d", buffer[0]);
break;
} }
return true; return true;
@ -670,8 +675,8 @@ vive_device_create(struct os_hid_device *mainboard_dev,
fov, h_meters, fov, h_meters,
(double)d->base.hmd->views[eye].lens_center.y_meters, 0, (double)d->base.hmd->views[eye].lens_center.y_meters, 0,
&d->base.hmd->views[eye].fov)) { &d->base.hmd->views[eye].fov)) {
U_LOG_E( VIVE_ERROR(
"Failed to compute the partial fields of view."); d, "Failed to compute the partial fields of view.");
free(d); free(d);
return NULL; return NULL;
} }
@ -698,7 +703,7 @@ vive_device_create(struct os_hid_device *mainboard_dev,
ret = os_thread_helper_start(&d->mainboard_thread, ret = os_thread_helper_start(&d->mainboard_thread,
vive_mainboard_run_thread, d); vive_mainboard_run_thread, d);
if (ret != 0) { if (ret != 0) {
U_LOG_E("Failed to start mainboard thread!"); VIVE_ERROR(d, "Failed to start mainboard thread!");
vive_device_destroy((struct xrt_device *)d); vive_device_destroy((struct xrt_device *)d);
return NULL; return NULL;
} }
@ -707,7 +712,7 @@ vive_device_create(struct os_hid_device *mainboard_dev,
ret = os_thread_helper_start(&d->sensors_thread, ret = os_thread_helper_start(&d->sensors_thread,
vive_sensors_run_thread, d); vive_sensors_run_thread, d);
if (ret != 0) { if (ret != 0) {
U_LOG_E("Failed to start sensors thread!"); VIVE_ERROR(d, "Failed to start sensors thread!");
vive_device_destroy((struct xrt_device *)d); vive_device_destroy((struct xrt_device *)d);
return NULL; return NULL;
} }