Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send device battery levels over OSC #108

Merged
merged 7 commits into from
Nov 24, 2024

Conversation

cubee-cb
Copy link
Contributor

@cubee-cb cubee-cb commented Nov 24, 2024

I've edited the osc.rs file to send HMD, controller, and tracker battery levels and charging state over OSC to VRChat.
It takes in AppState as a new parameter, but could probably pass just the raw list of devices unless we want to add more parameters like FPS or IPD, etc.

For now there is a workaround for HMD battery specifically as XSOverlay has no parameter for it, and OVR Toolkit uses an int 0-100. I implement both 0-100 as hmdBattery and 0-1 as headsetBattery.

I can only test the HMD battery on Monado at the moment (WiVRn with PICO 4), so controller batteries, tracker batteries, and SteamVR devices are untested.

Parameters are based on the XSOverlay format, excluding average battery levels but adding charging state. Charging state in my testing is delayed, I expect it only updates when the battery level is updated.

headsetBattery (float)
leftControllerBattery (float)
leftControllerCharging (bool)
tracker0Battery (float)
tracker0Charging (bool)
etc...

i _understand_ now!
basically, i did it the "wrong" way first by modifying openxr.rs and openvr.rs to pass battery levels to osc, when really i could have just made osc get the pre-formatted device details from AppState. live and learn, i'm new to rust anyway.
this is just to make sure the unwrap() doesn't crash; -1 (or any negative value) is used as the "disconnected" value.
this means parameter can be immutable if left unset at initialisation, and we can use format!() macro in the match statements. silly workarounds no more!
Copy link
Owner

@galister galister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no reason to send battery states out 10 times/second

let's add a separate timer for sending the battery states (similar to self.last_sent), once per 10s maybe?

@cubee-cb
Copy link
Contributor Author

cubee-cb commented Nov 24, 2024

true.
i'm not quite understanding last_sent, i see it being set to Instant::now when the OscSender is created, but that is the only time i can see it being set. how does that know when the last message was sent?

@cubee-cb
Copy link
Contributor Author

cubee-cb commented Nov 24, 2024

you know, i thought the osc debug menu was updating a little fast for 10 times per second (updated values being fully lit all the time).
i think last_sent is not being reset at all, so elapsed time is always more than 100ms, so it sends every frame instead.
i guess i'll fix that then.

i added a second Instant for the batteries that only sends after 10 seconds, and the battery parameters are constantly lit still.

@galister
Copy link
Owner

ok, mind fixing that as well?
also, we should ideally store next_send instead of last_sent so that there's less calculation involved

@cubee-cb
Copy link
Contributor Author

next_send as in, set an instant in the future, then send once that expires?

@cubee-cb
Copy link
Contributor Author

i've fixed the timers, i won't change them to next_send just yet because i'm not quite sure how to do that, but i might look at it tomorrow.

Copy link
Owner

@galister galister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, i think it's good as is. gonna run the actions and merge when i'm back

@galister galister merged commit a71f4de into galister:main Nov 24, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants