M5Unit-HEART 0.1.0 git rev:05c3b01
Loading...
Searching...
No Matches
m5::unit::UnitMAX30102 Class Reference

Pulse oximetry and heart-rate sensor. More...

#include <unit_MAX30102.hpp>

Inheritance diagram for m5::unit::UnitMAX30102:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitMAX30102 (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual bool begin () override
 
virtual void update (const bool force=false) override
 
uint32_t caluculateSamplingRate ()
 Calculate the sampling rate from the current settings.
 
bool reset ()
 Reset.
 
bool readRevisionID (uint8_t &rev)
 Read the revision ID.
 
Settings for begin
config_t config ()
 Gets the configration.
 
void config (const config_t &cfg)
 Set the configration.
 
Measurement data by periodic
uint32_t ir () const
 Oldest IR.
 
uint32_t red () const
 Oldest Red.
 
uint8_t retrived () const
 Number of data last retrieved.
 
uint8_t overflow () const
 The number of samples lost.
 
Periodic measurement
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool startPeriodicMeasurement (const max30102::Mode mode, const max30102::ADC range, const max30102::Sampling rate, const max30102::LEDPulse width, const max30102::FIFOSampling avg, const uint8_t ir_current, const uint8_t red_current)
 Start periodic measurement.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
Mode configuration
bool readMode (max30102::Mode &mode)
 Read the operation mode.
 
bool writeMode (const max30102::Mode mode)
 Write the operation mode.
 
bool readShutdownControl (bool &shdn)
 Read the shutdown control.
 
bool writeShutdownControl (const bool shdn)
 Write the shutdown control.
 
SpO2 configuration
Note
Note that there are different combinations that can be set depending on the mode
  • Mode:SPO2
    Sampling\LEDPulseWidth 69 118 215 411
    50 o o o o
    100 o o o o
    200 o o o o
    400 o o o o
    800 o o o x
    1000 o o x x
    1600 o x x x
    3200 x x x x
  • Mode:HROnly
    Sampling\LEDPulseWidth 69 118 215 411
    50 o o o o
    100 o o o o
    200 o o o o
    400 o o o o
    800 o o o o
    1000 o o o o
    1600 o o o x
    3200 o x x x
bool readSpO2Configuration (max30102::ADC &range, max30102::Sampling &rate, max30102::LEDPulse &width)
 Read the SpO2 configuration.
 
bool readSpO2ADCRange (max30102::ADC &range)
 Read the ADC range.
 
bool readSpO2SamplingRate (max30102::Sampling &rate)
 Read the sampling rate.
 
bool readSpO2LEDPulseWidth (max30102::LEDPulse &width)
 Read the LED pulse width.
 
bool writeSpO2Configuration (const max30102::ADC range, const max30102::Sampling rate, const max30102::LEDPulse width)
 Write the SpO2 configuration.
 
bool writeSpO2ADCRange (const max30102::ADC range)
 Write the ADC range.
 
bool writeSpO2SamplingRate (const max30102::Sampling rate)
 Write the sampling rate.
 
bool writeSpO2LEDPulseWidth (const max30102::LEDPulse width)
 Write the LED pulse width.
 
LED Pulse Amplitude
Note
Note that the target LEDs differ depending on the mode
In SPO2/HRonly mode, slot1(LED1):Red slot2(LED2):IR
In MultiMode, it is the same as the Slot setting
bool readLEDCurrent (uint8_t &raw, const uint8_t slot)
 Read the LED current.
 
bool readLEDCurrent (float &mA, const uint8_t slot)
 Read the LED current.
 
bool writeLEDCurrent (const uint8_t slot, const uint8_t raw)
 Write the LED current.
 
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeLEDCurrent (const uint8_t slot, const T mA)
 Write the LED current.
 
Multi-LED Mode Control
Warning
Available only in MultiLED Mode
For MAX30102 only slots 1 and 2 are valid
bool readMultiLEDModeControl (max30102::Slot &slot1, max30102::Slot &slot2)
 Read the the MultiLED Mode form Slot 1-2.
 
bool writeMultiLEDModeControl (const max30102::Slot slot1, const max30102::Slot slot2)
 Write the MultiLED Mode to Slot 1-2.
 
Measurement temperature
bool measureTemperatureSingleshot (max30102::TemperatureData &td)
 Measure tempeature single shot.
 
FIFO
bool readFIFOConfiguration (max30102::FIFOSampling &avg, bool &rollover, uint8_t &almostFull)
 Read the FIFO configuration.
 
bool writeFIFOConfiguration (const max30102::FIFOSampling avg, const bool rollover, const uint8_t almostFull)
 Write the FIFO configuration.
 
bool readFIFOReadPointer (uint8_t &rptr)
 Read the FIFO read pointer.
 
bool writeFIFOReadPointer (const uint8_t rptr)
 Write the FIFO read pointer.
 
bool readFIFOWritePointer (uint8_t &wptr)
 Read the FIFO write pointer.
 
bool writeFIFOWritePointer (const uint8_t wptr)
 Write the FIFO write pointer.
 
bool readFIFOOverflowCounter (uint8_t &cnt)
 Read the FIFO overflow counter.
 
bool writeFIFOOverflowCounter (const uint8_t cnt)
 Write the FIFO overflow counter.
 
bool resetFIFO ()
 Reset FIFO pointer and counter.
 

Protected Member Functions

bool read_register (const uint8_t reg, uint8_t *buf, const size_t len)
 
bool read_register8 (const uint8_t reg, uint8_t &v)
 
bool start_periodic_measurement ()
 
bool start_periodic_measurement (const max30102::Mode mode, const max30102::ADC range, const max30102::Sampling rate, const max30102::LEDPulse width, const max30102::FIFOSampling avg, const uint8_t ir_current, const uint8_t red_current)
 
bool stop_periodic_measurement ()
 
bool write_spo2_configuration (const max30102::SpO2Configuration &sc)
 
bool read_led_current (const uint8_t idx, uint8_t &raw)
 
bool read_led_current (const uint8_t idx, float &mA)
 
bool write_led_current (const uint8_t idx, const uint8_t raw)
 
bool write_led_current (const uint8_t idx, const float mA)
 
bool write_fifo_sampling_average (const max30102::FIFOSampling avg)
 
bool read_FIFO ()
 
bool reset_FIFO (const bool circling_read_ptr=true)
 
bool read_measurement_temperature (max30102::TemperatureData &td)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitMAX30102, max30102::Data)
 

