-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DS3Report.h
97 lines (89 loc) · 2.91 KB
/
DS3Report.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
88
89
90
91
92
93
94
95
96
97
#ifndef _DS3_REPORT_
#define _DS3_REPORT_
#include <stdint.h>
#define DS3_BUTTON_SELECT_MASK (1U << 0)
#define DS3_BUTTON_L3_MASK (1U << 1)
#define DS3_BUTTON_R3_MASK (1U << 2)
#define DS3_BUTTON_START_MASK (1U << 3)
#define DS3_DPAD_UP_MASK (1U << 4)
#define DS3_DPAD_RIGHT_MASK (1U << 5)
#define DS3_DPAD_DOWN_MASK (1U << 6)
#define DS3_DPAD_LEFT_MASK (1U << 7)
#define DS3_BUTTON_L2_MASK (1U << 8)
#define DS3_BUTTON_R1_MASK (1U << 9)
#define DS3_BUTTON_L1_MASK (1U << 10)
#define DS3_BUTTON_R2_MASK (1U << 11)
#define DS3_BUTTON_TRIANGLE_MASK (1U << 12)
#define DS3_BUTTON_CIRCLE_MASK (1U << 13)
#define DS3_BUTTON_CROSS_MASK (1U << 14)
#define DS3_BUTTON_SQUARE_MASK (1U << 15)
#define DS3_BUTTON_PS_MASK (1U << 16)
typedef struct {
uint8_t reportId;
byte reserved1;
uint32_t buttons;
uint8_t lx;
uint8_t ly;
uint8_t rx;
uint8_t ry;
byte reserved2[3];
uint8_t analogDpadUp;
uint8_t analogDpadRight;
uint8_t analogDpadDown;
uint8_t analogDpadLeft;
uint8_t analogL2;
uint8_t analogR2;
uint8_t analogL1;
uint8_t analogR1;
uint8_t analogTriangle;
uint8_t analogCircle;
uint8_t analogCross;
uint8_t analogSquare;
byte reserved3[4];
uint8_t batteryStatus;
byte reserved4[10];
uint16_t accelX; // 10 bit
uint16_t accellY; // 10 bit
uint16_t accelZ; // 10 bit
uint16_t gyro; // 10 bit
} DS3Report; // 48 bytes
// uint8_t dpadToHatDInput(uint8_t dpad) {
// switch (dpad & (DS3_DPAD_UP_MASK | DS3_DPAD_DOWN_MASK | DS3_DPAD_LEFT_MASK | DS3_DPAD_RIGHT_MASK)) {
// case DS3_DPAD_UP_MASK: return 0;
// case DS3_DPAD_UP_MASK | DS3_DPAD_RIGHT_MASK: return 1;
// case DS3_DPAD_RIGHT_MASK: return 2;
// case DS3_DPAD_DOWN_MASK | DS3_DPAD_RIGHT_MASK: return 3;
// case DS3_DPAD_DOWN_MASK: return 4;
// case DS3_DPAD_DOWN_MASK | DS3_DPAD_LEFT_MASK: return 5;
// case DS3_DPAD_LEFT_MASK: return 6;
// case DS3_DPAD_UP_MASK | DS3_DPAD_LEFT_MASK: return 7;
// }
// return 15;
// }
// #ifdef PS3
// Gamepad._GamepadReport.hat = dpad2hat(axes);
// #else
// // UP + DOWN = UP, SOCD (Simultaneous Opposite Cardinal Directions) Cleaner
// if(axes & B10000000)
// Gamepad._GamepadReport.Y = -1;
// else if(axes & B01000000)
// Gamepad._GamepadReport.Y = 1;
// else
// Gamepad._GamepadReport.Y = 0;
// // UP + DOWN = NEUTRAL
// //Gamepad._GamepadReport.Y = ((axes & B01000000)>>6) - ((axes & B10000000)>>7);
// // LEFT + RIGHT = NEUTRAL
// Gamepad._GamepadReport.X = ((axes & B00010000)>>4) - ((axes & B00100000)>>5);
// #endif
// #ifdef PS3
// Gamepad._GamepadReport.buttons = buttons & 0x3FF;
// if(buttons & 0x400) // B11
// Gamepad._GamepadReport.Z = -1;
// else if(buttons & 0x800) // B12
// Gamepad._GamepadReport.Z = 1;
// else
// Gamepad._GamepadReport.Z = 0;
// #else
// Gamepad._GamepadReport.buttons = buttons;
// #endif
#endif