-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBikeBLEServer.ino
74 lines (58 loc) · 1.5 KB
/
BikeBLEServer.ino
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
#include "config.h"
#include "CadenceServer.h"
#include "PowerServer.h"
#include "NetworkService.h"
#include "BikeBridge.h"
bool _BLEClientConnected = false;
class MyServerCallbacks : public BLEServerCallbacks
{
void onConnect(BLEServer *pServer)
{
_BLEClientConnected = true;
};
void onDisconnect(BLEServer *pServer)
{
_BLEClientConnected = false;
}
};
//CadenceServer cadenceServer;
PowerServer powerServer;
NetworkService networkService;
BikeBridge bike;
void initBLE()
{
// Create BLE Device
BLEDevice::init("BodyWorx ABX450AT");
// Create BLE Server
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
//cadenceServer.init(pServer);
powerServer.init(pServer);
// Start Advertising
pServer->getAdvertising()->start();
}
void setup()
{
Serial.begin(115200);
Serial.println("Start");
networkService.setup();
bike.setup(&networkService);
initBLE();
}
ulong lastCrankEventTime = 0;
short lastPower = 0;
void loop()
{
networkService.loop();
bike.loop();
if ( lastCrankEventTime != bike.getLastCrankEventTime()
|| lastPower != bike.getPower() )
{
lastCrankEventTime = bike.getLastCrankEventTime();
lastPower = bike.getPower();
int crankCount = bike.getCrankCount();
//cadenceServer.Update(wheelRevCount, lastRevTime);
powerServer.update(lastPower, crankCount, lastCrankEventTime);
networkService.publish("cycle/bleupdate", "%d,%d,%d", lastPower, crankCount, lastCrankEventTime);
}
}