Monado OpenXR Runtime
Loading...
Searching...
No Matches
pimax_p2.h
Go to the documentation of this file.
1// Copyright 2024, Coreforge
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Pimax P2 driver header - inherits xrt_device.
6 * @author Coreforge <BC549b@gmail.com>
7 * @ingroup drv_pimax_p2
8 */
9
10#pragma once
11#include "xrt/xrt_device.h"
12
13#include "os/os_threading.h"
14#include "util/u_var.h"
15
16#include <hidapi/hidapi.h>
17
18
19#define PIMAX_P2_MODEL_NAME_LENGTH 32
20
21/*!
22 * @defgroup drv_pimax_p2 Pimax P2 HMD driver
23 * @ingroup drv
24 *
25 * @brief Driver for the HID device of Pimax P2 HMDs.
26 */
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32struct pimax_p2_device;
33
34/*!
35 * Initializes the Pimax HID device, enables the displays, and allocates and
36 * populates pdev with data.
37 * Should be called before lighthouse init.
38 * If no Pimax P2 HID is found or an error occurs, returns false.
39 *
40 * @ingroup drv_pimax_p2
41 */
42bool
43pimax_p2_init(struct pimax_p2_device **pdev);
44
45/*!
46 * Fills the xrt_hmd_parts with data.
47 *
48 * @ingroup drv_pimax_p2
49 */
50bool
51pimax_p2_setup_hmd(struct pimax_p2_device *pdev, struct xrt_hmd_parts *hmd);
52
53/*!
54 * Like xrt_device->get_view_poses, but does not fill in the head relation.
55 * Tracking must be handled separately.
56 *
57 * @ingroup drv_pimax_p2
58 */
61 const struct xrt_vec3 *default_eye_relation,
62 struct xrt_hmd_parts *hmd,
63 uint32_t view_count,
64 struct xrt_fov *out_fovs,
65 struct xrt_pose *out_poses);
66
67
68/*!
69 * Compute distortion, using the mesh loaded by init.
70 *
71 * @ingroup drv_pimax_p2
72 */
75 struct pimax_p2_device *dev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result);
76
77/*!
78 * Get backlight brightness from 0 to 1.
79 *
80 * @ingroup drv_pimax_p2
81 */
83pimax_p2_get_brightness(struct pimax_p2_device *dev, float *out_brightness);
84
85/*!
86 * Set backlight brightness from 0 to 1.
87 *
88 * @ingroup drv_pimax_p2
89 */
91pimax_p2_set_brightness(struct pimax_p2_device *dev, float brightness, bool relative);
92
93/*!
94 * Clean up a pimax_p2_device.
95 *
96 * @ingroup drv_pimax_p2
97 */
98void
100
101struct pimax_p2_device;
102
104{
105 struct xrt_vec2 size_in_meters;
106 uint32_t pixels_width;
107 uint32_t pixels_height;
108 uint32_t refresh_rate;
109 float nominal_frame_interval_ns;
110 float gap;
111};
112
113typedef void (*pimax_p2_display_get_props_func_t)(struct pimax_p2_device *dev,
114 struct pimax_p2_display_properties *out_props);
115typedef void (*pimax_p2_init_display_func_t)(struct pimax_p2_device *dev);
116
117
119{
120 pimax_p2_display_get_props_func_t get_display_properties;
121 pimax_p2_init_display_func_t init_display;
122};
123
125{
126 const wchar_t product_name[PIMAX_P2_MODEL_NAME_LENGTH]; // the name in the USB descriptor
127 const char display_name[PIMAX_P2_MODEL_NAME_LENGTH]; // the name for the xdev
128 const char *default_mesh_name;
129 struct pimax_p2_model_funcs funcs;
130};
131
133{
134 struct xrt_fov fov;
135 size_t len;
136 float *data;
137};
138
140{
141 float ipd;
142 struct pimax_p2_view_mesh views[2];
143};
144
146{
147 size_t mesh_count;
148 struct pimax_p2_mesh *meshes;
149};
150
152{
153 struct pimax_p2_model_funcs *model_funcs;
154 const char *default_mesh_name;
155
156 char display_name[XRT_DEVICE_NAME_LEN];
157
158 struct pimax_p2_mesh_set *mesh_set;
159
160 hid_device *hid_dev;
161 struct os_mutex hid_mutex;
163 {
164 float ipd;
165 float separation;
166 int brightness;
167 bool upscaling;
168 struct u_var_draggable_f32 offset_h_0;
169 struct u_var_draggable_f32 offset_h_1;
170 struct u_var_draggable_f32 offset_v_0;
171 struct u_var_draggable_f32 offset_v_1;
172 } device_config;
173
174 // as the mutex and thread are direct struct members, they cannot be set to NULL to indicate status
175 enum
176 {
177 PIMAX_P2_INIT_STATE_HID_MUTEX = 1 << 0,
178 // hid_dev can just be checked for NULL
179 PIMAX_P2_INIT_STATE_HID_THREAD = 1 << 1,
180 PIMAX_P2_INIT_STATE_HID_THREAD_RUNNING = 1 << 2,
181 } init_state_flags;
182
183 struct os_thread poll_thread;
184 bool should_poll;
185 uint32_t polls_since_last_keepalive;
186
187 bool always_update_distortion;
188};
189
190#ifdef __cplusplus
191}
192#endif
xrt_result_t pimax_p2_set_brightness(struct pimax_p2_device *dev, float brightness, bool relative)
Set backlight brightness from 0 to 1.
Definition pimax_p2.c:931
bool pimax_p2_init(struct pimax_p2_device **pdev)
Initializes the Pimax HID device, enables the displays, and allocates and populates pdev with data.
Definition pimax_p2.c:1077
xrt_result_t pimax_p2_get_brightness(struct pimax_p2_device *dev, float *out_brightness)
Get backlight brightness from 0 to 1.
Definition pimax_p2.c:921
xrt_result_t pimax_p2_compute_distortion_from_mesh(struct pimax_p2_device *dev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result)
Compute distortion, using the mesh loaded by init.
Definition pimax_p2.c:949
void pimax_p2_destroy(struct pimax_p2_device *dev)
Clean up a pimax_p2_device.
Definition pimax_p2.c:1111
xrt_result_t pimax_p2_get_view_poses(struct pimax_p2_device *dev, const struct xrt_vec3 *default_eye_relation, struct xrt_hmd_parts *hmd, uint32_t view_count, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
Like xrt_device->get_view_poses, but does not fill in the head relation.
Definition pimax_p2.c:845
bool pimax_p2_setup_hmd(struct pimax_p2_device *pdev, struct xrt_hmd_parts *hmd)
Fills the xrt_hmd_parts with data.
Definition pimax_p2.c:1139
enum xrt_result xrt_result_t
Result type used across Monado.
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition os_threading.h:69
A wrapper around a native thread.
Definition os_threading.h:298
Definition pimax_p2.h:152
Definition pimax_p2.h:104
Definition pimax_p2.h:146
Definition pimax_p2.h:140
Definition pimax_p2.h:125
Definition pimax_p2.h:119
Definition pimax_p2.h:133
Draggable single precision float information.
Definition u_var.h:134
Describes a projection matrix fov.
Definition xrt_defines.h:542
All of the device components that deals with interfacing to a users head.
Definition xrt_device.h:165
A pose composed of a position and orientation.
Definition xrt_defines.h:522
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition xrt_defines.h:300
A 2 element vector with single floats.
Definition xrt_defines.h:279
A 3 element vector with single floats.
Definition xrt_defines.h:310
Variable tracking code.
Header defining an xrt display or controller device.