Reformatted all the files according to clang-format style

This commit is contained in:
Avamander
2021-04-18 20:28:14 +03:00
parent e56ebb8bd6
commit 40d45d923b
179 changed files with 10119 additions and 10688 deletions

View File

@@ -9,8 +9,7 @@
using namespace Pinetime::Controllers;
/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
Biquad::Biquad(float b0, float b1, float b2, float a1, float a2) : b0{b0}, b1{b1}, b2{b2}, a1{a1}, a2{a2} {
Biquad::Biquad(float b0, float b1, float b2, float a1, float a2) : b0 {b0}, b1 {b1}, b2 {b2}, a1 {a1}, a2 {a2} {
}
float Biquad::Step(float x) {

View File

@@ -4,11 +4,11 @@ namespace Pinetime {
namespace Controllers {
/// Direct Form II Biquad Filter
class Biquad {
public:
Biquad(float b0, float b1, float b2, float a1, float a2);
public:
Biquad(float b0, float b1, float b2, float a1, float a2);
float Step(float x);
private:
private:
float b0;
float b1;
float b2;

View File

@@ -4,38 +4,35 @@
using namespace Pinetime::Controllers;
HeartRateController::HeartRateController(Pinetime::System::SystemTask &systemTask) : systemTask{systemTask} {
HeartRateController::HeartRateController(Pinetime::System::SystemTask& systemTask) : systemTask {systemTask} {
}
void HeartRateController::Update(HeartRateController::States newState, uint8_t heartRate) {
this->state = newState;
if(this->heartRate != heartRate) {
if (this->heartRate != heartRate) {
this->heartRate = heartRate;
service->OnNewHeartRateValue(heartRate);
}
}
void HeartRateController::Start() {
if(task != nullptr) {
if (task != nullptr) {
state = States::NotEnoughData;
task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StartMeasurement);
}
}
void HeartRateController::Stop() {
if(task != nullptr) {
if (task != nullptr) {
state = States::Stopped;
task->PushMessage(Pinetime::Applications::HeartRateTask::Messages::StopMeasurement);
}
}
void HeartRateController::SetHeartRateTask(Pinetime::Applications::HeartRateTask *task) {
void HeartRateController::SetHeartRateTask(Pinetime::Applications::HeartRateTask* task) {
this->task = task;
}
void HeartRateController::SetService(Pinetime::Controllers::HeartRateService *service) {
void HeartRateController::SetService(Pinetime::Controllers::HeartRateService* service) {
this->service = service;
}

View File

@@ -12,8 +12,8 @@ namespace Pinetime {
}
namespace Controllers {
class HeartRateController {
public:
enum class States { Stopped, NotEnoughData, NoTouch, Running};
public:
enum class States { Stopped, NotEnoughData, NoTouch, Running };
explicit HeartRateController(System::SystemTask& systemTask);
@@ -22,12 +22,16 @@ namespace Pinetime {
void Update(States newState, uint8_t heartRate);
void SetHeartRateTask(Applications::HeartRateTask* task);
States State() const { return state; }
uint8_t HeartRate() const { return heartRate; }
States State() const {
return state;
}
uint8_t HeartRate() const {
return heartRate;
}
void SetService(Pinetime::Controllers::HeartRateService *service);
void SetService(Pinetime::Controllers::HeartRateService* service);
private:
private:
System::SystemTask& systemTask;
Applications::HeartRateTask* task = nullptr;
States state = States::Stopped;

View File

@@ -13,7 +13,7 @@ using namespace Pinetime::Controllers;
namespace {
int Compare(int* d1, int* d2, size_t count) {
int e = 0;
for(size_t i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++) {
auto d = d1[i] - d2[i];
e += d * d;
}
@@ -21,15 +21,15 @@ namespace {
}
int CompareShift(int* d, int shift, size_t count) {
return Compare(d +shift, d, count - shift);
return Compare(d + shift, d, count - shift);
}
int Trough(int* d, size_t size, float mn, float mx) {
auto z2 = CompareShift(d, mn-2, size);
auto z1 = CompareShift(d, mn-1, size);
for(int i = mn; i < mx + 1; i++) {
auto z2 = CompareShift(d, mn - 2, size);
auto z1 = CompareShift(d, mn - 1, size);
for (int i = mn; i < mx + 1; i++) {
auto z = CompareShift(d, i, size);
if(z2 > z1 && z1 < z)
if (z2 > z1 && z1 < z)
return i;
z2 = z1;
z1 = z;
@@ -38,11 +38,11 @@ namespace {
}
}
Ppg::Ppg(float spl) : offset{spl},
hpf{0.87033078, -1.74066156, 0.87033078,-1.72377617, 0.75754694},
agc{20, 0.971, 2},
lpf{0.11595249, 0.23190498, 0.11595249,-0.72168143, 0.18549138} {
Ppg::Ppg(float spl)
: offset {spl},
hpf {0.87033078, -1.74066156, 0.87033078, -1.72377617, 0.75754694},
agc {20, 0.971, 2},
lpf {0.11595249, 0.23190498, 0.11595249, -0.72168143, 0.18549138} {
}
int Ppg::Preprocess(float spl) {
@@ -53,13 +53,13 @@ int Ppg::Preprocess(float spl) {
auto spl_int = static_cast<int>(spl);
if(dataIndex < 200)
if (dataIndex < 200)
data[dataIndex++] = spl_int;
return spl_int;
}
float Ppg::HeartRate() {
if(dataIndex < 200)
if (dataIndex < 200)
return 0;
NRF_LOG_INFO("PREPROCESS, offset = %d", offset);
@@ -71,26 +71,26 @@ float Ppg::HeartRate() {
int cccount = 0;
float Ppg::ProcessHeartRate() {
if(cccount > 2)
if (cccount > 2)
asm("nop");
cccount ++;
cccount++;
auto t0 = Trough(data.data(), dataIndex, 7, 48);
if(t0 < 0)
if (t0 < 0)
return 0;
float t1 = t0 * 2;
t1 = Trough(data.data(), dataIndex, t1-5, t1+5);
if(t1 < 0)
t1 = Trough(data.data(), dataIndex, t1 - 5, t1 + 5);
if (t1 < 0)
return 0;
float t2 = static_cast<int>(t1 * 3) / 2;
t2 = Trough(data.data(), dataIndex, t2 - 5, t2 + 5);
if(t2 < 0)
if (t2 < 0)
return 0;
float t3 = static_cast<int>(t2 * 4) / 3;
t3 = Trough(data.data(), dataIndex, t3 - 4, t3 + 4);
if(t3 < 0)
if (t3 < 0)
return static_cast<int>(60 * 24 * 3) / static_cast<int>(t2);
return static_cast<int>(60 * 24 * 4) / static_cast<int>(t3);

View File

@@ -7,7 +7,7 @@
namespace Pinetime {
namespace Controllers {
class Ppg {
public:
public:
explicit Ppg(float spl);
int Preprocess(float spl);
@@ -16,7 +16,7 @@ namespace Pinetime {
void SetOffset(uint16_t i);
void Reset();
private:
private:
std::array<int, 200> data;
size_t dataIndex = 0;
float offset;
@@ -24,7 +24,6 @@ namespace Pinetime {
Ptagc agc;
Biquad lpf;
float ProcessHeartRate();
};
}

View File

@@ -10,17 +10,16 @@
using namespace Pinetime::Controllers;
/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
Ptagc::Ptagc(float start, float decay, float threshold) : peak{start}, decay{decay}, boost{1.0f/decay}, threshold{threshold} {
Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {decay}, boost {1.0f / decay}, threshold {threshold} {
}
float Ptagc::Step(float spl) {
if(std::abs(spl) > peak)
if (std::abs(spl) > peak)
peak *= boost;
else
peak *= decay;
if((spl > (peak * threshold)) || (spl < (peak * -threshold)))
if ((spl > (peak * threshold)) || (spl < (peak * -threshold)))
return 0.0f;
spl = 100.0f * spl / (2.0f * peak);

View File

@@ -3,16 +3,15 @@
namespace Pinetime {
namespace Controllers {
class Ptagc {
public:
public:
Ptagc(float start, float decay, float threshold);
float Step(float spl);
private:
private:
float peak;
float decay;
float boost;
float threshold;
};
}
}