d/pssense: Add distinct create device function separate from prober function
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2662>
854 unmodified linesExpand all85585685785885986086186286386486585986086186286386487086586686787286886987087187287387887487587687787887988488088188288388416 unmodified lines90190290390490990590690791290890991091191291391891491591691791825 unmodified lines94494594694795294894995095195295395495995595695795895996096196696296396496596696797296896997097197229 unmodified lines10021003100410051010100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710282 unmodified lines854 unmodified linesExpand all}
#define SET_INPUT(NAME) (pssense->base.inputs[PSSENSE_INDEX_##NAME].name = XRT_INPUT_PSSENSE_##NAME)
intpssense_found(struct xrt_prober *xp, struct xrt_prober_device **devices, size_t device_count, size_t index, cJSON *attached_data, struct xrt_device **out_xdevs)struct xrt_device *pssense_create(struct xrt_prober *xp, struct xrt_prober_device *xpdev){ struct os_hid_device *hid = NULL; int ret;
ret = xrt_prober_open_hid_interface(xp, devices[index], 0, &hid); ret = xrt_prober_open_hid_interface(xp, xpdev, 0, &hid); if (ret != 0) { U_LOG_E("Failed to open HID interface for PlayStation Sense controller!"); return -1; return NULL; }
unsigned char product_name[128]; ret = xrt_prober_get_string_descriptor( // xp, // devices[index], // xpdev, // XRT_PROBER_STRING_PRODUCT, // product_name, // sizeof(product_name)); // if (ret <= 0) { U_LOG_E("Failed to get product name from Bluetooth device!"); return -1; return NULL; }
enum u_device_alloc_flags flags = U_DEVICE_ALLOC_TRACKING_NONE; struct pssense_device *pssense = U_DEVICE_ALLOCATE(struct pssense_device, flags, 23, 2);16 unmodified lines
pssense->log_level = debug_get_log_option_pssense_log(); pssense->hid = hid;
if (devices[index]->product_id == PSSENSE_PID_LEFT) { if (xpdev->product_id == PSSENSE_PID_LEFT) { pssense->base.device_type = XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER; pssense->hand = PSSENSE_HAND_LEFT; } else if (devices[index]->product_id == PSSENSE_PID_RIGHT) { } else if (xpdev->product_id == PSSENSE_PID_RIGHT) { pssense->base.device_type = XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER; pssense->hand = PSSENSE_HAND_RIGHT; } else { PSSENSE_ERROR(pssense, "Unable to determine controller type"); pssense_device_destroy(&pssense->base); return -1; return NULL; }
SET_INPUT(PS_CLICK); SET_INPUT(SHARE_CLICK);25 unmodified lines ret = os_mutex_init(&pssense->lock); if (ret != 0) { PSSENSE_ERROR(pssense, "Failed to init mutex!"); pssense_device_destroy(&pssense->base); return -1; return NULL; }
ret = os_thread_helper_init(&pssense->controller_thread); if (ret != 0) { PSSENSE_ERROR(pssense, "Failed to init threading!"); pssense_device_destroy(&pssense->base); return -1; return NULL; }
ret = os_thread_helper_start(&pssense->controller_thread, pssense_run_thread, pssense); if (ret != 0) { PSSENSE_ERROR(pssense, "Failed to start thread!"); pssense_device_destroy(&pssense->base); return -1; return NULL; }
if (!pssense_get_calibration_data(pssense)) { PSSENSE_ERROR(pssense, "Failed to retrieve calibration data"); pssense_device_destroy(&pssense->base); return -1; return NULL; }
u_var_add_root(pssense, pssense->base.str, false); u_var_add_log_level(pssense, &pssense->log_level, "Log level");29 unmodified lines u_var_add_ro_vec3_i32(pssense, &pssense->state.gyro_raw, "Raw Gyro"); u_var_add_ro_vec3_i32(pssense, &pssense->state.accel_raw, "Raw Accel"); u_var_add_pose(pssense, &pssense->pose, "Pose");
out_xdevs[0] = &pssense->base; return &pssense->base;}
intpssense_found(struct xrt_prober *xp, struct xrt_prober_device **devices, size_t device_count, size_t index, cJSON *attached_data, struct xrt_device **out_xdevs){ struct xrt_prober_device *xpdev = devices[index];
struct xrt_device *xdev = pssense_create(xp, xpdev); if (xdev == NULL) { return -1; }
out_xdevs[0] = xdev; return 1;}
/*!2 unmodified lines25 unmodified lines2627282930313233343536373839404118 unmodified lines25 unmodified lines#define PSSENSE_PID_LEFT 0x0E45#define PSSENSE_PID_RIGHT 0x0E46
/*! * Create a PlayStation Sense controller device. * * @ingroup drv_pssense */struct xrt_device *pssense_create(struct xrt_prober *xp, struct xrt_prober_device *xpdev);
/*! * Probing function for PlayStation Sense devices. * * @ingroup drv_pssense * @see xrt_prober_found_func_t18 unmodified lines