Max30101 pulse oximeter library
Revision 6:30640433472a, committed 2017-11-22
- Comitter:
- jurica238814
- Date:
- Wed Nov 22 15:49:02 2017 +0000
- Parent:
- 5:2927db6219fc
- Commit message:
- I2C reference added (had conflicts with external i2c). Some methods added.
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 Wed Nov 22 14:43:43 2017 +0000
+++ b/max30101.cpp Wed Nov 22 15:49:02 2017 +0000
@@ -10,7 +10,7 @@
#include "max30101.h"
#include "max30101_regs.h"
-MAX30101::MAX30101(I2C i2c, PinName enablePin): i2c(i2c), _enable(enablePin){
+MAX30101::MAX30101(I2C *i2c, PinName enablePin): i2c(i2c), _enable(enablePin){
_enable = 0;
i2cAddress = MAX_I2C_ADDRESS;
}
@@ -28,7 +28,7 @@
dataToSend[0] = regAddress;
dataToSend[1] = *data;
- success = i2c.write(i2cAddress & 0xFE, dataToSend, len + 1); // R/W bit is set low for a write command
+ success = i2c->write(i2cAddress & 0xFE, dataToSend, len + 1); // R/W bit is set low for a write command
return success;
}
@@ -36,8 +36,8 @@
uint8_t success; /* 0 on success (ack), non-0 on failure (nack) */
char regAddr = regAddress;
- i2c.write(i2cAddress & 0xFE, ®Addr, 1); // R/W bit is set low for a write command
- success = i2c.read(i2cAddress | 0x01, dataBuffer, len); // R/W bit is set high for a read command
+ i2c->write(i2cAddress & 0xFE, ®Addr, 1); // R/W bit is set low for a write command
+ success = i2c->read(i2cAddress | 0x01, dataBuffer, len); // R/W bit is set high for a read command
return success;
}
@@ -110,3 +110,24 @@
success = writeToReg((char)SP02_CONFIG_REG, &data, 1);
return success;
}
+
+void MAX30101::setupRedLED(uint8_t pulseInterval){
+ char data = 0x00;
+ data = 0x02;
+ writeToReg((char)MODE_CONFIG_REG, &data, 1);
+
+ data = (char)pulseInterval;
+ writeToReg((char)LED1_PA, &data, 1);
+
+ data = 0b00011111;
+ configFifo(&data);
+
+ data = 0b00000011;
+ writeToReg((char)SP02_CONFIG_REG, &data, 1);
+}
+
+void MAX30101::turnGreenLED(){
+ /*
+ TODO
+ */
+}
--- a/max30101.h Wed Nov 22 14:43:43 2017 +0000
+++ b/max30101.h Wed Nov 22 15:49:02 2017 +0000
@@ -15,7 +15,7 @@
class MAX30101{
public:
- MAX30101(I2C i2c, PinName enablePin);
+ MAX30101(I2C *i2c, PinName enablePin);
char readID();
inline void enable(){_enable = 1;};
inline void disable(){_enable = 0;};
@@ -27,9 +27,11 @@
uint32_t readFifoSample(char readAddres);
uint8_t readFifo(int *data, int numOfSamples);
uint8_t setSamplesPerSecond(SamplesPerSecond samplesPerSecond);
+ void setupRedLED(uint8_t pulseInterval);
+ void turnGreenLED();
private:
- I2C i2c;
+ I2C *i2c;
uint8_t i2cAddress;
DigitalOut _enable;
};