-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSwgeBeacon.cpp
75 lines (63 loc) · 1.73 KB
/
SwgeBeacon.cpp
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
#include "pxt.h"
#include "SwgeBeaconService.h"
using namespace pxt;
/**
* A set of functions to advertise beacon with Bluetooth
*/
namespace bluetooth
{
SwgeBeaconService *pBeaconInstance = nullptr;
SwgeBeaconService *getBeaconService()
{
if (pBeaconInstance == nullptr)
{
pBeaconInstance = new SwgeBeaconService(uBit.ble);
}
return pBeaconInstance;
}
//%
void activateSwgeLocationBeaconAdvanced(uint8_t zone, uint8_t react_interval, int8_t rssi)
{
// only zones used in the park, and which the droid will react to, are values 1 - 7.
if (zone < 0 || zone > 7) {
zone = 1;
}
getBeaconService()->activateSwgeLocationBeacon(zone, react_interval, (uint8_t)(rssi & 0xFF));
}
//%
void activateSwgeLocationBeacon(uint8_t zone)
{
// most common values found throughout the park
uint8_t react_interval = 0x02;
char rssi = 0xA6;
activateSwgeLocationBeaconAdvanced(zone, react_interval, rssi);
}
//%
void activateSwgeDroidBeacon(uint8_t personality)
{
// limit value of personality to between 0 and 8
personality %= 9;
// droid is paired with a remote
uint8_t is_paired = 1;
// establish chip's affiliation, 0 = scoundrel
uint8_t affiliation = 0;
// resistance = 1
if (personality == 3 || personality == 6) {
affiliation = 1;
// first order = 2
} else if (personality == 5 || personality == 8) {
affiliation = 2;
}
getBeaconService()->activateSwgeDroidBeacon(personality, affiliation, is_paired);
}
//%
void activateGenericBeacon(String mfr_id, String beacon_data)
{
getBeaconService()->activateGenericBeacon(MSTR(mfr_id), MSTR(beacon_data));
}
//%
void activateSwgeBeacon(uint8_t zone)
{
activateSwgeLocationBeacon(zone);
}
}