Protected Attributes

std::unique_ptr< m5::container::CircularBuffer< max30102::Data > > _data {}
 
max30102::Mode _mode {}
 
uint8_t _retrived {}
 
uint8_t _overflow {}
 
uint32_t _mask {}
 
max30102::Slot _slot [2] {}
 
config_t _cfg {}
 

Detailed Description

Pulse oximetry and heart-rate sensor.

Note
The only single measurement is temperature; other data is constantly measured and stored

Member Function Documentation

◆ caluculateSamplingRate()

uint32_t m5::unit::UnitMAX30102::caluculateSamplingRate ( )

Calculate the sampling rate from the current settings.

Returns
>= 0 Sampling rate
Note
Calculate by FIFO average and SpO2 sampling rate

◆ measureTemperatureSingleshot()

bool m5::unit::UnitMAX30102::measureTemperatureSingleshot ( max30102::TemperatureData & td)

Measure tempeature single shot.

Parameters
[out]tdTemperatureData
Returns
True if successful
Warning
Blocking until measured about 29 ms
Does not work in power-save mode
See also
m5::unit::MAX30102::readShutdownControl

◆ overflow()

uint8_t m5::unit::UnitMAX30102::overflow ( ) const
inline

The number of samples lost.

Note
It saturates at (MAX_FIFO_DEPTH -1)

◆ readFIFOConfiguration()

bool m5::unit::UnitMAX30102::readFIFOConfiguration ( max30102::FIFOSampling & avg,
bool & rollover,
uint8_t & almostFull )

Read the FIFO configuration.

Parameters
[out]avgFIFO sampling average
[out]rollloverFIFO Rolls on Full if true
[out]almostFullFIFO Almost Full Value for interrupt
Returns
True if successful

◆ readLEDCurrent() [1/2]

bool m5::unit::UnitMAX30102::readLEDCurrent ( float & mA,
const uint8_t slot )
inline

Read the LED current.

Parameters
[out]mACurrent (mA)
slotSlot index (0:LED1 1:LED2)
Returns
True if successful
Note
mA Value in increments of 0.2

◆ readLEDCurrent() [2/2]

bool m5::unit::UnitMAX30102::readLEDCurrent ( uint8_t & raw,
const uint8_t slot )
inline

Read the LED current.

Parameters
[out]rawRaw value
slotSlot index (0:LED1 1:LED2)
Returns
True if successful

◆ readMode()

bool m5::unit::UnitMAX30102::readMode ( max30102::Mode & mode)

Read the operation mode.

Parameters
[out]modeMode
Returns
True if successful

◆ readMultiLEDModeControl()

bool m5::unit::UnitMAX30102::readMultiLEDModeControl ( max30102::Slot & slot1,
max30102::Slot & slot2 )

Read the the MultiLED Mode form Slot 1-2.

