USB Host Shield 2.0
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  };
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
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
BTD * pBtd
Definition: BTD.h:646
bool connected()
Definition: XBOXONESBT.h:45
uint16_t hci_handle
Definition: BTD.h:649
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1447
Definition: BTHID.h:29
void pair(void)
Definition: BTHID.h:91
virtual void OnInitBTHID()
Definition: XBOXONESBT.h:65