forked from doudar/SmartSpin2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEchelonData.cpp
45 lines (35 loc) · 1.16 KB
/
EchelonData.cpp
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
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include "sensors/EchelonData.h"
bool EchelonData::hasHeartRate() { return false; }
bool EchelonData::hasCadence() { return !std::isnan(this->cadence); }
bool EchelonData::hasPower() { return this->cadence >= 0 && this->resistance >= 0; }
bool EchelonData::hasSpeed() { return false; }
int EchelonData::getHeartRate() { return INT_MIN; }
float EchelonData::getCadence() { return this->cadence; }
int EchelonData::getPower() { return this->power; }
float EchelonData::getSpeed() { return nanf(""); }
void EchelonData::decode(uint8_t *data, size_t length) {
switch (data[1]) {
// Cadence notification
case 0xD1:
this->cadence = static_cast<int>((data[9] << 8) + data[10]);
break;
// Resistance notification
case 0xD2:
this->resistance = static_cast<int>(data[3]);
break;
}
if (std::isnan(this->cadence) || this->resistance < 0) {
return;
}
if (this->cadence == 0 || this->resistance == 0) {
power = 0;
} else {
power = pow(1.090112, resistance) * pow(1.015343, cadence) * 7.228958;
}
}