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  };
68 
70  virtual void ResetBTHID() {
72  };
76  virtual void sendOutputReport(uint8_t *data, uint8_t nbytes) {
77  // See: https://lore.kernel.org/patchwork/patch/973394/
78  uint8_t buf[nbytes + 2];
79  buf[0] = 0xA2; // HID BT DATA (0xA0) | Report Type (Output 0x02)
80  buf[1] = 0x03; // Report ID
81  memcpy(buf + 2, data, nbytes);
82 
83  // Send the Bluetooth DATA output report on the interrupt channel
84  pBtd->L2CAP_Command(hci_handle, buf, sizeof(buf), interrupt_scid[0], interrupt_scid[1]);
85  };
87 };
88 #endif
Definition: BTD.h:222
bool useSimplePairing
Definition: BTD.h:532
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition: BTD.cpp:1452
Definition: BTHID.h:29
uint8_t interrupt_scid[2]
Definition: BTHID.h:158
bool connected
Definition: BTHID.h:88
void pair(void)
Definition: BTHID.h:91
uint16_t hci_handle
Definition: BTD.h:650
BTD * pBtd
Definition: BTD.h:647
bool connected()
Definition: XBOXONESBT.h:45
virtual void sendOutputReport(uint8_t *data, uint8_t nbytes)
Definition: XBOXONESBT.h:76
XBOXONESBT(BTD *p, bool pair=false)
Definition: XBOXONESBT.h:35
virtual void OnInitBTHID()
Definition: XBOXONESBT.h:65
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
Definition: XBOXONESBT.h:56
virtual void ResetBTHID()
Definition: XBOXONESBT.h:70
void Parse(uint8_t len, uint8_t *buf)