-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_pacemaker.cpp
More file actions
50 lines (43 loc) · 1.13 KB
/
final_pacemaker.cpp
File metadata and controls
50 lines (43 loc) · 1.13 KB
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
#define MQTTCLIENT_QOS2 1
#define IAP_LOCATION 0x1FFF1FF1
#include "ESP8266Interface.h"
#include "MQTTNetwork.h"
#include "MQTTmbed.h"
#include "MQTTClient.h"
#include "mbed.h"
Serial pc(USBTX, USBRX);
Serial slave(p9, p10);
Countdown cd;
Thread receiving;
int duration;
void receivingThread() {
while(true) {
if (slave.readable() && slave.getc() == 't') {
printf("heartbeat duration: %d\r\n", 1480 - duration);
printf("reads from heart\n");
//if heart beats too fast
pc.printf("FASTER THAN 1480");
if (duration > 900) {
//publish to broker "FAST"
pc.printf("TOO FAST");
}
duration = 1480;
}
}
}
int main() {
receiving.start((callback(receivingThread)));
//MQTT BS
while (true) {
duration = 1480;
while (duration > 0) {
duration -= 1;
cd.countdown_ms(1);
while(!cd.expired());
}
pc.printf("SLOWER THAN 1480"); //force a tick
slave.printf("t");
//publish to broker "SLOW"
}
return 1;
}