-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBluetooth.h
62 lines (51 loc) · 1.67 KB
/
Bluetooth.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
#pragma once
#include "BluetoothHC05.h"
#include "BluetoothHC06.h"
#include "BluetoothZS040.h"
namespace AW {
template <typename BluetoothType>
class TBluetoothActor : public TActor {
public:
TBluetoothActor(TActor* owner, TActor* serial)
: Owner(owner)
, Serial(serial)
, Bluetooth(this, Serial)
{}
bool IsOK() const {
return Bluetooth.IsOK();
}
bool IsConnected() const {
return Bluetooth.IsConnected();
}
protected:
TActor* Owner;
TActor* Serial;
BluetoothType Bluetooth;
void OnEvent(TEventPtr event, const TActorContext& context) override {
switch (event->EventID) {
case TEventBootstrap::EventID:
return OnBootstrap(static_cast<TEventBootstrap*>(event.Release()), context);
case TEventSerialData::EventID:
return OnSerialData(static_cast<TEventSerialData*>(event.Release()), context);
case TEventReceive::EventID:
return OnReceive(static_cast<TEventReceive*>(event.Release()), context);
}
}
void OnBootstrap(TUniquePtr<TEventBootstrap>, const TActorContext& context) {
Bluetooth.Init(context);
}
void OnSerialData(TUniquePtr<TEventSerialData> event, const TActorContext& context) {
//::Serial.println("== ");
if (event->Sender == Serial) {
if (!Bluetooth.Receive(event, context)) {
context.Send(this, Owner, event.Release());
}
} else {
context.Send(this, Serial, event.Release());
}
}
void OnReceive(TUniquePtr<TEventReceive> event, const TActorContext& context) {
Bluetooth.Receive(event, context);
}
};
}