From 59d9d832d65b209aa84381c92d2a89fdaf9ef543 Mon Sep 17 00:00:00 2001 From: Torge Matthies Date: Tue, 30 Jul 2024 16:06:56 +0200 Subject: [PATCH] xrt: add device battery status query Co-authored-by: Gabriele Musco Part-of: --- doc/changes/auxiliary/mr.2292.md | 1 + doc/changes/xrt/mr.2292.md | 1 + src/xrt/auxiliary/util/u_device.c | 7 +++++++ src/xrt/auxiliary/util/u_device.h | 8 ++++++++ src/xrt/include/xrt/xrt_device.h | 30 ++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 doc/changes/auxiliary/mr.2292.md create mode 100644 doc/changes/xrt/mr.2292.md diff --git a/doc/changes/auxiliary/mr.2292.md b/doc/changes/auxiliary/mr.2292.md new file mode 100644 index 000000000..699726921 --- /dev/null +++ b/doc/changes/auxiliary/mr.2292.md @@ -0,0 +1 @@ +a/util: Add not-implemented fallback function for `xrd_device::get_battery_status`. diff --git a/doc/changes/xrt/mr.2292.md b/doc/changes/xrt/mr.2292.md new file mode 100644 index 000000000..4adb75bab --- /dev/null +++ b/doc/changes/xrt/mr.2292.md @@ -0,0 +1 @@ +Add a `get_battery_status` function to `xrt_device` for getting the device's battery status info. diff --git a/src/xrt/auxiliary/util/u_device.c b/src/xrt/auxiliary/util/u_device.c index 7ffaeb135..9db948adc 100644 --- a/src/xrt/auxiliary/util/u_device.c +++ b/src/xrt/auxiliary/util/u_device.c @@ -539,3 +539,10 @@ u_device_ni_is_form_factor_available(struct xrt_device *xdev, enum xrt_form_fact E(is_form_factor_available); return false; } + +xrt_result_t +u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge) +{ + E(get_battery_status); + return XRT_ERROR_NOT_IMPLEMENTED; +} diff --git a/src/xrt/auxiliary/util/u_device.h b/src/xrt/auxiliary/util/u_device.h index d55521a6e..920415906 100644 --- a/src/xrt/auxiliary/util/u_device.h +++ b/src/xrt/auxiliary/util/u_device.h @@ -259,6 +259,14 @@ u_device_ni_get_visibility_mask(struct xrt_device *xdev, bool u_device_ni_is_form_factor_available(struct xrt_device *xdev, enum xrt_form_factor form_factor); +/*! + * Not implemented function for @ref xrt_device::get_battery_status. + * + * @ingroup aux_util + */ +xrt_result_t +u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge); + #ifdef __cplusplus } diff --git a/src/xrt/include/xrt/xrt_device.h b/src/xrt/include/xrt/xrt_device.h index 5174c3bbb..b9cec163a 100644 --- a/src/xrt/include/xrt/xrt_device.h +++ b/src/xrt/include/xrt/xrt_device.h @@ -269,6 +269,7 @@ struct xrt_device bool stage_supported; bool face_tracking_supported; bool body_tracking_supported; + bool battery_status_supported; /* * @@ -502,6 +503,19 @@ struct xrt_device */ bool (*is_form_factor_available)(struct xrt_device *xdev, enum xrt_form_factor form_factor); + /*! + * @brief Get battery status information. + * + * @param[in] xdev The device. + * @param[out] out_present Whether battery status information exist for this device. + * @param[out] out_charging Whether the device's battery is being charged. + * @param[out] out_charge Battery charge as a value between 0 and 1. + */ + xrt_result_t (*get_battery_status)(struct xrt_device *xdev, + bool *out_present, + bool *out_charging, + float *out_charge); + /*! * Destroy device. */ @@ -702,6 +716,22 @@ xrt_device_is_form_factor_available(struct xrt_device *xdev, enum xrt_form_facto return xdev->is_form_factor_available(xdev, form_factor); } +/*! + * Helper function for @ref xrt_device::get_battery_status. + * + * @copydoc xrt_device::get_battery_status + * + * @public @memberof xrt_device + */ +static inline xrt_result_t +xrt_device_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge) +{ + if (xdev->get_battery_status == NULL) { + return XRT_ERROR_NOT_IMPLEMENTED; + } + return xdev->get_battery_status(xdev, out_present, out_charging, out_charge); +} + /*! * Helper function for @ref xrt_device::destroy. *