fix osc timer and give battery parameters their own timer
This commit is contained in:
@@ -324,7 +324,7 @@ pub fn openvr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
|
||||
|
||||
#[cfg(feature = "osc")]
|
||||
if let Some(ref mut sender) = osc_sender {
|
||||
let _ = sender.send_params(&overlays, &state); // i love inconsistent naming; in openxr.rs `state` is called `app_state`
|
||||
let _ = sender.send_params(&overlays, &state);
|
||||
};
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
|
||||
@@ -16,7 +16,8 @@ use crate::{
|
||||
use super::common::OverlayContainer;
|
||||
|
||||
pub struct OscSender {
|
||||
last_sent: Instant,
|
||||
last_sent_overlay: Instant,
|
||||
last_sent_battery: Instant,
|
||||
upstream: UdpSocket,
|
||||
}
|
||||
|
||||
@@ -34,7 +35,8 @@ impl OscSender {
|
||||
|
||||
Ok(Self {
|
||||
upstream,
|
||||
last_sent: Instant::now(),
|
||||
last_sent_overlay: Instant::now(),
|
||||
last_sent_battery: Instant::now(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,9 +57,9 @@ impl OscSender {
|
||||
where
|
||||
D: Default,
|
||||
{
|
||||
if self.last_sent.elapsed().as_millis() < 100 {
|
||||
return Ok(());
|
||||
}
|
||||
// send overlay data every 0.1 seconds
|
||||
if self.last_sent_overlay.elapsed().as_millis() >= 100 {
|
||||
self.last_sent_overlay = Instant::now();
|
||||
|
||||
let mut num_overlays = 0;
|
||||
let mut has_keyboard = false;
|
||||
@@ -95,7 +97,12 @@ impl OscSender {
|
||||
vec![OscType::Int(num_overlays)],
|
||||
)?;
|
||||
|
||||
// battery levels
|
||||
}
|
||||
|
||||
// send battery levels every 10 seconds
|
||||
if self.last_sent_battery.elapsed().as_millis() >= 10000 {
|
||||
self.last_sent_battery = Instant::now();
|
||||
|
||||
let mut tracker_idx = 0;
|
||||
|
||||
for device in &app.input_state.devices {
|
||||
@@ -139,7 +146,7 @@ impl OscSender {
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user