Skip to content

Commit ee7489e

Browse files
committed
Cosmetic change
1 parent 6fb9866 commit ee7489e

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/utility/heart_rate.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace {
1919

2020
constexpr float ALPHA{0.95f}; // for removeDC
2121

22-
void calculateButterworthCoefficients(float Fs, float Fc, float& a0, float& a1, float& b1) {
22+
void calculateButterworthCoefficients(float Fs, float Fc, float& a0, float& a1, float& b1)
23+
{
2324
float tanWc = std::tan(M_PI * Fc / Fs);
2425
float sqrt2 = std::sqrt(2.0f);
2526

@@ -28,14 +29,16 @@ void calculateButterworthCoefficients(float Fs, float Fc, float& a0, float& a1,
2829
b1 = (tanWc - sqrt2) / (tanWc + sqrt2);
2930
}
3031

31-
inline dcFilter_t removeDC(const float x, const float prev_w, const float alpha) {
32+
inline dcFilter_t removeDC(const float x, const float prev_w, const float alpha)
33+
{
3234
dcFilter_t filtered;
3335
filtered.w = x + alpha * prev_w;
3436
filtered.result = filtered.w - prev_w;
3537
return filtered;
3638
}
3739

38-
float meanDiff(const float M, meanDiffFilter_t& filterValues) {
40+
float meanDiff(const float M, meanDiffFilter_t& filterValues)
41+
{
3942
float avg{};
4043

4144
filterValues.sum -= filterValues.values[filterValues.index];
@@ -53,7 +56,8 @@ float meanDiff(const float M, meanDiffFilter_t& filterValues) {
5356
return avg - M;
5457
}
5558

56-
void lowPassButterworthFilter(const float x, butterworthFilter_t& fr) {
59+
void lowPassButterworthFilter(const float x, butterworthFilter_t& fr)
60+
{
5761
fr.v[0] = fr.v[1];
5862
fr.v[1] = (fr.a0 * x) + (fr.a1 * fr.v[0]) - (fr.b1 * fr.v[1]);
5963
fr.result = fr.v[0] + fr.v[1];
@@ -75,21 +79,24 @@ namespace m5 {
7579
namespace max30100 {
7680

7781
HeartRate::HeartRate(const uint32_t srate, const float threshold, const size_t max_data_size)
78-
: _sampleRate{(float)srate}, _threshold(threshold), _maxDataSize{max_data_size} {
82+
: _sampleRate{(float)srate}, _threshold(threshold), _maxDataSize{max_data_size}
83+
{
7984
assert(srate && "SampleRate must not be zero");
8085
if (!max_data_size) {
8186
_maxDataSize = (size_t)srate * 30U;
8287
}
8388
calculateButterworthCoefficients(_sampleRate, 10.0f, _bwfIR.a0, _bwfIR.a1, _bwfIR.b1);
8489
}
8590

86-
void HeartRate::setSampleRate(const uint32_t sr) {
91+
void HeartRate::setSampleRate(const uint32_t sr)
92+
{
8793
_sampleRate = sr;
8894
calculateButterworthCoefficients(_sampleRate, 10.0f, _bwfIR.a0, _bwfIR.a1, _bwfIR.b1);
8995
clear();
9096
}
9197

92-
void HeartRate::clear() {
98+
void HeartRate::clear()
99+
{
93100
_dataIR.clear();
94101
_peakDowns.clear();
95102
_incrasing = false;
@@ -99,7 +106,8 @@ void HeartRate::clear() {
99106
calculateButterworthCoefficients(_sampleRate, 10.0f, _bwfIR.a0, _bwfIR.a1, _bwfIR.b1);
100107
}
101108

102-
bool HeartRate::push_back(const float ir, const float red) {
109+
bool HeartRate::push_back(const float ir, const float red)
110+
{
103111
// Filtering (IR)
104112
_dcIR = removeDC(ir, _dcIR.w, ALPHA);
105113
// M5_LIB_LOGI("\n>ACIR:%f", _dcIR.result);
@@ -136,7 +144,8 @@ bool HeartRate::push_back(const float ir, const float red) {
136144
return _beat;
137145
}
138146

139-
float HeartRate::calculate() const {
147+
float HeartRate::calculate() const
148+
{
140149
if (_peakDowns.size() < 2) {
141150
return 0.0f;
142151
}
@@ -149,7 +158,8 @@ float HeartRate::calculate() const {
149158
return 1.0f / avg * 60000.0f;
150159
}
151160

152-
bool HeartRate::detect_beat() {
161+
bool HeartRate::detect_beat()
162+
{
153163
auto now = m5::utility::millis();
154164
bool beat{};
155165

src/utility/heart_rate.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ struct butterworthFilter_t {
4242
@brief Utility class for calcurate heart beat rate and SpO2
4343
*/
4444
class HeartRate {
45-
public:
45+
public:
4646
/*!
4747
@brief Conversion m5::unit::max30100::Sample to sapling rate
4848
@param rate bm5::unit::max30100::Sample value
4949
@return Sample rate
5050
*/
51-
static uint32_t getSampleRate(const m5::unit::max30100::Sample rate) {
51+
static uint32_t getSampleRate(const m5::unit::max30100::Sample rate)
52+
{
5253
static constexpr uint32_t table[] = {50, 100, 167, 200, 400, 600, 800, 1000};
5354
return table[m5::stl::to_underlying(rate)];
5455
}
@@ -65,11 +66,13 @@ class HeartRate {
6566
//! @brief Set sample rate
6667
void setSampleRate(const uint32_t sr);
6768
//! @brief Set threshold
68-
void setThreshold(const float t) {
69+
void setThreshold(const float t)
70+
{
6971
_threshold = t;
7072
}
7173
//! @brief Set coefficients for SpO2 calculations
72-
void setSpO2Coefficients(const float coeff) {
74+
void setSpO2Coefficients(const float coeff)
75+
{
7376
_coeffSpO2 = coeff;
7477
}
7578
///@}
@@ -90,12 +93,13 @@ class HeartRate {
9093
*/
9194
float calculate() const;
9295
//! @brief Gets the latest SpO2
93-
float SpO2() const {
96+
float SpO2() const
97+
{
9498
return _SpO2;
9599
}
96100
///@}
97101

98-
private:
102+
private:
99103
bool detect_beat();
100104

101105
float _sampleRate{}, _threshold{};

0 commit comments

Comments
 (0)