Forward controller battery info via XR_EXT_interaction_profile_battery_state_display

This commit is contained in:
Sapphire committed 2026-11-11 16:23:54 -05:00
1 parent aba0210923
commit 2233817b59
10 files changed
+159 -14

No files matched your search

+1
View File
@@ -1376,6 +1376,7 @@ void application::initialize()
XR_KHR_MAINTENANCE1_EXTENSION_NAME,
XR_KHR_VISIBILITY_MASK_EXTENSION_NAME,
XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME,
XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME,
XR_EXT_HAND_INTERACTION_EXTENSION_NAME,
XR_EXT_HAND_TRACKING_EXTENSION_NAME,
+1
View File
@@ -286,6 +286,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.settings.mirror_gamepad = config.forward_gamepad;
info.settings.enabled_body_parts = config.body_part_mask;
info.battery_status = self->instance.has_extension(XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME);
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
+49 -3
View File
@@ -346,6 +346,8 @@ void scenes::stream::tracking()
std::vector<serialization_packet> packets;
const bool battery = instance.has_extension(XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME);
const bool hand_tracking = config.check_feature(feature::hand_tracking);
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
@@ -594,12 +596,56 @@ void scenes::stream::tracking()
if (next_battery_check < now)
{
auto status = get_battery_status();
network_session->send_stream(from_headset::battery{
.charge = status.charge.value_or(-1),
.present = status.charge.has_value(),
network_session->send_control(from_headset::battery{
.device = device_id::HEAD,
.charge = status.charge,
.charging = status.charging,
});
if (battery)
{
static std::array paths{
std::make_pair("/user/hand/left", device_id::LEFT_CONTROLLER),
std::make_pair("/user/hand/right", device_id::RIGHT_CONTROLLER),
std::make_pair("/user/gamepad", device_id::GAMEPAD),
};
for (auto [path, device]: paths)
{
XrResult res;
XrPath p;
if (res = xrStringToPath(instance, path, &p); !XR_SUCCEEDED(res))
{
spdlog::warn("xrStringToPath(\"{}\") returned {} when querying battery, continuing", path, xr::to_string(res));
continue;
}
XrBatteryStateDisplayEXT battery_state{
.type = XR_TYPE_BATTERY_STATE_DISPLAY_EXT,
};
XrInteractionProfileState profile_state{
.type = XR_TYPE_INTERACTION_PROFILE_STATE,
.next = &battery_state,
};
if (res = xrGetCurrentInteractionProfile(session, p, &profile_state); !XR_SUCCEEDED(res))
{
spdlog::warn("xrGetCurrentInteractionProfile returned {} when querying battery, continuing", xr::to_string(res));
continue;
}
std::optional<float> charge{};
if (battery_state.stateFlags & XR_BATTERY_STATE_DISPLAY_STATE_VALID_BIT_EXT)
charge = battery_state.batteryLevel;
network_session->send_control(from_headset::battery{
.device = device,
.charge = charge,
.charging = (battery_state.stateFlags & XR_BATTERY_STATE_DISPLAY_STATE_CHARGING_BIT_EXT) != 0,
});
}
}
next_battery_check = now + battery_check_interval;
}
+11 -6
View File
@@ -154,10 +154,14 @@ enum class device_id : uint8_t
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
LEFT_HAND, // identify hand tracking
RIGHT_HAND, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
LEFT_CONTROLLER, // identify controller
RIGHT_CONTROLLER, // identify controller
LEFT_HAND = LEFT_CONTROLLER, // identify hand tracking
RIGHT_HAND = RIGHT_CONTROLLER, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
GAMEPAD, // identify gamepad
// Gamepad, microsoft/xbox_controller profile (/user/gamepad)
GAMEPAD_MENU_CLICK, // /user/gamepad/input/menu/click
@@ -346,6 +350,7 @@ struct headset_info_packet
};
std::optional<audio_description> speaker;
std::optional<audio_description> microphone;
bool battery_status; // supports XR_EXT_interaction_profile_battery_state_display, for reporting controller/gamepad battery status
bool hand_tracking;
bool eye_gaze;
bool palm_pose;
@@ -668,8 +673,8 @@ struct feedback
struct battery
{
float charge;
bool present;
device_id device;
std::optional<float> charge;
bool charging;
};
+30
View File
@@ -728,11 +728,13 @@ wivrn_controller::wivrn_controller(xrt_device_name name,
.orientation_tracking = true,
.position_tracking = true,
.hand_tracking = name != XRT_DEVICE_EXT_HAND_INTERACTION and cnx->get_info().hand_tracking,
.battery_status = cnx->get_info().battery_status,
},
.update_inputs = method_pointer<&wivrn_controller::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_controller::get_tracked_pose>,
.get_hand_tracking = method_pointer<&wivrn_controller::get_hand_tracking>,
.set_output = method_pointer<&wivrn_controller::set_output>,
.get_battery_status = method_pointer<&wivrn_controller::get_battery_status>,
.destroy = [](xrt_device *) {},
},
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
@@ -992,6 +994,26 @@ xrt_result_t wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t de
}
}
xrt_result_t wivrn_controller::get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge)
{
auto bat = battery.lock();
*out_charging = bat->charging;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
void wivrn_controller::set_derived_pose(const from_headset::derived_pose & derived)
{
auto list = [this](device_id id) -> pose_list * {
@@ -1008,6 +1030,14 @@ void wivrn_controller::set_derived_pose(const from_headset::derived_pose & deriv
target->set_derived(source, xrt_cast(derived.relation));
}
void wivrn_controller::update_battery(const from_headset::battery & new_battery)
{
const device_id device = device_type == XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER ? device_id::LEFT_CONTROLLER : device_id::RIGHT_CONTROLLER;
if (new_battery.device == device)
{
*battery.lock() = new_battery;
}
}
void wivrn_controller::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
aim.update_tracking(tracking, offset);
+8 -1
View File
@@ -20,6 +20,7 @@
#pragma once
#include "utils/thread_safe.h"
#include "xrt/xrt_device.h"
#include "hand_joints_list.h"
@@ -48,6 +49,8 @@ class wivrn_controller : public xrt_device
std::vector<xrt_input> inputs_array;
std::vector<xrt_output> outputs_array;
thread_safe<from_headset::battery> battery{};
wivrn::wivrn_session * cnx;
public:
@@ -58,12 +61,16 @@ public:
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
xrt_result_t get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns);
xrt_result_t get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge);
xrt_result_t set_output(xrt_output_name name, const xrt_output_value * value);
void set_inputs(const from_headset::inputs &, const clock_offset &);
void set_derived_pose(const from_headset::derived_pose &);
void update_battery(const from_headset::battery &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
+32
View File
@@ -42,9 +42,13 @@ wivrn_gamepad::wivrn_gamepad(wivrn::wivrn_session & cnx) :
.str = "WiVRn Gamepad",
.serial = "WiVRn Gamepad",
.tracking_origin = &origin,
.supported = {
.battery_status = cnx.get_info().battery_status,
},
.update_inputs = method_pointer<&wivrn_gamepad::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_gamepad::get_tracked_pose>,
.set_output = method_pointer<&wivrn_gamepad::set_output>,
.get_battery_status = method_pointer<&wivrn_gamepad::get_battery_status>,
.destroy = [](xrt_device *) {},
},
origin{
@@ -110,6 +114,34 @@ xrt_result_t wivrn_gamepad::get_tracked_pose(xrt_input_name name, int64_t, xrt_s
return XRT_ERROR_INPUT_UNSUPPORTED;
}
xrt_result_t wivrn_gamepad::get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge)
{
auto bat = battery.lock();
*out_charging = bat->charging;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
void wivrn_gamepad::set_battery(const from_headset::battery & new_battery)
{
if (new_battery.device == device_id::GAMEPAD)
{
*battery.lock() = new_battery;
}
}
void wivrn_gamepad::set_inputs(const from_headset::inputs & inputs)
{
std::lock_guard lock(mutex);
+7
View File
@@ -18,6 +18,7 @@
#pragma once
#include "utils/thread_safe.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
@@ -43,6 +44,8 @@ class wivrn_gamepad : public xrt_device
std::array<xrt_input, 18> inputs_staging; // written from the network thread, published by update_inputs
std::array<xrt_output, 4> outputs_array;
thread_safe<from_headset::battery> battery{};
wivrn::wivrn_session * cnx;
public:
@@ -51,8 +54,12 @@ public:
xrt_result_t update_inputs();
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
xrt_result_t get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge);
xrt_result_t set_output(xrt_output_name name, const xrt_output_value * value);
void set_battery(const from_headset::battery &);
// Update from a forwarded inputs packet (gamepad device_ids).
void set_inputs(const from_headset::inputs &);
void set_connected(bool);
+14 -4
View File
@@ -164,8 +164,10 @@ void wivrn_hmd::update_tracking(const from_headset::tracking & tracking, const c
void wivrn_hmd::update_battery(const from_headset::battery & new_battery)
{
// We will only request a new sample if the current one is consumed
*battery.lock() = new_battery;
if (new_battery.device == device_id::HEAD)
{
*battery.lock() = new_battery;
}
}
xrt_result_t wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation,
@@ -214,9 +216,17 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present,
float * out_charge)
{
auto bat = battery.lock();
*out_present = bat->present;
*out_charging = bat->charging;
*out_charge = bat->charge;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
+6
View File
@@ -822,6 +822,12 @@ void wivrn_session::operator()(from_headset::feedback && feedback)
void wivrn_session::operator()(from_headset::battery && battery)
{
hmd.update_battery(battery);
left_controller.update_battery(battery);
left_hand_interaction.update_battery(battery);
right_controller.update_battery(battery);
right_hand_interaction.update_battery(battery);
if (gamepad_device)
gamepad_device->set_battery(battery);
}
void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)