Library for MAX30101 SpO2 and heart rate sensor
Dependents: HeartRate HeartRate proj final_project_ee119 ... more
Revision 5:be1dde31fe49, committed 2017-05-05
- Comitter:
- j3
- Date:
- Fri May 05 00:25:21 2017 +0000
- Parent:
- 4:d1b50bd4065a
- Child:
- 6:302fb0f991d8
- Commit message:
- added useful enums
Changed in this revision
| MAX30101.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MAX30101.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX30101.cpp Thu May 04 23:46:46 2017 +0000
+++ b/MAX30101.cpp Fri May 05 00:25:21 2017 +0000
@@ -260,50 +260,47 @@
//*****************************************************************************
-int32_t MAX30101::readFIFO(uint8_t numLeds, uint8_t *data, uint16_t &readBytes)
+int32_t MAX30101::readFIFO(LedChannels_e numLeds, uint8_t *data, uint16_t &readBytes)
{
int32_t result = -1;
readBytes = 0;
- if((numLeds > 0) && (numLeds < 4))
+ //Get write pointer
+ result = readRegister(FIFO_WritePointer, m_fifoWritePtr);
+ if(result == 0)
{
- //Get write pointer
- result = readRegister(FIFO_WritePointer, m_fifoWritePtr);
+ //Get read pointer
+ result = readRegister(FIFO_ReadPointer, m_fifoReadPtr);
if(result == 0)
{
- //Get read pointer
- result = readRegister(FIFO_ReadPointer, m_fifoReadPtr);
+ //Calculate num bytes to read
+ if(m_fifoWritePtr > m_fifoReadPtr)
+ {
+ m_fifoNumBytes = ((m_fifoWritePtr - m_fifoReadPtr) *
+ (BYTES_PER_CH * numLeds));
+ }
+ else
+ {
+ m_fifoNumBytes = (((32 - m_fifoReadPtr) + m_fifoWritePtr) *
+ (BYTES_PER_CH * numLeds));
+ }
+
+ //temporary buffer for data
+ char local_data[m_fifoNumBytes];
+ local_data[0] = FIFO_DataRegister;
+
+ //Set fifo data ptr
+ result = m_i2cBus.write(I2C_W_ADRS, local_data, 1, true);
if(result == 0)
{
- //Calculate num bytes to read
- if(m_fifoWritePtr > m_fifoReadPtr)
- {
- m_fifoNumBytes = ((m_fifoWritePtr - m_fifoReadPtr) *
- (BYTES_PER_CH * numLeds));
- }
- else
- {
- m_fifoNumBytes = (((32 - m_fifoReadPtr) + m_fifoWritePtr) *
- (BYTES_PER_CH * numLeds));
- }
-
- //temporary buffer for data
- char local_data[m_fifoNumBytes];
- local_data[0] = FIFO_DataRegister;
-
- //Set fifo data ptr
- result = m_i2cBus.write(I2C_W_ADRS, local_data, 1, true);
+ //read fifo
+ result = m_i2cBus.read(I2C_R_ADRS, local_data, m_fifoNumBytes);
if(result == 0)
{
- //read fifo
- result = m_i2cBus.read(I2C_R_ADRS, local_data, m_fifoNumBytes);
- if(result == 0)
- {
- //move data to user buffer
- memcpy(data, local_data, m_fifoNumBytes);
- readBytes = m_fifoNumBytes;
- }
+ //move data to user buffer
+ memcpy(data, local_data, m_fifoNumBytes);
+ readBytes = m_fifoNumBytes;
}
}
}
--- a/MAX30101.h Thu May 04 23:46:46 2017 +0000
+++ b/MAX30101.h Fri May 05 00:25:21 2017 +0000
@@ -109,6 +109,57 @@
MultiLedMode = 7
};
+ ///Number of LED channels used
+ enum LedChannels_e
+ {
+ OneLedChannel = 1,
+ TwoLedChannels = 2,
+ ThreeLedChannels = 3
+ };
+
+ ///Number of samples averaged per FIFO sample, set in FIFO config
+ enum NumSamplesAveraged_e
+ {
+ AveragedSamples_0 = 0,
+ AveragedSamples_2 = 1,
+ AveragedSamples_4 = 2,
+ AveragedSamples_8 = 3,
+ AveragedSamples_16 = 4,
+ AveragedSamples_32 = 5
+ };
+
+ ///ADC Range, set in SpO2 config
+ enum ADCRange_e
+ {
+ ADC_Range_0 = 0,
+ ADC_Range_1 = 1,
+ ADC_Range_2 = 2,
+ ADC_Range_3 = 3
+ };
+
+ //LED PulseWidth, set in SpO2 config
+ enum LEDPulseWidth
+ {
+ PW_0 = 0,
+ PW_1 = 0,
+ PW_2 = 0,
+ PW_3 = 0
+ };
+
+
+ ///Sample rate, set in SpO2 config
+ enum SampleRate_e
+ {
+ SR_50_Hz = 0,
+ SR_100_Hz = 1,
+ SR_200_Hz = 3,
+ SR_400_Hz = 4,
+ SR_800_Hz = 5,
+ SR_1000_Hz = 6,
+ SR_1600_Hz = 7,
+ SR_3200_Hz = 8
+ };
+
///Interrupt Status/Enable BitField
union InterruptBitField_u
{
@@ -345,7 +396,7 @@
*
* @return 0 on success, non 0 otherwise
*/
- int32_t readFIFO(uint8_t numLeds, uint8_t *data, uint16_t &readBytes);
+ int32_t readFIFO(LedChannels_e numLeds, uint8_t *data, uint16_t &readBytes);
protected: