-
Notifications
You must be signed in to change notification settings - Fork 1
/
bpm-eeprom-sniffer.ino
117 lines (108 loc) · 2.43 KB
/
bpm-eeprom-sniffer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <Wire.h>
#define BPM_POWER_PIN 13
byte numWritings;
String systolic;
String diastolic;
int heartRate;
void setup()
{
pinMode(BPM_POWER_PIN, OUTPUT);
Serial.begin(115200);
Wire.begin(0x50, 21, 22, 400000); // I2C fast mode
Wire.onReceive(receiveEvent);
}
void pushBpmPowerButton() // Emulate a push on power button
{
digitalWrite(BPM_POWER_PIN, HIGH);
delay(100);
digitalWrite(BPM_POWER_PIN, LOW);
}
void startBpm() // The power button must be pressed twice to begin the measurement
{
pushBpmPowerButton();
delay(200);
pushBpmPowerButton();
}
void loop()
{
startBpm();
delay(2 * 60 * 1000); // Run every 2 minutes
}
int readData()
{
Wire.read(); // Discard the memory address
return Wire.read();
}
String hexToString(int hex)
{
String str = String(hex, HEX);
if (str.length() == 1)
{
return '0' + str;
}
return str;
}
void receiveEvent(int numBytes)
{
if (numBytes == 2) // Receiving a writing
{
switch (++numWritings)
{
case 1:
{
int memAddress = Wire.read();
if (memAddress == 0xF) // Measurement error
{
Serial.println("Erro na medição");
numWritings = 0;
}
break;
}
case 6:
{
int data = readData();
switch (data)
{
case 0x10:
sys = "1";
dia = "";
break;
case 0x11:
sys = "1";
dia = "1";
break;
case 0x01:
sys = "";
dia = "1";
break;
case 0x00:
sys = "";
dia = "";
break;
}
break;
}
case 7:
{
int data = readData();
systolic += hexToString(data);
break;
}
case 8:
{
int data = readData();
diastolic += hexToString(data);
break;
}
case 9:
heartRate = readData();
break;
case 10:
Serial.printf("Pressão sistólca: %s mmHg\n", systolic);
Serial.printf("Pressão diastólica: %s mmHg\n", diastolic);
Serial.printf("Frequência cardíaca: %d bpm\n", heartRate);
numWritings = 0;
break;
}
}
}