-
-
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.
Split sensor code out into their own files
- Loading branch information
Showing
15 changed files
with
550 additions
and
467 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include "SensorData.h" | ||
|
||
class CyclePowerData : public SensorData | ||
{ | ||
public: | ||
CyclePowerData() : SensorData("CPS"){}; | ||
|
||
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: | ||
int power; | ||
float cadence; | ||
float crankRev = 0; | ||
float lastCrankRev = 0; | ||
float lastCrankEventTime = 0; | ||
float crankEventTime = 0; | ||
uint8_t missedReadingCount = 0; | ||
}; |
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,53 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include "SensorData.h" | ||
|
||
class FitnessMachineIndoorBikeData : public SensorData | ||
{ | ||
public: | ||
FitnessMachineIndoorBikeData() : SensorData("FTMS"){}; | ||
|
||
bool hasHeartRate(); | ||
bool hasCadence(); | ||
bool hasPower(); | ||
bool hasSpeed(); | ||
int getHeartRate(); | ||
float getCadence(); | ||
int getPower(); | ||
float getSpeed(); | ||
void decode(uint8_t *data, size_t length); | ||
|
||
enum Types : uint8_t | ||
{ | ||
InstantaneousSpeed = 0, | ||
AverageSpeed = 1, | ||
InstantaneousCadence = 2, | ||
AverageCadence = 3, | ||
TotalDistance = 4, | ||
ResistanceLevel = 5, | ||
InstantaneousPower = 6, | ||
AveragePower = 7, | ||
TotalEnergy = 8, | ||
EnergyPerHour = 9, | ||
EnergyPerMinute = 10, | ||
HeartRate = 11, | ||
MetabolicEquivalent = 12, | ||
ElapsedTime = 13, | ||
RemainingTime = 14 | ||
}; | ||
|
||
static constexpr uint8_t FieldCount = Types::RemainingTime + 1; | ||
|
||
private: | ||
double_t values[FieldCount]; | ||
|
||
// See: https://github.com/oesmith/gatt-xml/blob/master/org.bluetooth.characteristic.indoor_bike_data.xml | ||
static uint8_t const flagBitIndices[]; | ||
static uint8_t const flagEnabledValues[]; | ||
static size_t const byteSizes[]; | ||
static uint8_t const signedFlags[]; | ||
static double_t const resolutions[]; | ||
|
||
static int convert(int value, size_t length, uint8_t isSigned); | ||
}; |
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,24 @@ | ||
#pragma once | ||
|
||
#include "SensorData.h" | ||
|
||
class FlywheelData : public SensorData | ||
{ | ||
public: | ||
FlywheelData() : SensorData("FLYW"){}; | ||
|
||
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; | ||
int power; | ||
}; |
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,22 @@ | ||
#pragma once | ||
|
||
#include "SensorData.h" | ||
|
||
class HeartRateData : public SensorData | ||
{ | ||
public: | ||
HeartRateData() : SensorData("HRM"){}; | ||
|
||
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: | ||
int heartrate; | ||
}; |
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,23 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
class SensorData | ||
{ | ||
public: | ||
SensorData(String id) : id(id){}; | ||
|
||
String getId(); | ||
virtual bool hasHeartRate() = 0; | ||
virtual bool hasCadence() = 0; | ||
virtual bool hasPower() = 0; | ||
virtual bool hasSpeed() = 0; | ||
virtual int getHeartRate() = 0; | ||
virtual float getCadence() = 0; | ||
virtual int getPower() = 0; | ||
virtual float getSpeed() = 0; | ||
virtual void decode(uint8_t *data, size_t length) = 0; | ||
|
||
private: | ||
String id; | ||
}; |
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,50 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <Arduino.h> | ||
#include <NimBLEDevice.h> | ||
#include "SensorData.h" | ||
#include "CyclePowerData.h" | ||
#include "FlywheelData.h" | ||
#include "FitnessMachineIndoorBikeData.h" | ||
#include "HeartRateData.h" | ||
|
||
class SensorDataFactory | ||
{ | ||
public: | ||
SensorDataFactory(){}; | ||
|
||
std::shared_ptr<SensorData> getSensorData(BLERemoteCharacteristic *characteristic, uint8_t *data, size_t length); | ||
|
||
private: | ||
class KnownDevice | ||
{ | ||
public: | ||
KnownDevice(NimBLEUUID uuid, std::shared_ptr<SensorData> sensorData) : uuid(uuid), sensorData(sensorData){}; | ||
NimBLEUUID getUUID(); | ||
std::shared_ptr<SensorData> decode(uint8_t *data, size_t length); | ||
|
||
private: | ||
NimBLEUUID uuid; | ||
std::shared_ptr<SensorData> sensorData; | ||
}; | ||
|
||
class NullData : public SensorData | ||
{ | ||
public: | ||
NullData() : SensorData("Null"){}; | ||
|
||
virtual bool hasHeartRate(); | ||
virtual bool hasCadence(); | ||
virtual bool hasPower(); | ||
virtual bool hasSpeed(); | ||
virtual int getHeartRate(); | ||
virtual float getCadence(); | ||
virtual int getPower(); | ||
virtual float getSpeed(); | ||
virtual void decode(uint8_t *data, size_t length); | ||
}; | ||
|
||
std::vector<KnownDevice *> knownDevices; | ||
static std::shared_ptr<SensorData> NULL_SENSOR_DATA; | ||
}; |
Oops, something went wrong.