Skip to content

Commit

Permalink
osc-battery: xsoverlay parity! add average tracker and controller bat…
Browse files Browse the repository at this point in the history
…tery parameters.

this should now be in parity with xsoverlay's parameters.

gone back to 1-indexing trackers because it's more user-friendly, so other programs can standardise more easily.
  • Loading branch information
cubee-cb committed Dec 28, 2024
1 parent 2db284b commit 85ab3f4
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/backend/osc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ impl OscSender {
if self.last_sent_battery.elapsed().as_millis() >= 10000 {
self.last_sent_battery = Instant::now();

let mut tracker_idx = 0;
let mut tracker_count: i8 = 0;
let mut controller_count: i8 = 0;
let mut tracker_total_bat = 0.0;
let mut controller_total_bat = 0.0;

for device in &app.input_state.devices {
let tracker_param;

// soc is the battery level (set to device status.charge)
let level = device.soc.unwrap_or(-1.0);
let parameter = match device.role {
TrackedDeviceRole::None => {""}
TrackedDeviceRole::None => {continue}
TrackedDeviceRole::Hmd => {
// legacy OVR Toolkit style (int)
// as of 20 Nov 2024 OVR Toolkit uses int 0-100, but this may change in a future update.
Expand All @@ -123,28 +126,44 @@ impl OscSender {

"headset"
}
TrackedDeviceRole::LeftHand => {"leftController"}
TrackedDeviceRole::RightHand => {"rightController"}
TrackedDeviceRole::LeftHand => {
controller_count += 1;
controller_total_bat += level;
"leftController"
}
TrackedDeviceRole::RightHand => {
controller_count += 1;
controller_total_bat += level;
"rightController"
}
TrackedDeviceRole::Tracker => {
tracker_param = format!("tracker{tracker_idx}");
tracker_idx += 1;
tracker_param = format!("tracker{tracker_count}");
tracker_count += 1;
tracker_total_bat += level;
tracker_param.as_str()
}
};

// send battery parameters
if !parameter.is_empty() {

self.send_message(
format!("/avatar/parameters/{parameter}Battery").into(),
vec![OscType::Float(level)],
)?;
self.send_message(
format!("/avatar/parameters/{parameter}Charging").into(),
vec![OscType::Bool(device.charging)],
)?;
}
// send device battery parameters
self.send_message(
format!("/avatar/parameters/{parameter}Battery").into(),
vec![OscType::Float(level)],
)?;
self.send_message(
format!("/avatar/parameters/{parameter}Charging").into(),
vec![OscType::Bool(device.charging)],
)?;
}

// send average controller and tracker battery parameters
self.send_message(
format!("/avatar/parameters/averageControllerBattery").into(),
vec![OscType::Float(controller_total_bat / controller_count as f32)],
)?;
self.send_message(
format!("/avatar/parameters/averageTrackerBattery").into(),
vec![OscType::Float(tracker_total_bat / tracker_count as f32)],
)?;
}

Ok(())
Expand Down

0 comments on commit 85ab3f4

Please sign in to comment.