Forward controller battery info via XR_EXT_interaction_profile_battery_state_display
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user