Library for MAX30101 SpO2 and heart rate sensor
Dependents: HeartRate HeartRate proj final_project_ee119 ... more
Revision 3:a2effad05c99, committed 2017-05-04
- Comitter:
- j3
- Date:
- Thu May 04 23:44:48 2017 +0000
- Parent:
- 2:0db1f3bec727
- Child:
- 4:d1b50bd4065a
- Commit message:
- Added reading fifo mbr fx. Library requires algorithm to get heart rate or SpO2 readings.
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 Mon May 01 21:00:34 2017 +0000
+++ b/MAX30101.cpp Thu May 04 23:44:48 2017 +0000
@@ -259,6 +259,60 @@
}
+//*****************************************************************************
+int32_t MAX30101::readFIFO(uint8_t 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 read pointer
+ result = readRegister(FIFO_ReadPointer, m_fifoReadPtr);
+ 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);
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
+
//*****************************************************************************
int32_t MAX30101::writeRegister(Registers_e reg, uint8_t value)
{
--- a/MAX30101.h Mon May 01 21:00:34 2017 +0000
+++ b/MAX30101.h Thu May 04 23:44:48 2017 +0000
@@ -68,6 +68,10 @@
static const uint8_t I2C_W_ADRS = 0xAE;
///8-bit read address
static const uint8_t I2C_R_ADRS = 0xAF;
+ ///Max # Bytes in FIFO
+ static const uint16_t MAX_FIFO_BYTES = 288;
+ ///# of bytes per LED channel
+ static const uint8_t BYTES_PER_CH = 3;
///MAX30101 Register Map
enum Registers_e
@@ -97,6 +101,14 @@
PartID = 0xFF
};
+ ///MAX30101 Operational Modes
+ enum OpModes_e
+ {
+ HeartRateMode = 2,
+ SpO2Mode = 3,
+ MultiLedMode = 7
+ };
+
///Interrupt Status/Enable BitField
union InterruptBitField_u
{
@@ -323,6 +335,17 @@
* @return 0 on success, non 0 otherwise
*/
int32_t getProxIntThreshold(uint8_t &data);
+
+ /**
+ * @brief Attempts to read numBytes of data from FIFO
+ *
+ * @param numLeds - Number of LED channels used; 0 < numLeds < 4
+ * @param data - pointer to buffer for holding read data
+ * @param[out] readBytes - number of bytes read from fifo
+ *
+ * @return 0 on success, non 0 otherwise
+ */
+ int32_t readFIFO(uint8_t numLeds, uint8_t *data, uint16_t &readBytes);
protected:
@@ -345,6 +368,8 @@
private:
I2C m_i2cBus;
+ uint8_t m_fifoReadPtr, m_fifoWritePtr, m_fifoNumBytes;
+
};