Announcement

Collapse
No announcement yet.

Does anyone know how to get battery life in-game?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [VIVE] Does anyone know how to get battery life in-game?

    Hi, I just realised that the bars at the bottom of the controller represent remaining battery, in the scene you see when you open SteamVR and do nothing and put your HMD on.

    So apparently the variable can be retrieved somehow, question is where... I don't see any bp nodes on this. I tried to read the source but I didn't find anything useful as I'm not that good with C++.

    However I did find this post via Google: https://steamcommunity.com/app/35872...6528902079894/

    Though the Valve guy said it's useless, it was after all almost a year ago. Things might've changed now.

    And apparently he's using Unity, cuz by googling "SteamVR.cs" I was led to "openvr/unity_package/Assets/SteamVR/Scripts/SteamVR.cs" on the OpenVR Github repo.

    Then I noticed SteamVR's api is OpenVR (not to be confused with OSVR) so I went back in to read the source and found this at line 1007 of openvr.h:
    Code:
    virtual float GetFloatTrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0;
    At line 191 there's this "Prop_DeviceBatteryPercentage_Float" (the float that was mentioned in the steam community post). So as far as my understanding of cpp goes(which is probably a few milliemeters if not micrometers...) I should just include openvr.h in MotionControllerComponent and call this function and expose it to blueprint. But I really have no idea how to call this function... How do I get my vr::TrackedDeviceIndex_t for starters?

    Has anyone tried anything similar? I'd really appreciate any help on this.

    PS: I was thinking about making a flashlight and the light flickers when the actual controller's battery is low.

    #2
    Good news is that I have an example for you, bad news is that working with the openVR library is not an enjoyable experience currently. Epic has comments noting that when they update to the next version they can do things in a more sane manner, but for now since everything is on an old steam SDK version they are directly loading the .dll and creating pointers to the functions manually (direct system paths in Windows). Since all of the important accessing and references are done in a private structure you kind of have to re-implement their direct DLL mapping instead of being able to access it (or at least after a few days of linker hell that is all that I could get working).

    You can do it the normal way (openVRs getInterface()) in editor builds but when packaging out it loses the DLL context and needs the direct accessing method instead for the time being.


    I have all of the interesting tracked device properties accessible in here:
    https://bitbucket.org/mordentral/vre...unctionLibrary

    GetVRDeviceProperty has a Float version that returns Prop_DeviceBatteryPercentage_Float as one of its Enum options.

    Sadly their device ID to Object mapping array is also private currently and inaccessible so you won't have any direct link between a controller and which device it is in OpenVR and will have to infer it yourself. I believe that the first tracked controller is always the right handed one? But I didn't look into it too heavily so I may be remembering wrong.
    Last edited by mordentral; 07-29-2016, 08:15 AM.


    Consider supporting me on patreon

    My Open source tools and plugins
    Advanced Sessions Plugin
    VR Expansion Plugin

    Comment


      #3
      Thanks for helping. So basically it's far too over my head... since I didn't understand most of what your wrote...

      I'll still try tinkering with your plugin though, thx for sharing.

      Comment


        #4
        Originally posted by vito0719 View Post
        Thanks for helping. So basically it's far too over my head... since I didn't understand most of what your wrote...

        I'll still try tinkering with your plugin though, thx for sharing.
        Well, I mean you could just use the plugin in that case. But installing a plugin just for a battery life indicator might not be what you want to do (or might, I have no idea how important it is to you).


        Consider supporting me on patreon

        My Open source tools and plugins
        Advanced Sessions Plugin
        VR Expansion Plugin

        Comment


          #5
          Originally posted by mordentral View Post
          Well, I mean you could just use the plugin in that case. But installing a plugin just for a battery life indicator might not be what you want to do (or might, I have no idea how important it is to you).
          Oh really... That's cool. It's not a critical gameplay feature obviously, but I think it's fun and by a rough look I think your plugin has much more function than just that. I'll be sure to check it out, cheers mate!

          Edit: Though it's not a very important feature, I'm still willing to compile a custom made engine for it if I have to...
          Last edited by vito0719; 08-01-2016, 11:37 PM.

          Comment


            #6
            I know I'm reviving an old thread, but is there now an easier way of getting the battery life in-game?

            Comment

            Working...
            X