mirror of
https://github.com/m5stack/M5Unit-HEART.git
synced 2026-05-20 11:28:19 -07:00
Fixes HeartRate
This commit is contained in:
@@ -23,13 +23,6 @@ m5::unit::UnitUnified Units;
|
||||
m5::unit::UnitHEART unitHeart;
|
||||
m5::max30100::HeartRate heartRate(100);
|
||||
|
||||
uint32_t getSamplingRate(const m5::unit::max30100::Sampling rate) {
|
||||
static constexpr uint32_t table[] = {50, 100, 167, 200, 400, 600, 800, 1000};
|
||||
return table[m5::stl::to_underlying(rate)];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
|
||||
@@ -40,7 +33,7 @@ void setup() {
|
||||
cfg.pulseWidth = m5::unit::max30100::LedPulseWidth::PW400;
|
||||
cfg.irCurrent = m5::unit::max30100::CurrentControl::mA7_6;
|
||||
cfg.redCurrent = m5::unit::max30100::CurrentControl::mA7_6;
|
||||
heartRate.setSamplingRate(getSamplingRate(cfg.samplingRate));
|
||||
heartRate.setSamplingRate(m5::max30100::HeartRate::getSamplingRate(cfg.samplingRate));
|
||||
heartRate.setThreshold(25.0f); // depends on ir/redCurrent
|
||||
unitHeart.config(cfg);
|
||||
}
|
||||
@@ -88,8 +81,7 @@ void loop() {
|
||||
Units.update();
|
||||
if (unitHeart.updated()) {
|
||||
while (unitHeart.available()) {
|
||||
// M5_LOGI("\n>IR:%u\n>RED:%u", unitHeart.ir(),
|
||||
// unitHeart.red());
|
||||
M5_LOGI("\n>IR:%u\n>RED:%u", unitHeart.ir(), unitHeart.red());
|
||||
bool beat = heartRate.push_back((float)unitHeart.ir(), (float)unitHeart.red());
|
||||
if (beat) {
|
||||
M5_LOGI("Beat!");
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define M5_UNIT_HEART_HPP
|
||||
|
||||
#include "unit/unit_MAX30100.hpp"
|
||||
#include "utility/heart_rate.hpp"
|
||||
|
||||
/*!
|
||||
@namespace m5
|
||||
|
||||
@@ -296,11 +296,11 @@ class UnitMAX30100 : public Component, public PeriodicMeasurementAdapter<UnitMAX
|
||||
|
||||
///@name Measurement data by periodic
|
||||
///@{
|
||||
//! @brief Oldest CO2eq (ppm)
|
||||
//! @brief Oldest IR
|
||||
inline uint16_t ir() const {
|
||||
return !empty() ? oldest().ir() : 0;
|
||||
}
|
||||
//! @brief Oldest TVOC (ppb)
|
||||
//! @brief Oldest Red
|
||||
inline uint16_t red() const {
|
||||
return !empty() ? oldest().red() : 0;
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@ bool HeartRate::push_back(const float ir, const float red) {
|
||||
|
||||
// SpO2
|
||||
_acSqIR += _dcIR.result * _dcIR.result;
|
||||
//_acSqRED += _dcRED.result * _dcRED.result;
|
||||
_acSqRED = _dcRED.result * _dcRED.result;
|
||||
++_count;
|
||||
if (_beat) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <deque>
|
||||
#include <cstddef>
|
||||
#include <m5_unit_component/types.hpp>
|
||||
#include "../unit/unit_max30100.hpp"
|
||||
|
||||
namespace m5 {
|
||||
namespace max30100 {
|
||||
@@ -42,12 +43,22 @@ struct butterworthFilter_t {
|
||||
*/
|
||||
class HeartRate {
|
||||
public:
|
||||
/*!
|
||||
@brief Conversion m5::unit::max30100::Sampling to sapling rate
|
||||
@param rate bm5::unit::max30100::Sampling value
|
||||
@return Sampling rate
|
||||
*/
|
||||
static uint32_t getSamplingRate(const m5::unit::max30100::Sampling rate) {
|
||||
static constexpr uint32_t table[] = {50, 100, 167, 200, 400, 600, 800, 1000};
|
||||
return table[m5::stl::to_underlying(rate)];
|
||||
}
|
||||
|
||||
/*!
|
||||
@param sr Sampling rate (e.g. 167 if max30100::Sampling::Rate167)
|
||||
@param threshold Threshold for detect beat (depends on ir/redCUrrent)
|
||||
@param store_size Stored data size(0U means auto)
|
||||
*/
|
||||
HeartRate(const uint32_t srate, const float threshold = 125.f, const size_t max_data_size = 0U);
|
||||
explicit HeartRate(const uint32_t srate = 1, const float threshold = 125.f, const size_t max_data_size = 0U);
|
||||
|
||||
///@name Settings
|
||||
///@{
|
||||
|
||||
Reference in New Issue
Block a user