Skip to content

Commit 319fdab

Browse files
author
Elias Santistevan
committed
Adds funcationality for the second mode added to the maximfast algorithm in firmware 10.1
1 parent 21b346b commit 319fdab

File tree

6 files changed

+180
-103
lines changed

6 files changed

+180
-103
lines changed

Examples/Example1_readBPM/Example1_readBPM.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void setup(){
6464
Serial.println("Could not communicate with the sensor!!!");
6565

6666
Serial.println("Configuring Sensor....");
67-
int error = bioHub.configBpm(); // Configuring just the BPM settings.
67+
int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings.
6868
if(!error){
6969
Serial.println("Sensor configured.");
7070
}

Examples/Example2_adjustLEDvalues/Example2_adjustLEDvalues.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
/*
2+
This example displays a more manual method of adjusting the way in which the
3+
MAX30101 gathers data. Specifically we'll look at how to modify the pulse
4+
length of the LEDs within the MAX30101 which impacts the number of samples
5+
that can be gathered, so we'll adjust this value as well. In addition we
6+
gather additional data from the bioData type: LED samples. This data gives
7+
the number of samples gathered by the MAX30101 for both the red and IR LEDs.
28
A summary of the hardware connections are as follows:
39
SDA -> SDA
410
SCL -> SCL
@@ -112,7 +118,7 @@ void setup(){
112118
Serial.println(sampleVal);
113119

114120
// Some time to read your settings.
115-
delay(2000);
121+
delay(4000);
116122

117123
}
118124

Examples/Example3_modifyAGCalgo/Example3_modifyAGCalgo.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void setup(){
105105
Serial.println(sampVal);
106106

107107
Serial.println("Configuing Sensor.");
108-
error = configBpm();
108+
error = configBpm(MODE_ONE);
109109
if (error){
110110
Serial.println("Could not configure the sensor.");
111111
}

keywords.txt

+5
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ eraseFlash KEYWORD2
5252
readBootloaderVers KEYWORD2
5353
readSensorHubVersion KEYWORD2
5454
readAlgorithmVersion KEYWORD2
55+
Literals =================================
56+
MODE_ONE LITERAL1
57+
MODE_TWO LITERAL1
58+
ENABLE LITERAL1
59+
DISABLE LITERAL1

src/SparkFun_Bio_Sensor_Hub_Library.cpp

+153-82
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ uint8_t SparkFun_Bio_Sensor_Hub::readSensorHubStatus(){
9393
// This function sets very basic settings to get sensor and biometric data.
9494
// The biometric data includes data about heartrate, the confidence
9595
// level, SpO2 levels, and whether the sensor has detected a finger or not.
96-
uint8_t SparkFun_Bio_Sensor_Hub::configBpm(){
96+
uint8_t SparkFun_Bio_Sensor_Hub::configBpm(uint8_t mode){
9797

9898
uint8_t statusChauf = 0;
99+
if (mode == MODE_ONE || mode == MODE_TWO){}
100+
else return INCORR_PARAM;
99101

100102
statusChauf = setOutputMode(ALGO_DATA); // Just the data
101103
if( statusChauf != SUCCESS )
@@ -112,10 +114,12 @@ uint8_t SparkFun_Bio_Sensor_Hub::configBpm(){
112114
statusChauf = max30101Control(ENABLE);
113115
if( statusChauf != SUCCESS )
114116
return statusChauf;
115-
116-
statusChauf = maximFastAlgoControl(MODE_ONE);
117+
118+
statusChauf = maximFastAlgoControl(mode);
117119
if( statusChauf != SUCCESS )
118120
return statusChauf;
121+
122+
_userSelectedMode = mode;
119123

120124
delay(1000);
121125
return SUCCESS;
@@ -144,37 +148,7 @@ uint8_t SparkFun_Bio_Sensor_Hub::configSensor(){
144148
statusChauf = maximFastAlgoControl(MODE_ONE); //Enable algorithm
145149
if( statusChauf != SUCCESS )
146150
return statusChauf;
147-
148-
delay(1000);
149-
return SUCCESS;
150-
151-
}
152151

153-
// This function sets very basic settings to get sensor and biometric data.
154-
// Sensor data includes 24 bit LED values for the two LED channels: Red and IR.
155-
// The biometric data includes data about heartrate, the confidence
156-
// level, SpO2 levels, and whether the sensor has detected a finger or not.
157-
// Of note, the number of samples is set to one.
158-
uint8_t SparkFun_Bio_Sensor_Hub::configSensorBpm(){
159-
160-
uint8_t statusChauf; // Our status chauffeur
161-
162-
statusChauf = setOutputMode(SENSOR_AND_ALGORITHM); // Data and sensor data
163-
if( statusChauf != SUCCESS )
164-
return statusChauf;
165-
166-
statusChauf = setFifoThreshold(0x01); // One sample before interrupt is fired to the MAX32664
167-
if( statusChauf != SUCCESS )
168-
return statusChauf;
169-
170-
statusChauf = max30101Control(ENABLE); //Enable Sensor.
171-
if( statusChauf != SUCCESS )
172-
return statusChauf;
173-
174-
statusChauf = maximFastAlgoControl(MODE_ONE); //Enable algorithm
175-
if( statusChauf != SUCCESS )
176-
return statusChauf;
177-
178152
delay(1000);
179153
return SUCCESS;
180154

@@ -184,12 +158,12 @@ uint8_t SparkFun_Bio_Sensor_Hub::configSensorBpm(){
184158
// Sensor data includes 24 bit LED values for the two LED channels: Red and IR.
185159
// The biometric data includes data about heartrate, the confidence
186160
// level, SpO2 levels, and whether the sensor has detected a finger or not.
187-
// In addition mode two also gives data on the R value of the SPO2
188-
// measurements, and and extended finger status value.
189161
// Of note, the number of samples is set to one.
190-
uint8_t SparkFun_Bio_Sensor_Hub::configSensorBpmTwo(){
162+
uint8_t SparkFun_Bio_Sensor_Hub::configSensorBpm(uint8_t mode){
191163

192164
uint8_t statusChauf; // Our status chauffeur
165+
if (mode == MODE_ONE || mode == MODE_TWO){}
166+
else return INCORR_PARAM;
193167

194168
statusChauf = setOutputMode(SENSOR_AND_ALGORITHM); // Data and sensor data
195169
if( statusChauf != SUCCESS )
@@ -203,10 +177,12 @@ uint8_t SparkFun_Bio_Sensor_Hub::configSensorBpmTwo(){
203177
if( statusChauf != SUCCESS )
204178
return statusChauf;
205179

206-
statusChauf = maximFastAlgoControl(MODE_TWO); //Enable algorithm
180+
statusChauf = maximFastAlgoControl(mode); //Enable algorithm
207181
if( statusChauf != SUCCESS )
208182
return statusChauf;
209183

184+
_userSelectedMode = mode;
185+
210186
delay(1000);
211187
return SUCCESS;
212188

@@ -232,26 +208,64 @@ bioData SparkFun_Bio_Sensor_Hub::readBpm(){
232208
}
233209

234210
numSamplesOutFifo();
211+
212+
if (_userSelectedMode = MODE_ONE) {
213+
214+
readFillArray(READ_DATA_OUTPUT, READ_DATA, MAXFAST_ARRAY_SIZE, bpmArr);
215+
216+
// Heart Rate formatting
217+
libBpm.heartRate = (uint16_t(bpmArr[0]) << 8);
218+
libBpm.heartRate |= (bpmArr[1]);
219+
libBpm.heartRate /= 10;
220+
221+
// Confidence formatting
222+
libBpm.confidence = bpmArr[2];
223+
224+
//Blood oxygen level formatting
225+
libBpm.oxygen = uint16_t(bpmArr[3]) << 8;
226+
libBpm.oxygen |= bpmArr[4];
227+
libBpm.oxygen /= 10;
228+
229+
//"Machine State" - has a finger been detected?
230+
libBpm.status = bpmArr[5];
231+
232+
return libBpm;
233+
}
234+
235+
else if (_userSelectedMode = MODE_TWO) {
235236

236-
readFillArray(READ_DATA_OUTPUT, READ_DATA, WHRM_ARRAY_SIZE, bpmArr);
237+
readFillArray(READ_DATA_OUTPUT, READ_DATA,\
238+
MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA, bpmArrTwo);
237239

238-
// Heart Rate formatting
239-
libBpm.heartRate = (uint16_t(bpmArr[0]) << 8);
240-
libBpm.heartRate |= (bpmArr[1]);
241-
libBpm.heartRate /= 10;
240+
// Heart Rate formatting
241+
libBpm.heartRate = (uint16_t(bpmArrTwo[0]) << 8);
242+
libBpm.heartRate |= (bpmArrTwo[1]);
243+
libBpm.heartRate /= 10;
242244

243-
// Confidence formatting
244-
libBpm.confidence = bpmArr[2];
245+
// Confidence formatting
246+
libBpm.confidence = bpmArrTwo[2];
245247

246-
//Blood oxygen level formatting
247-
libBpm.oxygen = uint16_t(bpmArr[3]) << 8;
248-
libBpm.oxygen |= bpmArr[4];
249-
libBpm.oxygen /= 10;
248+
//Blood oxygen level formatting
249+
libBpm.oxygen = uint16_t(bpmArrTwo[3]) << 8;
250+
libBpm.oxygen |= bpmArrTwo[4];
251+
libBpm.oxygen /= 10;
250252

251-
//"Machine State" - has a finger been detected?
252-
libBpm.status = bpmArr[5];
253+
//"Machine State" - has a finger been detected?
254+
libBpm.status = bpmArrTwo[5];
253255

254-
return libBpm;
256+
//Sp02 r Value formatting
257+
libBpm.rValue = uint16_t(bpmArrTwo[6]) << 8;
258+
libBpm.rValue |= bpmArrTwo[7];
259+
libBpm.rValue /= 10;
260+
261+
//Extended Machine State formatting
262+
libBpm.extStatus = bpmArrTwo[8];
263+
264+
// There are two additional bytes of data that were requested but that
265+
// have not been implemented in firmware 10.1 so will not be saved to
266+
// user's data.
267+
return libBpm;
268+
}
255269

256270
}
257271

@@ -286,39 +300,96 @@ bioData SparkFun_Bio_Sensor_Hub::readSensor(){
286300
bioData SparkFun_Bio_Sensor_Hub::readSensorBpm(){
287301

288302
bioData libLedBpm;
289-
readFillArray(READ_DATA_OUTPUT, READ_DATA, WHRM_ARRAY_SIZE + MAX30101_LED_ARRAY, bpmSenArr);
290303

291-
// Value of LED one....
292-
libLedBpm.irLed = uint32_t(bpmSenArr[0]) << 16;
293-
libLedBpm.irLed |= uint32_t(bpmSenArr[1]) << 8;
294-
libLedBpm.irLed |= bpmSenArr[2];
304+
if (_userSelectedMode == MODE_ONE){
305+
306+
readFillArray(READ_DATA_OUTPUT, READ_DATA, MAXFAST_ARRAY_SIZE + MAX30101_LED_ARRAY, bpmSenArr);
307+
308+
// Value of LED one....
309+
libLedBpm.irLed = uint32_t(bpmSenArr[0]) << 16;
310+
libLedBpm.irLed |= uint32_t(bpmSenArr[1]) << 8;
311+
libLedBpm.irLed |= bpmSenArr[2];
312+
313+
// Value of LED two...
314+
libLedBpm.redLed = uint32_t(bpmSenArr[3]) << 16;
315+
libLedBpm.redLed |= uint32_t(bpmSenArr[4]) << 8;
316+
libLedBpm.redLed |= bpmSenArr[5];
317+
318+
// -- What happened here? -- There are two uint32_t values that are given by
319+
// the sensor for LEDs that do not exists on the MAX30101. So we have to
320+
// request those empty values because they occupy the buffer:
321+
// bpmSenArr[6-11].
322+
323+
// Heart rate formatting
324+
libLedBpm.heartRate = (uint16_t(bpmSenArr[12]) << 8);
325+
libLedBpm.heartRate |= (bpmSenArr[13]);
326+
libLedBpm.heartRate /= 10;
327+
328+
// Confidence formatting
329+
libLedBpm.confidence = bpmSenArr[14];
330+
331+
//Blood oxygen level formatting
332+
libLedBpm.oxygen = uint16_t(bpmSenArr[15]) << 8;
333+
libLedBpm.oxygen |= bpmSenArr[16];
334+
libLedBpm.oxygen /= 10;
335+
336+
//"Machine State" - has a finger been detected?
337+
libLedBpm.status = bpmSenArr[17];
338+
return libLedBpm;
339+
}
340+
341+
else if (_userSelectedMode == MODE_TWO){
342+
343+
readFillArray(READ_DATA_OUTPUT, READ_DATA,\
344+
MAXFAST_ARRAY_SIZE + MAX30101_LED_ARRAY + MAXFAST_EXTENDED_DATA, bpmSenArrTwo);
345+
346+
// Value of LED one....
347+
libLedBpm.irLed = uint32_t(bpmSenArr[0]) << 16;
348+
libLedBpm.irLed |= uint32_t(bpmSenArr[1]) << 8;
349+
libLedBpm.irLed |= bpmSenArr[2];
350+
351+
// Value of LED two...
352+
libLedBpm.redLed = uint32_t(bpmSenArr[3]) << 16;
353+
libLedBpm.redLed |= uint32_t(bpmSenArr[4]) << 8;
354+
libLedBpm.redLed |= bpmSenArr[5];
355+
356+
// -- What happened here? -- There are two uint32_t values that are given by
357+
// the sensor for LEDs that do not exists on the MAX30101. So we have to
358+
// request those empty values because they occupy the buffer:
359+
// bpmSenArr[6-11].
360+
361+
// Heart rate formatting
362+
libLedBpm.heartRate = (uint16_t(bpmSenArr[12]) << 8);
363+
libLedBpm.heartRate |= (bpmSenArr[13]);
364+
libLedBpm.heartRate /= 10;
365+
366+
// Confidence formatting
367+
libLedBpm.confidence = bpmSenArr[14];
368+
369+
//Blood oxygen level formatting
370+
libLedBpm.oxygen = uint16_t(bpmSenArr[15]) << 8;
371+
libLedBpm.oxygen |= bpmSenArr[16];
372+
libLedBpm.oxygen /= 10;
373+
374+
//"Machine State" - has a finger been detected?
375+
libLedBpm.status = bpmSenArr[17];
376+
377+
//Sp02 r Value formatting
378+
libLedBpm.rValue = uint16_t(bpmArrTwo[18]) << 8;
379+
libLedBpm.rValue |= bpmArrTwo[19];
380+
libLedBpm.rValue /= 10;
381+
382+
//Extended Machine State formatting
383+
libLedBpm.extStatus = bpmArrTwo[20];
384+
385+
// There are two additional bytes of data that were requested but that
386+
// have not been implemented in firmware 10.1 so will not be saved to
387+
// user's data.
388+
//
389+
return libLedBpm;
390+
391+
}
295392

296-
// Value of LED two...
297-
libLedBpm.redLed = uint32_t(bpmSenArr[3]) << 16;
298-
libLedBpm.redLed |= uint32_t(bpmSenArr[4]) << 8;
299-
libLedBpm.redLed |= bpmSenArr[5];
300-
301-
// -- What happened here? -- There are two uint32_t values that are given by
302-
// the sensor for LEDs that do not exists on the MAX30101. So we have to
303-
// request those empty values because they occupy the buffer:
304-
// bpmSenArr[6-11].
305-
306-
// Heart rate formatting
307-
libLedBpm.heartRate = (uint16_t(bpmSenArr[12]) << 8);
308-
libLedBpm.heartRate |= (bpmSenArr[13]);
309-
libLedBpm.heartRate /= 10;
310-
311-
// Confidence formatting
312-
libLedBpm.confidence = bpmSenArr[14];
313-
314-
//Blood oxygen level formatting
315-
libLedBpm.oxygen = uint16_t(bpmSenArr[15]) << 8;
316-
libLedBpm.oxygen |= bpmSenArr[16];
317-
libLedBpm.oxygen /= 10;
318-
319-
//"Machine State" - has a finger been detected?
320-
libLedBpm.status = bpmSenArr[17];
321-
return libLedBpm;
322393

323394
}
324395
// This function modifies the pulse width of the MAX30101 LEDs. All of the LEDs

0 commit comments

Comments
 (0)