Skip to content

Commit e3ead33

Browse files
authored
Merge pull request #319 from DavidVentura/use-byte-for-ppg
Use int8_t for PPG data array
2 parents 65e4fe0 + a62b81d commit e3ead33

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/components/heartrate/Ppg.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using namespace Pinetime::Controllers;
1111

1212
/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
1313
namespace {
14-
int Compare(int* d1, int* d2, size_t count) {
14+
int Compare(int8_t* d1, int8_t* d2, size_t count) {
1515
int e = 0;
1616
for (size_t i = 0; i < count; i++) {
1717
auto d = d1[i] - d2[i];
@@ -20,11 +20,11 @@ namespace {
2020
return e;
2121
}
2222

23-
int CompareShift(int* d, int shift, size_t count) {
23+
int CompareShift(int8_t* d, int shift, size_t count) {
2424
return Compare(d + shift, d, count - shift);
2525
}
2626

27-
int Trough(int* d, size_t size, float mn, float mx) {
27+
int Trough(int8_t* d, size_t size, uint8_t mn, uint8_t mx) {
2828
auto z2 = CompareShift(d, mn - 2, size);
2929
auto z1 = CompareShift(d, mn - 1, size);
3030
for (int i = mn; i < mx + 1; i++) {
@@ -45,13 +45,13 @@ Ppg::Ppg(float spl)
4545
lpf {0.11595249, 0.23190498, 0.11595249, -0.72168143, 0.18549138} {
4646
}
4747

48-
int Ppg::Preprocess(float spl) {
48+
int8_t Ppg::Preprocess(float spl) {
4949
spl -= offset;
5050
spl = hpf.Step(spl);
5151
spl = agc.Step(spl);
5252
spl = lpf.Step(spl);
5353

54-
auto spl_int = static_cast<int>(spl);
54+
auto spl_int = static_cast<int8_t>(spl);
5555

5656
if (dataIndex < 200)
5757
data[dataIndex++] = spl_int;

src/components/heartrate/Ppg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ namespace Pinetime {
1010
public:
1111
explicit Ppg(float spl);
1212

13-
int Preprocess(float spl);
13+
int8_t Preprocess(float spl);
1414
float HeartRate();
1515

1616
void SetOffset(uint16_t i);
1717
void Reset();
1818

1919
private:
20-
std::array<int, 200> data;
20+
std::array<int8_t, 200> data;
2121
size_t dataIndex = 0;
2222
float offset;
2323
Biquad hpf;
@@ -27,4 +27,4 @@ namespace Pinetime {
2727
float ProcessHeartRate();
2828
};
2929
}
30-
}
30+
}

0 commit comments

Comments
 (0)