-
Notifications
You must be signed in to change notification settings - Fork 0
/
BluetoothHC06.h
78 lines (66 loc) · 2.13 KB
/
BluetoothHC06.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
/*
template <typename DerivedType, typename _SerialType = HardwareSerial>
class BluetoothHC06 : public SerialActivity<BluetoothHC06<DerivedType, _SerialType>, _SerialType> {
public:
bool OK;
BluetoothHC06()
: OK(false)
{}
void OnCommand(const StringBuf& buf) {
static_cast<DerivedType*>(this)->OnCommand(buf);
}
template <typename... Types>
String BluetoothCommand(Types... args);
template <typename... Types>
String BluetoothCommand(const String& arg, Types... args) {
Port.write(arg.c_str());
return BluetoothCommand(args...);
}
template <typename... Types>
String BluetoothCommand(const StringSumHelper& arg, Types... args) {
Port.write(arg.c_str());
return BluetoothCommand(args...);
}
template <typename Type, typename... Types>
String BluetoothCommand(Type arg, Types... args) {
Port.write(arg);
return BluetoothCommand(args...);
}
String BluetoothCommand() {
delay(1000);
String Response = Port.readStringUntil('\n');
Response.trim();
return Response;
}
static unsigned long GetBaudCode(unsigned long baud) {
switch (baud) {
case 9600:
return 4;
case 38400:
return 6;
default:
return 4;
}
}
template <typename ConfigType>
void OnSetup(const ConfigType& config) {
SerialActivity<BluetoothHC06<DerivedType, _SerialType>, _SerialType>::OnSetup(config);
OK = BluetoothCommand("AT") == "OK";
if (OK) {
//OK &= BluetoothCommand(String("AT+BAUD") + GetBaudCode(config.Baud)) == "OK" + config.Baud;
OK &= BluetoothCommand(String("AT+NAME") + config.Name) == "OKsetname";
OK &= BluetoothCommand(String("AT+PIN") + config.Password) == "OKsetPIN";
}
}
void OnLoop(const ActivityContext& context) {
if (OK) {
SerialActivity<BluetoothHC06<DerivedType, _SerialType>, _SerialType>::OnLoop(context);
}
}
bool IsBluetoothConnected() const {
// TODO
return OK && true;
}
};
*/