USB Host Shield 2.0
XBOXONESParser.h
Go to the documentation of this file.
1
/* Copyright (C) 2020 Kristian Sloth Lauszus. All rights reserved.
2
3
This software may be distributed and modified under the terms of the GNU
4
General Public License version 2 (GPL2) as published by the Free Software
5
Foundation and appearing in the file GPL2.TXT included in the packaging of
6
this file. Please note that GPL2 Section 2[b] requires that all works based
7
on this software must also be made publicly available under the terms of
8
the GPL2 ("Copyleft").
9
10
Contact information
11
-------------------
12
13
Kristian Sloth Lauszus
14
Web : https://lauszus.com
15
e-mail : lauszus@gmail.com
16
*/
17
18
#ifndef _xboxonesparser_h_
19
#define _xboxonesparser_h_
20
21
#include "
Usb.h
"
22
#include "
controllerEnums.h
"
23
24
union
XboxOneSButtons
{
25
struct
{
26
uint8_t
dpad
: 4;
27
uint8_t
reserved
: 4;
28
29
uint8_t
a
: 1;
30
uint8_t
b
: 1;
31
uint8_t
x
: 1;
32
uint8_t
y
: 1;
33
34
uint8_t
l1
: 1;
35
uint8_t
r1
: 1;
36
uint8_t
view
: 1;
37
uint8_t
menu
: 1;
38
39
uint8_t
l3
: 1;
40
uint8_t
r3
: 1;
41
uint8_t
reserved2
: 6;
42
} __attribute__((packed));
43
uint32_t
val
: 24;
44
} __attribute__((packed));
45
46
struct
XboxOneSData
{
47
/* Button and joystick values */
48
uint16_t hatValue[4];
49
uint16_t trigger[2];
50
XboxOneSButtons
btn
;
51
} __attribute__((packed));
52
54
class
XBOXONESParser
{
55
public
:
57
XBOXONESParser
() {
58
Reset();
59
};
60
72
uint16_t getButtonPress(
ButtonEnum
b
);
73
bool
getButtonClick(
ButtonEnum
b);
81
int16_t getAnalogHat(
AnalogHatEnum
a
);
82
84
//void setRumbleOff();
85
93
//void setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor);
94
95
protected
:
101
void
Parse(uint8_t len, uint8_t *buf);
102
104
void
Reset();
105
111
//virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) = 0;
112
113
private
:
114
bool
checkDpad(
ButtonEnum
b);
// Used to check Xbox One S DPAD buttons
115
116
XboxOneSData
xboxOneSData;
117
XboxOneSButtons
oldButtonState, buttonClickState;
118
uint8_t oldDpad;
119
120
// The Xbox button is sent in a separate report
121
uint8_t xboxButtonState, xboxOldButtonState, xboxbuttonClickState;
122
123
uint16_t triggerOld[2];
124
bool
L2Clicked;
// These buttons are analog, so we use we use these bools to check if they where clicked or not
125
bool
R2Clicked;
126
};
127
#endif
XBOXONESParser
Definition:
XBOXONESParser.h:54
XboxOneSButtons::l3
uint8_t l3
Definition:
XBOXONESParser.h:39
XboxOneSButtons::x
uint8_t x
Definition:
XBOXONESParser.h:31
XboxOneSButtons::reserved2
uint8_t reserved2
Definition:
XBOXONESParser.h:41
XboxOneSButtons::dpad
uint8_t dpad
Definition:
XBOXONESParser.h:26
AnalogHatEnum
AnalogHatEnum
Definition:
controllerEnums.h:163
Usb.h
XboxOneSData::btn
XboxOneSButtons btn
Definition:
XBOXONESParser.h:50
controllerEnums.h
XboxOneSButtons::l1
uint8_t l1
Definition:
XBOXONESParser.h:34
XboxOneSButtons::b
uint8_t b
Definition:
XBOXONESParser.h:30
XBOXONESParser::XBOXONESParser
XBOXONESParser()
Definition:
XBOXONESParser.h:57
ButtonEnum
ButtonEnum
Definition:
controllerEnums.h:78
XboxOneSData
Definition:
XBOXONESParser.h:46
XboxOneSButtons::a
uint8_t a
Definition:
XBOXONESParser.h:29
XboxOneSButtons::reserved
uint8_t reserved
Definition:
XBOXONESParser.h:27
XboxOneSButtons::val
uint32_t val
Definition:
XBOXONESParser.h:43
XboxOneSButtons
Definition:
XBOXONESParser.h:24
XboxOneSButtons::r3
uint8_t r3
Definition:
XBOXONESParser.h:40
XboxOneSButtons::menu
uint8_t menu
Definition:
XBOXONESParser.h:37
XboxOneSButtons::y
uint8_t y
Definition:
XBOXONESParser.h:32
XboxOneSButtons::view
uint8_t view
Definition:
XBOXONESParser.h:36
XboxOneSButtons::r1
uint8_t r1
Definition:
XBOXONESParser.h:35
Generated by
1.8.13