diff --git a/_x_b_o_x_o_n_e_s_b_t_8h_source.html b/_x_b_o_x_o_n_e_s_b_t_8h_source.html index e09374cd..d5152247 100644 --- a/_x_b_o_x_o_n_e_s_b_t_8h_source.html +++ b/_x_b_o_x_o_n_e_s_b_t_8h_source.html @@ -63,22 +63,21 @@ $(function() {
XBOXONESBT.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 _xboxonesbt_h_
19 #define _xboxonesbt_h_
20 
21 #include "BTHID.h"
22 #include "XBOXONESParser.h"
23 
28 class XBOXONESBT : public BTHID, public XBOXONESParser {
29 public:
35  XBOXONESBT(BTD *p, bool pair = false) :
36  BTHID(p, pair) {
38  pBtd->useSimplePairing = true; // The Xbox One S controller only works via simple pairing
39  };
40 
45  bool connected() {
46  return BTHID::connected;
47  };
48 
49 protected:
56  virtual void ParseBTHIDData(uint8_t len, uint8_t *buf) {
57  XBOXONESParser::Parse(len, buf);
58  };
59 
65  virtual void OnInitBTHID() {
67  if (pFuncOnInit)
68  pFuncOnInit(); // Call the user function
69  };
70 
72  virtual void ResetBTHID() {
74  };
77 #if 0
78 
79  virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) {
80  // See: https://lore.kernel.org/patchwork/patch/973394/
81  uint8_t buf[nbytes + 2];
82 
83  buf[0] = 0x52; // HID BT Set_report (0x50) | Report Type (Output 0x02)
84  buf[1] = 0x03; // Report ID
85 
86  memcpy(buf + 2, data, nbytes);
87 
88  Notify(PSTR("\r\n"), 0x80);
89  for (uint8_t i = 0; i < sizeof(buf); i++) {
90  D_PrintHex<uint8_t > (buf[i], 0x80);
91  Notify(PSTR(" "), 0x80);
92  }
93  Notify(PSTR("\r\n"), 0x80);
94 
95  //pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]);
96  pBtd->L2CAP_Command(hci_handle, buf, sizeof(buf), control_scid[0], control_scid[1]);
97  };
99 #endif
100 };
101 #endif
bool useSimplePairing
Definition: BTD.h:531
+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 _xboxonesbt_h_
19 #define _xboxonesbt_h_
20 
21 #include "BTHID.h"
22 #include "XBOXONESParser.h"
23 
28 class XBOXONESBT : public BTHID, public XBOXONESParser {
29 public:
35  XBOXONESBT(BTD *p, bool pair = false) :
36  BTHID(p, pair) {
38  pBtd->useSimplePairing = true; // The Xbox One S controller only works via simple pairing
39  };
40 
45  bool connected() {
46  return BTHID::connected;
47  };
48 
49 protected:
56  virtual void ParseBTHIDData(uint8_t len, uint8_t *buf) {
57  XBOXONESParser::Parse(len, buf);
58  };
59 
65  virtual void OnInitBTHID() {
67  if (pFuncOnInit)
68  pFuncOnInit(); // Call the user function
69  };
70 
72  virtual void ResetBTHID() {
74  };
78  virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) {
79  // See: https://lore.kernel.org/patchwork/patch/973394/
80  uint8_t buf[nbytes + 2];
81  buf[0] = 0xA2; // HID BT DATA (0xA0) | Report Type (Output 0x02)
82  buf[1] = 0x03; // Report ID
83  memcpy(buf + 2, data, nbytes);
84 
85  // Send the Bluetooth DATA output report on the interrupt channel
86  pBtd->L2CAP_Command(hci_handle, buf, sizeof(buf), interrupt_scid[0], interrupt_scid[1]);
87  };
89 };
90 #endif
bool useSimplePairing
Definition: BTD.h:531
Definition: BTD.h:221
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
Definition: XBOXONESBT.h:56
+
uint8_t interrupt_scid[2]
Definition: BTHID.h:149
bool connected
Definition: BTHID.h:88
+
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes)
Definition: XBOXONESBT.h:78
virtual void ResetBTHID()
Definition: XBOXONESBT.h:72
-
uint8_t control_scid[2]
Definition: BTHID.h:146
-
#define Notify(...)
Definition: message.h:51
void Parse(uint8_t len, uint8_t *buf)
XBOXONESBT(BTD *p, bool pair=false)
Definition: XBOXONESBT.h:35
void(* pFuncOnInit)(void)
Definition: BTD.h:643
-
#define PSTR(str)
BTD * pBtd
Definition: BTD.h:646
bool connected()
Definition: XBOXONESBT.h:45
uint16_t hci_handle
Definition: BTD.h:649
diff --git a/_x_b_o_x_o_n_e_s_parser_8cpp_source.html b/_x_b_o_x_o_n_e_s_parser_8cpp_source.html index 3dc2ef51..5de2cd9d 100644 --- a/_x_b_o_x_o_n_e_s_parser_8cpp_source.html +++ b/_x_b_o_x_o_n_e_s_parser_8cpp_source.html @@ -63,7 +63,7 @@ $(function() {
XBOXONESParser.cpp
-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 #include "XBOXONESParser.h"
19 
20 // To enable serial debugging see "settings.h"
21 //#define PRINTREPORT // Uncomment to print the report send by the Xbox One S Controller
22 
24 const uint8_t XBOX_ONE_S_BUTTONS[] PROGMEM = {
25  UP, // UP
26  RIGHT, // RIGHT
27  DOWN, // DOWN
28  LEFT, // LEFT
29 
30  0x0E, // VIEW
31  0x0F, // MENU
32  0x10, // L3
33  0x11, // R3
34 
35  0, 0, // Skip L2 and R2 as these are analog buttons
36  0x0C, // L1
37  0x0D, // R1
38 
39  0x09, // B
40  0x08, // A
41  0x0A, // X
42  0x0B, // Y
43 };
44 
45 enum DPADEnum {
46  DPAD_OFF = 0x0,
47  DPAD_UP = 0x1,
49  DPAD_RIGHT = 0x3,
51  DPAD_DOWN = 0x5,
53  DPAD_LEFT = 0x7,
54  DPAD_LEFT_UP = 0x8,
55 };
56 
57 bool XBOXONESParser::checkDpad(ButtonEnum b) {
58  switch (b) {
59  case UP:
60  return xboxOneSData.btn.dpad == DPAD_LEFT_UP || xboxOneSData.btn.dpad == DPAD_UP || xboxOneSData.btn.dpad == DPAD_UP_RIGHT;
61  case RIGHT:
62  return xboxOneSData.btn.dpad == DPAD_UP_RIGHT || xboxOneSData.btn.dpad == DPAD_RIGHT || xboxOneSData.btn.dpad == DPAD_RIGHT_DOWN;
63  case DOWN:
64  return xboxOneSData.btn.dpad == DPAD_RIGHT_DOWN || xboxOneSData.btn.dpad == DPAD_DOWN || xboxOneSData.btn.dpad == DPAD_DOWN_LEFT;
65  case LEFT:
66  return xboxOneSData.btn.dpad == DPAD_DOWN_LEFT || xboxOneSData.btn.dpad == DPAD_LEFT || xboxOneSData.btn.dpad == DPAD_LEFT_UP;
67  default:
68  return false;
69  }
70 }
71 
73  if (b == L2)
74  return xboxOneSData.trigger[0];
75  else if (b == R2)
76  return xboxOneSData.trigger[1];
77  else if (b <= LEFT) // Dpad
78  return checkDpad(b);
79  else if (b == XBOX)
80  return xboxButtonState;
81  return xboxOneSData.btn.val & (1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[(uint8_t)b]));
82 }
83 
85  if(b == L2) {
86  if(L2Clicked) {
87  L2Clicked = false;
88  return true;
89  }
90  return false;
91  } else if(b == R2) {
92  if(R2Clicked) {
93  R2Clicked = false;
94  return true;
95  }
96  return false;
97  } else if (b == XBOX) {
98  bool click = xboxbuttonClickState;
99  xboxbuttonClickState = 0; // Clear "click" event
100  return click;
101  }
102  uint32_t mask = 1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[(uint8_t)b]);
103  bool click = buttonClickState.val & mask;
104  buttonClickState.val &= ~mask; // Clear "click" event
105  return click;
106 }
107 
109  return xboxOneSData.hatValue[(uint8_t)a] - 32768; // Convert to signed integer
110 }
111 
112 void XBOXONESParser::Parse(uint8_t len, uint8_t *buf) {
113  if (len > 1 && buf) {
114 #ifdef PRINTREPORT
115  Notify(PSTR("\r\n"), 0x80);
116  for (uint8_t i = 0; i < len; i++) {
117  D_PrintHex<uint8_t > (buf[i], 0x80);
118  Notify(PSTR(" "), 0x80);
119  }
120 #endif
121 
122  if (buf[0] == 0x01) // Check report ID
123  memcpy(&xboxOneSData, buf + 1, min((uint8_t)(len - 1), MFK_CASTUINT8T sizeof(xboxOneSData)));
124  else if (buf[0] == 0x02) { // This report contains the Xbox button
125  xboxButtonState = buf[1];
126  if(xboxButtonState != xboxOldButtonState) {
127  xboxbuttonClickState = xboxButtonState & ~xboxOldButtonState; // Update click state variable
128  xboxOldButtonState = xboxButtonState;
129  }
130  return;
131  } else if (buf[0] == 0x04) // Heartbeat
132  return;
133  else {
134 #ifdef DEBUG_USB_HOST
135  Notify(PSTR("\r\nUnknown report id: "), 0x80);
136  D_PrintHex<uint8_t > (buf[0], 0x80);
137 #endif
138  return;
139  }
140 
141  if (xboxOneSData.btn.val != oldButtonState.val) { // Check if anything has changed
142  buttonClickState.val = xboxOneSData.btn.val & ~oldButtonState.val; // Update click state variable
143  oldButtonState.val = xboxOneSData.btn.val;
144 
145  // The DPAD buttons does not set the different bits, but set a value corresponding to the buttons pressed, we will simply set the bits ourself
146  uint8_t newDpad = 0;
147  if (checkDpad(UP))
148  newDpad |= 1 << UP;
149  if (checkDpad(RIGHT))
150  newDpad |= 1 << RIGHT;
151  if (checkDpad(DOWN))
152  newDpad |= 1 << DOWN;
153  if (checkDpad(LEFT))
154  newDpad |= 1 << LEFT;
155  if (newDpad != oldDpad) {
156  buttonClickState.dpad = newDpad & ~oldDpad; // Override values
157  oldDpad = newDpad;
158  }
159  }
160 
161  // Handle click detection for triggers
162  if(xboxOneSData.trigger[0] != 0 && triggerOld[0] == 0)
163  L2Clicked = true;
164  triggerOld[0] = xboxOneSData.trigger[0];
165  if(xboxOneSData.trigger[1] != 0 && triggerOld[1] == 0)
166  R2Clicked = true;
167  triggerOld[1] = xboxOneSData.trigger[1];
168  }
169 }
170 
172  uint8_t i;
173  for (i = 0; i < sizeof(xboxOneSData.hatValue) / sizeof(xboxOneSData.hatValue[0]); i++)
174  xboxOneSData.hatValue[i] = 32768; // Center value
175  xboxOneSData.btn.val = 0;
176  oldButtonState.val = 0;
177  for (i = 0; i < sizeof(xboxOneSData.trigger) / sizeof(xboxOneSData.trigger[0]); i++)
178  xboxOneSData.trigger[i] = 0;
179 
180  xboxOneSData.btn.dpad = DPAD_OFF;
181  oldButtonState.dpad = DPAD_OFF;
182  buttonClickState.dpad = 0;
183  oldDpad = 0;
184 };
185 
186 #if 0
187 void XBOXONESParser::setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor) {
188  // See: https://lore.kernel.org/patchwork/patch/973394/
189  uint8_t buf[8];
190  buf[0] = 0x0F;//1 << 1 | 1 << 0; // Enable weak and strong feedback
191  buf[1] = leftTrigger;
192  buf[2] = rightTrigger;
193  buf[3] = leftMotor;
194  buf[4] = rightMotor;
195  buf[5] = 255; // Duration of effect in 10 ms
196  buf[6] = 0; // Start delay in 10 ms
197  buf[7] = 255; // Loop count
198  sendOutputReport(buf, sizeof(buf));
199 }
200 #endif
+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 #include "XBOXONESParser.h"
19 
20 // To enable serial debugging see "settings.h"
21 //#define PRINTREPORT // Uncomment to print the report send by the Xbox One S Controller
22 
24 const uint8_t XBOX_ONE_S_BUTTONS[] PROGMEM = {
25  UP, // UP
26  RIGHT, // RIGHT
27  DOWN, // DOWN
28  LEFT, // LEFT
29 
30  0x0E, // VIEW
31  0x0F, // MENU
32  0x10, // L3
33  0x11, // R3
34 
35  0, 0, // Skip L2 and R2 as these are analog buttons
36  0x0C, // L1
37  0x0D, // R1
38 
39  0x09, // B
40  0x08, // A
41  0x0A, // X
42  0x0B, // Y
43 };
44 
45 enum DPADEnum {
46  DPAD_OFF = 0x0,
47  DPAD_UP = 0x1,
49  DPAD_RIGHT = 0x3,
51  DPAD_DOWN = 0x5,
53  DPAD_LEFT = 0x7,
54  DPAD_LEFT_UP = 0x8,
55 };
56 
57 bool XBOXONESParser::checkDpad(ButtonEnum b) {
58  switch (b) {
59  case UP:
60  return xboxOneSData.btn.dpad == DPAD_LEFT_UP || xboxOneSData.btn.dpad == DPAD_UP || xboxOneSData.btn.dpad == DPAD_UP_RIGHT;
61  case RIGHT:
62  return xboxOneSData.btn.dpad == DPAD_UP_RIGHT || xboxOneSData.btn.dpad == DPAD_RIGHT || xboxOneSData.btn.dpad == DPAD_RIGHT_DOWN;
63  case DOWN:
64  return xboxOneSData.btn.dpad == DPAD_RIGHT_DOWN || xboxOneSData.btn.dpad == DPAD_DOWN || xboxOneSData.btn.dpad == DPAD_DOWN_LEFT;
65  case LEFT:
66  return xboxOneSData.btn.dpad == DPAD_DOWN_LEFT || xboxOneSData.btn.dpad == DPAD_LEFT || xboxOneSData.btn.dpad == DPAD_LEFT_UP;
67  default:
68  return false;
69  }
70 }
71 
73  if (b == L2)
74  return xboxOneSData.trigger[0];
75  else if (b == R2)
76  return xboxOneSData.trigger[1];
77  else if (b <= LEFT) // Dpad
78  return checkDpad(b);
79  else if (b == XBOX)
80  return xboxButtonState;
81  return xboxOneSData.btn.val & (1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[(uint8_t)b]));
82 }
83 
85  if(b == L2) {
86  if(L2Clicked) {
87  L2Clicked = false;
88  return true;
89  }
90  return false;
91  } else if(b == R2) {
92  if(R2Clicked) {
93  R2Clicked = false;
94  return true;
95  }
96  return false;
97  } else if (b == XBOX) {
98  bool click = xboxbuttonClickState;
99  xboxbuttonClickState = 0; // Clear "click" event
100  return click;
101  }
102  uint32_t mask = 1UL << pgm_read_byte(&XBOX_ONE_S_BUTTONS[(uint8_t)b]);
103  bool click = buttonClickState.val & mask;
104  buttonClickState.val &= ~mask; // Clear "click" event
105  return click;
106 }
107 
109  return xboxOneSData.hatValue[(uint8_t)a] - 32768; // Convert to signed integer
110 }
111 
112 void XBOXONESParser::Parse(uint8_t len, uint8_t *buf) {
113  if (len > 1 && buf) {
114 #ifdef PRINTREPORT
115  Notify(PSTR("\r\n"), 0x80);
116  for (uint8_t i = 0; i < len; i++) {
117  D_PrintHex<uint8_t > (buf[i], 0x80);
118  Notify(PSTR(" "), 0x80);
119  }
120 #endif
121 
122  if (buf[0] == 0x01) // Check report ID
123  memcpy(&xboxOneSData, buf + 1, min((uint8_t)(len - 1), MFK_CASTUINT8T sizeof(xboxOneSData)));
124  else if (buf[0] == 0x02) { // This report contains the Xbox button
125  xboxButtonState = buf[1];
126  if(xboxButtonState != xboxOldButtonState) {
127  xboxbuttonClickState = xboxButtonState & ~xboxOldButtonState; // Update click state variable
128  xboxOldButtonState = xboxButtonState;
129  }
130  return;
131  } else if (buf[0] == 0x04) // Heartbeat
132  return;
133  else {
134 #ifdef DEBUG_USB_HOST
135  Notify(PSTR("\r\nUnknown report id: "), 0x80);
136  D_PrintHex<uint8_t > (buf[0], 0x80);
137 #endif
138  return;
139  }
140 
141  if (xboxOneSData.btn.val != oldButtonState.val) { // Check if anything has changed
142  buttonClickState.val = xboxOneSData.btn.val & ~oldButtonState.val; // Update click state variable
143  oldButtonState.val = xboxOneSData.btn.val;
144 
145  // The DPAD buttons does not set the different bits, but set a value corresponding to the buttons pressed, we will simply set the bits ourself
146  uint8_t newDpad = 0;
147  if (checkDpad(UP))
148  newDpad |= 1 << UP;
149  if (checkDpad(RIGHT))
150  newDpad |= 1 << RIGHT;
151  if (checkDpad(DOWN))
152  newDpad |= 1 << DOWN;
153  if (checkDpad(LEFT))
154  newDpad |= 1 << LEFT;
155  if (newDpad != oldDpad) {
156  buttonClickState.dpad = newDpad & ~oldDpad; // Override values
157  oldDpad = newDpad;
158  }
159  }
160 
161  // Handle click detection for triggers
162  if(xboxOneSData.trigger[0] != 0 && triggerOld[0] == 0)
163  L2Clicked = true;
164  triggerOld[0] = xboxOneSData.trigger[0];
165  if(xboxOneSData.trigger[1] != 0 && triggerOld[1] == 0)
166  R2Clicked = true;
167  triggerOld[1] = xboxOneSData.trigger[1];
168  }
169 }
170 
172  uint8_t i;
173  for (i = 0; i < sizeof(xboxOneSData.hatValue) / sizeof(xboxOneSData.hatValue[0]); i++)
174  xboxOneSData.hatValue[i] = 32768; // Center value
175  xboxOneSData.btn.val = 0;
176  oldButtonState.val = 0;
177  for (i = 0; i < sizeof(xboxOneSData.trigger) / sizeof(xboxOneSData.trigger[0]); i++)
178  xboxOneSData.trigger[i] = 0;
179 
180  xboxOneSData.btn.dpad = DPAD_OFF;
181  oldButtonState.dpad = DPAD_OFF;
182  buttonClickState.dpad = 0;
183  oldDpad = 0;
184 };
185 
187  // See: https://lore.kernel.org/patchwork/patch/973394/
188  uint8_t buf[8];
189  buf[0] = 0x0F; // Disable all rumble motors
190  buf[1] = 0;
191  buf[2] = 0;
192  buf[3] = 0;
193  buf[4] = 0;
194  buf[5] = 0; // Duration of effect in 10 ms
195  buf[6] = 0; // Start delay in 10 ms
196  buf[7] = 0; // Loop count
197  sendOutputReport(buf, sizeof(buf));
198 }
199 
200 void XBOXONESParser::setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor) {
201  // See: https://lore.kernel.org/patchwork/patch/973394/
202  uint8_t buf[8];
203  buf[0] = 1 << 3 /* Left trigger */ | 1 << 2 /* Right trigger */ | 1 << 1 /* Left motor */ | 1 << 0 /* Right motor */;
204  buf[1] = leftTrigger;
205  buf[2] = rightTrigger;
206  buf[3] = leftMotor;
207  buf[4] = rightMotor;
208  buf[5] = 255; // Duration of effect in 10 ms
209  buf[6] = 0; // Start delay in 10 ms
210  buf[7] = 255; // Loop count
211  sendOutputReport(buf, sizeof(buf));
212 }
bool getButtonClick(ButtonEnum b)
@@ -72,13 +72,16 @@ $(function() {
int16_t getAnalogHat(AnalogHatEnum a)
#define pgm_read_byte(addr)
+
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes)=0
+
void setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor)
uint16_t getButtonPress(ButtonEnum b)
XboxOneSButtons btn
#define Notify(...)
Definition: message.h:51
+
uint16_t trigger[2]
void Parse(uint8_t len, uint8_t *buf)
diff --git a/_x_b_o_x_o_n_e_s_parser_8h_source.html b/_x_b_o_x_o_n_e_s_parser_8h_source.html index af89b6b8..c1273626 100644 --- a/_x_b_o_x_o_n_e_s_parser_8h_source.html +++ b/_x_b_o_x_o_n_e_s_parser_8h_source.html @@ -63,7 +63,7 @@ $(function() {
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 
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];
51 } __attribute__((packed));
52 
55 public:
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
+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 
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];
51 } __attribute__((packed));
52 
55 public:
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
diff --git a/class_x_b_o_x_o_n_e_s_b_t-members.html b/class_x_b_o_x_o_n_e_s_b_t-members.html index 76dd01ef..82bf70a4 100644 --- a/class_x_b_o_x_o_n_e_s_b_t-members.html +++ b/class_x_b_o_x_o_n_e_s_b_t-members.html @@ -97,12 +97,15 @@ $(function() { ResetBTHID()XBOXONESBTinlineprotectedvirtual Run()BTHIDprotectedvirtual sdp_scidBTHIDprotected - setLeds(struct KBDLEDS data)BTHIDinline - setLeds(uint8_t data)BTHID - setProtocolMode(uint8_t mode)BTHIDinline - SetReportParser(uint8_t id, HIDReportParser *prs)BTHIDinline - XBOXONESBT(BTD *p, bool pair=false)XBOXONESBTinline - XBOXONESParser()XBOXONESParserinline + sendOutputReport(uint8_t *data, uint8_t nbytes)XBOXONESBTinlineprotectedvirtual + setLeds(struct KBDLEDS data)BTHIDinline + setLeds(uint8_t data)BTHID + setProtocolMode(uint8_t mode)BTHIDinline + SetReportParser(uint8_t id, HIDReportParser *prs)BTHIDinline + setRumbleOff()XBOXONESParser + setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor)XBOXONESParser + XBOXONESBT(BTD *p, bool pair=false)XBOXONESBTinline + XBOXONESParser()XBOXONESParserinline
+
+ +

◆ sendOutputReport()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
virtual void XBOXONESBT::sendOutputReport (uint8_t * data,
uint8_t nbytes 
)
+
+inlineprotectedvirtual
+
+

Send the output to the Xbox One S controller. This is implemented in XBOXONESBT.h.

Parameters
+ + + +
outputPointer to data buffer.
nbytesBytes to send.
+
+
+ +

Implements XBOXONESParser.

+ +

Definition at line 78 of file XBOXONESBT.h.

+

The documentation for this class was generated from the following file:
-
XBOXONESParser Class Reference
+
XBOXONESParser Class Referenceabstract
@@ -84,6 +84,10 @@ Public Member Functions   int16_t getAnalogHat (AnalogHatEnum a)   +void setRumbleOff () +  +void setRumbleOn (uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor) + 
Xbox One S Controller functions
uint16_t getButtonPress (ButtonEnum b)   @@ -96,6 +100,8 @@ Protected Member Functions   void Reset ()   +virtual void sendOutputReport (uint8_t *data, uint8_t nbytes)=0 + 

Detailed Description

This class parses all the data sent by the Xbox One S controller

@@ -214,6 +220,77 @@ Protected Member Functions

Definition at line 108 of file XBOXONESParser.cpp.

+
+
+ +

◆ setRumbleOff()

+ +
+
+ + + + + + + +
void XBOXONESParser::setRumbleOff ()
+
+

Used to set the rumble off.

+ +

Definition at line 186 of file XBOXONESParser.cpp.

+ +
+
+ +

◆ setRumbleOn()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void XBOXONESParser::setRumbleOn (uint8_t leftTrigger,
uint8_t rightTrigger,
uint8_t leftMotor,
uint8_t rightMotor 
)
+
+

Used to turn on rumble continuously.

Parameters
+ + + + + +
leftTriggerLeft trigger force.
rightTriggerRight trigger force.
leftMotorLeft motor force.
rightMotorRight motor force.
+
+
+ +

Definition at line 200 of file XBOXONESParser.cpp.

+
@@ -249,12 +326,8 @@ Protected Member Functions
-

Used to set the rumble off. Used to turn on rumble continuously.

Parameters
+

Used to parse data sent from the Xbox One S controller.

Parameters
- - - -
leftTriggerLeft trigger force.
rightTriggerRight trigger force.
leftMotorLeft motor force.
rightMotorRight motor force. Used to parse data sent from the Xbox One S controller.
lenLength of the data.
bufPointer to the data buffer.
@@ -291,6 +364,51 @@ Protected Member Functions

Definition at line 171 of file XBOXONESParser.cpp.

+
+ + +

◆ sendOutputReport()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
virtual void XBOXONESParser::sendOutputReport (uint8_t * data,
uint8_t nbytes 
)
+
+protectedpure virtual
+
+

Send the output to the Xbox One S controller. This is implemented in XBOXONESBT.h.

Parameters
+ + + +
outputPointer to data buffer.
nbytesBytes to send.
+
+
+ +

Implemented in XBOXONESBT.

+

The documentation for this class was generated from the following files: