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 "OpenVRCosmosMapper.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 OpenVRCosmosMapper::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: a placeholder button for trackpad.
25   ++mNumButtons;
26   // Button 3: Thumbstick
27   GetButtonValueFromAction(aControllerState,
28                            aControllerInfo.mActionThumbstick_Pressed,
29                            aControllerInfo.mActionThumbstick_Touched);
30   // Button 4: A
31   GetButtonValueFromAction(aControllerState, aControllerInfo.mActionA_Pressed,
32                            aControllerInfo.mActionA_Touched);
33   // Button 5: B
34   GetButtonValueFromAction(aControllerState, aControllerInfo.mActionB_Pressed,
35                            aControllerInfo.mActionB_Touched);
36   // Button 6: Bumper
37   GetButtonValueFromAction(aControllerState,
38                            aControllerInfo.mActionBumper_Pressed,
39                            aControllerInfo.mActionBumper_Pressed);
40 
41   // Axis 0, 1: placeholder axes for touchpad.
42   mNumAxes += 2;
43   // Axis 2, 3: Thumbstick
44   GetAxisValueFromAction(aControllerState,
45                          aControllerInfo.mActionThumbstick_Analog);
46 
47   aControllerState.numButtons = mNumButtons;
48   aControllerState.numAxes = mNumAxes;
49 }
50 
51 }  // namespace mozilla::gfx