-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from doudar/serial_test
- Loading branch information
Showing
14 changed files
with
363 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (C) 2020 Anthony Doud & Joel Baranick | ||
* All rights reserved | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-only | ||
*/ | ||
#include <NimBLEDevice.h> | ||
#include <Arduino.h> | ||
#include <Main.h> | ||
|
||
#pragma once | ||
|
||
|
||
void collectAndSet(NimBLEUUID charUUID, NimBLEUUID serviceUUID, NimBLEAddress address, uint8_t *pData, size_t length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2020 Anthony Doud & Joel Baranick | ||
* All rights reserved | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-only | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "SensorData.h" | ||
|
||
class PelotonData : public SensorData { | ||
public: | ||
PelotonData() : SensorData("PTON") {} | ||
|
||
bool hasHeartRate(); | ||
bool hasCadence(); | ||
bool hasPower(); | ||
bool hasSpeed(); | ||
int getHeartRate(); | ||
float getCadence(); | ||
int getPower(); | ||
float getSpeed(); | ||
void decode(uint8_t *data, size_t length); | ||
|
||
private: | ||
bool hasData = false; | ||
float cadence = nanf(""); | ||
int power = INT_MIN; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2020 Anthony Doud & Joel Baranick | ||
* All rights reserved | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-only | ||
*/ | ||
|
||
#include "endian.h" | ||
#include "sensors/PelotonData.h" | ||
#include "Constants.h" | ||
|
||
bool PelotonData::hasHeartRate() { return false; } | ||
|
||
bool PelotonData::hasCadence() { return this->hasData; } | ||
|
||
bool PelotonData::hasPower() { return this->hasData; } | ||
|
||
bool PelotonData::hasSpeed() { return false; } | ||
|
||
int PelotonData::getHeartRate() { return INT_MIN; } | ||
|
||
float PelotonData::getCadence() { return this->cadence; } | ||
|
||
int PelotonData::getPower() { return this->power; } | ||
|
||
float PelotonData::getSpeed() { return nanf(""); } | ||
|
||
void PelotonData::decode(uint8_t *data, size_t length) { | ||
float value = 0.0; | ||
const uint8_t payload_length = data[2]; | ||
for (uint8_t i = 2 + payload_length; i > 2; i--) { | ||
// -30 = Convert from ASCII to numeric | ||
uint8_t next_digit = data[i] - 0x30; | ||
// Check for overflow | ||
if (value > 6553 || (value == 6553 && next_digit > 5)) { | ||
return; | ||
} | ||
value = value * 10 + next_digit; | ||
} | ||
hasData = true; | ||
switch (data[1]) { | ||
case POW_ID: | ||
if (value >= 0) { | ||
power = value / 10; | ||
} else { | ||
power = 0; | ||
} | ||
|
||
break; | ||
|
||
case CAD_ID: | ||
cadence = value; | ||
break; | ||
|
||
case RES_ID: | ||
// we don't use resistance | ||
break; | ||
|
||
default: | ||
break; | ||
// cadence = nanf(""); | ||
// power = INT_MIN; | ||
// hasData = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.