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