1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "OpenVRWMRMapper.h"
8 
9 #include "moz_external_vr.h"
10 #include "VRSession.h"
11 
12 namespace mozilla::gfx {
13 
UpdateButtons(VRControllerState & aControllerState,ControllerInfo & aControllerInfo)14 void OpenVRWMRMapper::UpdateButtons(VRControllerState& aControllerState,
15                                     ControllerInfo& aControllerInfo) {
16   mNumButtons = mNumAxes = 0;
17   // Button 0: Trigger
18   GetTriggerValueFromAction(aControllerState,
19                             aControllerInfo.mActionTrigger_Value);
20   // Button 1: Grip
21   GetButtonValueFromAction(aControllerState,
22                            aControllerInfo.mActionGrip_Pressed,
23                            aControllerInfo.mActionGrip_Touched);
24   // Button 2: Touchpad
25   GetButtonValueFromAction(aControllerState,
26                            aControllerInfo.mActionTrackpad_Pressed,
27                            aControllerInfo.mActionTrackpad_Touched);
28   // Button 3: Thumbstick.
29   GetButtonValueFromAction(aControllerState,
30                            aControllerInfo.mActionThumbstick_Pressed,
31                            aControllerInfo.mActionThumbstick_Touched);
32   // Button 4: Menu
33   GetButtonValueFromAction(aControllerState,
34                            aControllerInfo.mActionMenu_Pressed,
35                            aControllerInfo.mActionMenu_Touched);
36 
37   // Compared to Edge, we have a wrong implementation for the vertical axis
38   // value. In order to not affect the current VR content, we add a workaround
39   // for yAxis.
40   // Axis 0, 1: Trackpad
41   GetAxisValueFromAction(aControllerState,
42                          aControllerInfo.mActionTrackpad_Analog, true);
43   // Axis 2, 3: Thumbstick
44   GetAxisValueFromAction(aControllerState,
45                          aControllerInfo.mActionThumbstick_Analog, true);
46 
47   aControllerState.numButtons = mNumButtons;
48   aControllerState.numAxes = mNumAxes;
49 }
50 
51 }  // namespace mozilla::gfx