Parameters
[out]slot1Slot1 mode
[out]slot2Slot2 mode
Returns
True if successful

◆ readRevisionID()

bool m5::unit::UnitMAX30102::readRevisionID ( uint8_t & rev)

Read the revision ID.

Parameters
[out]revRevision
Returns
True if successful
Note
2-digit hexadecimal number (00 to FF) for part revision identification
Contact Maxim Integrated for the revision ID number assigned for your product

◆ readShutdownControl()

bool m5::unit::UnitMAX30102::readShutdownControl ( bool & shdn)

Read the shutdown control.

Parameters
[out]shdnShutdown control state (true:Power-save mode)
Returns
True if successful

◆ readSpO2Configuration()

bool m5::unit::UnitMAX30102::readSpO2Configuration ( max30102::ADC & range,
max30102::Sampling & rate,
max30102::LEDPulse & width )

Read the SpO2 configuration.

Parameters
[out]rangeADC rRange
[out]rateSampling rate
[out]widthLED pulse width
Returns
True if successful

◆ reset()

bool m5::unit::UnitMAX30102::reset ( )

Reset.

Returns
True if successful
Warning
Blocked until the reset process is completed

◆ retrived()

uint8_t m5::unit::UnitMAX30102::retrived ( ) const
inline

Number of data last retrieved.

Note
The number of data retrieved by the latest update, not all data accumulated
See also
available()

◆ startPeriodicMeasurement() [1/2]

bool m5::unit::UnitMAX30102::startPeriodicMeasurement ( )
inline

Start periodic measurement in the current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitMAX30102::startPeriodicMeasurement ( const max30102::Mode mode,
const max30102::ADC range,
const max30102::Sampling rate,
const max30102::LEDPulse width,
const max30102::FIFOSampling avg,
const uint8_t ir_current,
const uint8_t red_current )
inline

Start periodic measurement.

Parameters
modeOperation mode
rangeADC Range
rateSampling rate
widthLED pulse width
avgFIFO sampling average
ir_currentIR Led control (for All mode)
red_currentRED Led control (for Mode::SPO2 and Mode::MultiLED)
Returns
True if successful
Warning
Note that some combinations of rate and width are invalid. See also datasheet

◆ stopPeriodicMeasurement()

bool m5::unit::UnitMAX30102::stopPeriodicMeasurement ( )
inline

Stop periodic measurement.

Returns
True if successful
Note
Entering Power-save mode

◆ writeFIFOConfiguration()

bool m5::unit::UnitMAX30102::writeFIFOConfiguration ( const max30102::FIFOSampling avg,
const bool rollover,
const uint8_t almostFull )

Write the FIFO configuration.

Parameters
avgFIFO sampling average
rollloverFIFO Rolls on Full if true
almostFullFIFO Almost Full Value for interrupt
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeLEDCurrent() [1/2]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitMAX30102::writeLEDCurrent ( const uint8_t slot,
const T mA )
inline

Write the LED current.

Parameters
slotSlot index (0:LED1 1:LED2)
mACurrent (mA) 0 - 51.0f
Returns
True if successful
Note
mA Value in increments of 0.2

◆ writeLEDCurrent() [2/2]

bool m5::unit::UnitMAX30102::writeLEDCurrent ( const uint8_t slot,
const uint8_t raw )
inline

Write the LED current.

Parameters
slotSlot index (0:LED1 1:LED2)
rawRaw value
Returns
True if successful

◆ writeMode()

bool m5::unit::UnitMAX30102::writeMode ( const max30102::Mode mode)

Write the operation mode.

Parameters
modeMode
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeMultiLEDModeControl()

bool m5::unit::UnitMAX30102::writeMultiLEDModeControl ( const max30102::Slot slot1,
const max30102::Slot slot2 )

Write the MultiLED Mode to Slot 1-2.

Parameters
slot1Slot1 mode
slot2Slot2 mode
Returns
True if successful
Warning
The slots should be enabled in order (i.e., SLOT1 should not be disabled if SLOT2 is enabled)
During periodic detection runs, an error is returned

◆ writeShutdownControl()

bool m5::unit::UnitMAX30102::writeShutdownControl ( const bool shdn)

Write the shutdown control.

Parameters
shdnShutdown control state (true:Power-save mode)
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeSpO2Configuration()

bool m5::unit::UnitMAX30102::writeSpO2Configuration ( const max30102::ADC range,
const max30102::Sampling rate,
const max30102::LEDPulse width )

Write the SpO2 configuration.

Parameters
rangeADC rRange
rateSampling rate
widthLED pulse width
Returns
True if successful
Warning
During periodic detection runs, an error is returned