forked from espressif/arduino-esp32
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUSBHIDGamepad.h
87 lines (75 loc) · 2.77 KB
/
USBHIDGamepad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "USBHID.h"
#if CONFIG_TINYUSB_HID_ENABLED
/// Standard Gamepad Buttons Naming from Linux input event codes
/// https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
#define BUTTON_A 0
#define BUTTON_B 1
#define BUTTON_C 2
#define BUTTON_X 3
#define BUTTON_Y 4
#define BUTTON_Z 5
#define BUTTON_TL 6
#define BUTTON_TR 7
#define BUTTON_TL2 8
#define BUTTON_TR2 9
#define BUTTON_SELECT 10
#define BUTTON_START 11
#define BUTTON_MODE 12
#define BUTTON_THUMBL 13
#define BUTTON_THUMBR 14
#define BUTTON_SOUTH BUTTON_A
#define BUTTON_EAST BUTTON_B
#define BUTTON_NORTH BUTTON_X
#define BUTTON_WEST BUTTON_Y
/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes)
#define HAT_CENTER 0
#define HAT_UP 1
#define HAT_UP_RIGHT 2
#define HAT_RIGHT 3
#define HAT_DOWN_RIGHT 4
#define HAT_DOWN 5
#define HAT_DOWN_LEFT 6
#define HAT_LEFT 7
#define HAT_UP_LEFT 8
class USBHIDGamepad: public USBHIDDevice {
private:
USBHID hid;
int8_t _x; ///< Delta x movement of left analog-stick
int8_t _y; ///< Delta y movement of left analog-stick
int8_t _z; ///< Delta z movement of right analog-joystick
int8_t _rz; ///< Delta Rz movement of right analog-joystick
int8_t _rx; ///< Delta Rx movement of analog left trigger
int8_t _ry; ///< Delta Ry movement of analog right trigger
uint8_t _hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
uint32_t _buttons; ///< Buttons mask for currently pressed buttons
bool write();
public:
USBHIDGamepad(void);
void begin(void);
void end(void);
bool leftStick(int8_t x, int8_t y);
bool rightStick(int8_t z, int8_t rz);
bool leftTrigger(int8_t rx);
bool rightTrigger(int8_t ry);
bool hat(uint8_t hat);
bool pressButton(uint8_t button);
bool releaseButton(uint8_t button);
bool send(int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons);
// internal use
uint16_t _onGetDescriptor(uint8_t* buffer);
};
#endif