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) {
38
SwitchProParser::Reset
();
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
() {
66
SwitchProParser::Reset
();
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
() {
77
SwitchProParser::Reset
();
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
SwitchProBT::connected
bool connected()
Definition:
SwitchProBT.h:45
SwitchProParser
Definition:
SwitchProParser.h:141
BTD::L2CAP_Command
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
Definition:
BTD.cpp:1447
BTHID.h
SwitchProParser::Parse
void Parse(uint8_t len, uint8_t *buf)
Definition:
SwitchProParser.cpp:55
LED1
@ LED1
Definition:
controllerEnums.h:34
SwitchProParser.h
SwitchProParser::Reset
void Reset()
Definition:
SwitchProParser.cpp:231
SwitchProBT::SwitchProBT
SwitchProBT(BTD *p, bool pair=false, const char *pin="0000")
Definition:
SwitchProBT.h:36
BTD
Definition:
BTD.h:221
BTHID::pair
void pair(void)
Definition:
BTHID.h:91
SwitchProParser::setLedOn
void setLedOn(LEDEnum a)
Definition:
SwitchProParser.h:289
BluetoothService::pBtd
BTD * pBtd
Definition:
BTD.h:646
SwitchProBT::OnInitBTHID
virtual void OnInitBTHID()
Definition:
SwitchProBT.h:65
SwitchProParser::setLedHomeOn
void setLedHomeOn()
Definition:
SwitchProParser.h:310
SwitchProBT::ResetBTHID
virtual void ResetBTHID()
Definition:
SwitchProBT.h:76
BTHID::connected
bool connected
Definition:
BTHID.h:88
BTHID::interrupt_scid
uint8_t interrupt_scid[2]
Definition:
BTHID.h:158
BluetoothService::pFuncOnInit
void(* pFuncOnInit)(void)
Definition:
BTD.h:643
BluetoothService::hci_handle
uint16_t hci_handle
Definition:
BTD.h:649
BTHID
Definition:
BTHID.h:29
SwitchProBT::ParseBTHIDData
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
Definition:
SwitchProBT.h:56
SwitchProBT::sendOutputReport
virtual void sendOutputReport(uint8_t *data, uint8_t len)
Definition:
SwitchProBT.h:82
SwitchProBT
Definition:
SwitchProBT.h:28
Generated by
1.8.17