USB Host Shield 2.0
SwitchProBT.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 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 _switch_pro_bt_h_
19 #define _switch_pro_bt_h_
20 
21 #include "BTHID.h"
22 #include "SwitchProParser.h"
23 
28 class SwitchProBT : public BTHID, public SwitchProParser {
29 public:
36  SwitchProBT(BTD *p, bool pair = false, const char *pin = "0000") :
37  BTHID(p, pair, pin) {
39  };
40 
45  bool connected() {
46  return BTHID::connected;
47  };
48 
49 protected:
56  virtual void ParseBTHIDData(uint8_t len, uint8_t *buf) {
57  SwitchProParser::Parse(len, buf);
58  };
59 
65  virtual void OnInitBTHID() {
67 
68  // Only call this is a user function has not been set
69  if (!pFuncOnInit) {
70  setLedOn(LED1); // Turn on the LED1
71  setLedHomeOn(); // Turn on the home LED
72  }
73  };
74 
76  virtual void ResetBTHID() {
78  };
82  virtual void sendOutputReport(uint8_t *data, uint8_t len) {
83  uint8_t buf[1 /* BT DATA Output Report */ + len];
84 
85  // Send as a Bluetooth HID DATA output report on the interrupt channel
86  buf[0] = 0xA2; // HID BT DATA (0xA0) | Report Type (Output 0x02)
87  memcpy(&buf[1], data, len);
88 
89  // Send the Bluetooth DATA output report on the interrupt channel
90  pBtd->L2CAP_Command(hci_handle, buf, sizeof(buf), interrupt_scid[0], interrupt_scid[1]);
91  };
93 };
94 #endif
Definition: BTD.h:222
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
void(* pFuncOnInit)(void)
Definition: BTD.h:644
uint16_t hci_handle
Definition: BTD.h:650
BTD * pBtd
Definition: BTD.h:647
virtual void ResetBTHID()
Definition: SwitchProBT.h:76
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
Definition: SwitchProBT.h:56
bool connected()
Definition: SwitchProBT.h:45
virtual void sendOutputReport(uint8_t *data, uint8_t len)
Definition: SwitchProBT.h:82
SwitchProBT(BTD *p, bool pair=false, const char *pin="0000")
Definition: SwitchProBT.h:36
virtual void OnInitBTHID()
Definition: SwitchProBT.h:65
void setLedOn(LEDEnum a)
void Parse(uint8_t len, uint8_t *buf)
@ LED1