summaryrefslogtreecommitdiff
path: root/src/core/hid/input_interpreter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid/input_interpreter.h')
-rw-r--r--src/core/hid/input_interpreter.h111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/core/hid/input_interpreter.h b/src/core/hid/input_interpreter.h
deleted file mode 100644
index 3569aac93..000000000
--- a/src/core/hid/input_interpreter.h
+++ /dev/null
@@ -1,111 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/common_types.h"
9
10namespace Core {
11class System;
12}
13
14namespace Core::HID {
15enum class NpadButton : u64;
16}
17
18namespace Service::HID {
19class NPad;
20}
21
22/**
23 * The InputInterpreter class interfaces with HID to retrieve button press states.
24 * Input is intended to be polled every 50ms so that a button is considered to be
25 * held down after 400ms has elapsed since the initial button press and subsequent
26 * repeated presses occur every 50ms.
27 */
28class InputInterpreter {
29public:
30 explicit InputInterpreter(Core::System& system);
31 virtual ~InputInterpreter();
32
33 /// Gets a button state from HID and inserts it into the array of button states.
34 void PollInput();
35
36 /// Resets all the button states to their defaults.
37 void ResetButtonStates();
38
39 /**
40 * Checks whether the button is pressed.
41 *
42 * @param button The button to check.
43 *
44 * @returns True when the button is pressed.
45 */
46 [[nodiscard]] bool IsButtonPressed(Core::HID::NpadButton button) const;
47
48 /**
49 * Checks whether any of the buttons in the parameter list is pressed.
50 *
51 * @tparam HIDButton The buttons to check.
52 *
53 * @returns True when at least one of the buttons is pressed.
54 */
55 template <Core::HID::NpadButton... T>
56 [[nodiscard]] bool IsAnyButtonPressed() {
57 return (IsButtonPressed(T) || ...);
58 }
59
60 /**
61 * The specified button is considered to be pressed once
62 * if it is currently pressed and not pressed previously.
63 *
64 * @param button The button to check.
65 *
66 * @returns True when the button is pressed once.
67 */
68 [[nodiscard]] bool IsButtonPressedOnce(Core::HID::NpadButton button) const;
69
70 /**
71 * Checks whether any of the buttons in the parameter list is pressed once.
72 *
73 * @tparam T The buttons to check.
74 *
75 * @returns True when at least one of the buttons is pressed once.
76 */
77 template <Core::HID::NpadButton... T>
78 [[nodiscard]] bool IsAnyButtonPressedOnce() const {
79 return (IsButtonPressedOnce(T) || ...);
80 }
81
82 /**
83 * The specified button is considered to be held down if it is pressed in all 9 button states.
84 *
85 * @param button The button to check.
86 *
87 * @returns True when the button is held down.
88 */
89 [[nodiscard]] bool IsButtonHeld(Core::HID::NpadButton button) const;
90
91 /**
92 * Checks whether any of the buttons in the parameter list is held down.
93 *
94 * @tparam T The buttons to check.
95 *
96 * @returns True when at least one of the buttons is held down.
97 */
98 template <Core::HID::NpadButton... T>
99 [[nodiscard]] bool IsAnyButtonHeld() const {
100 return (IsButtonHeld(T) || ...);
101 }
102
103private:
104 std::shared_ptr<Service::HID::NPad> npad;
105
106 /// Stores 9 consecutive button states polled from HID.
107 std::array<Core::HID::NpadButton, 9> button_states{};
108
109 std::size_t previous_index{};
110 std::size_t current_index{};
111};