Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Windows/Hid/HidInputDevice.h
5698 views
1
// This file in particular along with its cpp file is public domain, use it for whatever you want.
2
3
// Internal common header for Hid input stuff.
4
5
#pragma once
6
7
#include <set>
8
9
#include "Common/CommonTypes.h"
10
#include "Common/Input/InputState.h"
11
#include "Windows/InputDevice.h"
12
#include "Common/CommonWindows.h"
13
14
enum class HIDControllerType {
15
DualShock,
16
DualSense,
17
SwitchPro,
18
};
19
20
struct HIDControllerState {
21
// Analog sticks
22
s8 stickAxes[4]; // LX LY RX RY
23
// Analog triggers
24
u8 triggerAxes[2];
25
// Buttons. Here the mapping is specific to the controller type and resolved
26
// later.
27
u32 buttons; // Bitmask, PSButton enum
28
29
bool accValid = false;
30
bool gyroValid = false;
31
float accelerometer[3]; // X, Y, Z
32
float gyro[3];
33
};
34
35
struct ButtonInputMapping {
36
u32 button;
37
InputKeyCode keyCode;
38
};
39
40
// Supports a few specific HID input devices, namely DualShock and DualSense.
41
// More may be added later. Just picks the first one available, for now.
42
class HidInputDevice : public InputDevice {
43
public:
44
void Init() override;
45
int UpdateState() override;
46
void Shutdown() override;
47
48
static void AddSupportedDevices(std::set<u32> *deviceVIDPIDs);
49
bool HasAccelerometer() const override {
50
switch (subType_) {
51
case HIDControllerType::DualSense:
52
case HIDControllerType::SwitchPro:
53
return true;
54
default:
55
break;
56
}
57
return false;
58
}
59
private:
60
void ReleaseAllKeys(const ButtonInputMapping *buttonMappings, int count);
61
InputDeviceID DeviceID(int pad);
62
HIDControllerState prevState_{};
63
HIDControllerType subType_{};
64
HANDLE controller_;
65
std::string name_;
66
int pad_ = 0;
67
int pollCount_ = 0;
68
int inReportSize_ = 0;
69
int outReportSize_ = 0;
70
enum {
71
POLL_FREQ = 283, // a prime number.
72
};
73
};
74
75