use thread_safe wrapper for hmd battery
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "wivrn_hmd.h"
|
||||
#include "math/m_api.h"
|
||||
#include "os/os_time.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_session.h"
|
||||
@@ -148,8 +147,7 @@ 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
|
||||
std::lock_guard lock(mutex);
|
||||
battery = new_battery;
|
||||
*battery.lock() = new_battery;
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_hmd::get_presence(bool * out_presence)
|
||||
@@ -204,10 +202,10 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present,
|
||||
bool * out_charging,
|
||||
float * out_charge)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
*out_present = battery.present;
|
||||
*out_charging = battery.charging;
|
||||
*out_charge = battery.charge;
|
||||
auto bat = battery.lock();
|
||||
*out_present = bat->present;
|
||||
*out_charging = bat->charging;
|
||||
*out_charge = bat->charge;
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
@@ -36,8 +35,6 @@ class wivrn_session;
|
||||
|
||||
class wivrn_hmd : public xrt_device
|
||||
{
|
||||
std::mutex mutex;
|
||||
|
||||
xrt_input pose_input{
|
||||
.active = true,
|
||||
.name = XRT_INPUT_GENERIC_HEAD_POSE,
|
||||
@@ -52,7 +49,7 @@ class wivrn_hmd : public xrt_device
|
||||
};
|
||||
|
||||
view_list views;
|
||||
from_headset::battery battery{};
|
||||
thread_safe<from_headset::battery> battery{};
|
||||
|
||||
std::atomic<bool> presence{true};
|
||||
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||
|
||||
Reference in New Issue
Block a user