The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/steamvr_lh: implement battery status query

Co-authored-by: Gabriele Musco <gabmus@disroot.org>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2292>

authored by

Torge Matthies
Gabriele Musco
and committed by
Marge Bot
81d9d1ee 0f57657b

+60
+1
doc/changes/drivers/mr.2292.md
··· 1 + steamvr_lh: Implement battery status query. 1 2 survive: Implement battery status query.
+53
src/xrt/drivers/steamvr_lh/device.cpp
··· 184 184 { 185 185 this->device_type = XRT_DEVICE_TYPE_UNKNOWN; 186 186 this->container_handle = handle; 187 + 187 188 #define SETUP_MEMBER_FUNC(name) this->xrt_device::name = &device_bouncer<ControllerDevice, &ControllerDevice::name> 188 189 SETUP_MEMBER_FUNC(set_output); 189 190 SETUP_MEMBER_FUNC(get_hand_tracking); ··· 206 207 this->hand_tracking_supported = true; 207 208 this->force_feedback_supported = false; 208 209 this->form_factor_check_supported = false; 210 + this->battery_status_supported = true; 209 211 210 212 #define SETUP_MEMBER_FUNC(name) this->xrt_device::name = &device_bouncer<Device, &Device::name> 211 213 SETUP_MEMBER_FUNC(update_inputs); 212 214 SETUP_MEMBER_FUNC(get_tracked_pose); 215 + SETUP_MEMBER_FUNC(get_battery_status); 213 216 #undef SETUP_MEMBER_FUNC 214 217 215 218 this->xrt_device::destroy = [](xrt_device *xdev) { ··· 412 415 Device::get_pose(uint64_t at_timestamp_ns, xrt_space_relation *out_relation) 413 416 { 414 417 m_relation_history_get(this->relation_hist, at_timestamp_ns, out_relation); 418 + } 419 + 420 + xrt_result_t 421 + Device::get_battery_status(bool *out_present, bool *out_charging, float *out_charge) 422 + { 423 + *out_present = this->provides_battery_status; 424 + *out_charging = this->charging; 425 + *out_charge = this->charge; 426 + return XRT_SUCCESS; 415 427 } 416 428 417 429 void ··· 781 793 vsync_to_photon_ns = *static_cast<float *>(prop.pvBuffer) * 1e9f; 782 794 break; 783 795 } 796 + case vr::Prop_DeviceProvidesBatteryStatus_Bool: { 797 + float supported = *static_cast<bool *>(prop.pvBuffer); 798 + this->provides_battery_status = supported; 799 + DEV_DEBUG("Has battery status: HMD: %s", supported ? "true" : "false"); 800 + break; 801 + } 802 + case vr::Prop_DeviceIsCharging_Bool: { 803 + float charging = *static_cast<bool *>(prop.pvBuffer); 804 + this->charging = charging; 805 + DEV_DEBUG("Charging: HMD: %s", charging ? "true" : "false"); 806 + break; 807 + } 808 + case vr::Prop_DeviceBatteryPercentage_Float: { 809 + float bat = *static_cast<float *>(prop.pvBuffer); 810 + this->charge = bat; 811 + DEV_DEBUG("Battery: HMD: %f", bat); 812 + break; 813 + } 784 814 default: { 785 815 Device::handle_property_write(prop); 786 816 break; ··· 850 880 } 851 881 break; 852 882 } 883 + case vr::Prop_DeviceProvidesBatteryStatus_Bool: { 884 + float supported = *static_cast<bool *>(prop.pvBuffer); 885 + const char *name; 886 + switch (this->device_type) { 887 + case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: { 888 + name = "Left"; 889 + break; 890 + } 891 + case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: { 892 + name = "Right"; 893 + break; 894 + } 895 + default: { 896 + name = "Unknown"; 897 + break; 898 + } 899 + } 900 + this->provides_battery_status = supported; 901 + DEV_DEBUG("Has battery status: %s: %s", name, supported ? "true" : "false"); 902 + break; 903 + } 853 904 case vr::Prop_DeviceIsCharging_Bool: { 854 905 float charging = *static_cast<bool *>(prop.pvBuffer); 855 906 const char *name; ··· 866 917 name = "Unknown"; 867 918 } 868 919 } 920 + this->charging = charging; 869 921 DEV_DEBUG("Charging: %s: %s", name, charging ? "true" : "false"); 870 922 break; 871 923 } ··· 885 937 name = "Unknown"; 886 938 } 887 939 } 940 + this->charge = bat; 888 941 DEV_DEBUG("Battery: %s: %f", name, bat); 889 942 break; 890 943 }
+6
src/xrt/drivers/steamvr_lh/device.hpp
··· 72 72 virtual void 73 73 get_tracked_pose(xrt_input_name name, uint64_t at_timestamp_ns, xrt_space_relation *out_relation) = 0; 74 74 75 + xrt_result_t 76 + get_battery_status(bool *out_present, bool *out_charging, float *out_charge); 77 + 75 78 protected: 76 79 Device(const DeviceBuilder &builder); 77 80 std::shared_ptr<Context> ctx; ··· 83 86 std::string manufacturer; 84 87 std::string model; 85 88 float vsync_to_photon_ns{0.f}; 89 + bool provides_battery_status{false}; 90 + bool charging{false}; 91 + float charge{1.0F}; 86 92 87 93 virtual void 88 94 handle_property_write(const vr::PropertyWrite_t &prop);