Skip to content

Commit 86b1c84

Browse files
committed
Adds comments, fixes some incorrect arguements to functions
1 parent 26f6969 commit 86b1c84

File tree

3 files changed

+95
-81
lines changed

3 files changed

+95
-81
lines changed
955 KB
Binary file not shown.

src/SparkFun_Bio_Sensor_Hub_Library.cpp

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,11 @@ version SparkFun_Bio_Sensor_Hub::readAlgorithmVersion(){
11341134
return libAlgoVers;
11351135

11361136
}
1137+
11371138
// ------------------Function Below for MAX32664 Version D (Blood Pressure) ----
1139+
1140+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1141+
// Write Byte: BPT_MEDICATION (0x00)
11381142
uint8_t SparkFun_Bio_Sensor_Hub::isPatientBPMedication(uint8_t medication){
11391143

11401144
if (medication != 0x01 || medication != 0x00)
@@ -1145,13 +1149,17 @@ uint8_t SparkFun_Bio_Sensor_Hub::isPatientBPMedication(uint8_t medication){
11451149

11461150
}
11471151

1152+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1153+
// Write Byte: BPT_MEDICATION (0x00)
11481154
uint8_t SparkFun_Bio_Sensor_Hub::isPatientBPMedication(){
11491155

11501156
uint8_t medication = readByte(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_MEDICATION);
11511157
return medication;
11521158

11531159
}
11541160

1161+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1162+
// Write Byte: SYSTOLIC_VALUE (0x01)
11551163
uint8_t SparkFun_Bio_Sensor_Hub::writeSystolicVals(uint8_t sysVal1, uint8_t sysVal2, uint8_t sysVal3){
11561164

11571165
const size_t numSysVals = 3;
@@ -1162,9 +1170,18 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeSystolicVals(uint8_t sysVal1, uint8_t sysV
11621170

11631171
}
11641172

1165-
uint8_t SparkFun_Bio_Sensor_Hub::readSystolicVals(){
1173+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1174+
// Write Byte: SYSTOLIC_VALUE (0x01)
1175+
uint8_t SparkFun_Bio_Sensor_Hub::readSystolicVals(uint8_t userArray[]){
1176+
1177+
const size_t numSysVals = 3;
1178+
uint8_t status = readMultipleBytes(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, SYSTOLIC_VALUE, numSysVals, userArray);
1179+
1180+
return status;
11661181
}
11671182

1183+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1184+
// Write Byte: DIASTOLIC_VALUE (0x02)
11681185
uint8_t SparkFun_Bio_Sensor_Hub::writeDiastolicVals(uint8_t diasVal1, uint8_t diasVal2, uint8_t diasVal3){
11691186

11701187
const size_t numDiasVals = 3;
@@ -1175,14 +1192,18 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeDiastolicVals(uint8_t diasVal1, uint8_t di
11751192

11761193
}
11771194

1178-
uint8_t SparkFun_Bio_Sensor_Hub::readDiastolicVals(uint8_t userProvidedArray[]){
1195+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1196+
// Write Byte: DIASTOLIC_VALUE (0x02)
1197+
uint8_t SparkFun_Bio_Sensor_Hub::readDiastolicVals(uint8_t userArray[]){
11791198

11801199
const size_t numDiasVals = 3;
1181-
uint8_t status = readMultipleBytes(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, DIASTOLIC_VALUE, numDiasVals, userProvidedArray);
1200+
uint8_t status = readMultipleBytes(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, DIASTOLIC_VALUE, numDiasVals, userArray);
11821201
return status;
11831202

11841203
}
11851204

1205+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1206+
// Write Byte: BPT_CALIB_DATA (0x03)
11861207
uint8_t SparkFun_Bio_Sensor_Hub::writeBPTAlgoData(uint8_t bptCalibData[]){
11871208

11881209
const size_t numCalibVals = 824;
@@ -1191,39 +1212,55 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeBPTAlgoData(uint8_t bptCalibData[]){
11911212

11921213
}
11931214

1194-
uint8_t SparkFun_Bio_Sensor_Hub::readBPTAlgoData(){
1215+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1216+
// Write Byte: BPT_CALIB_DATA (0x03)
1217+
uint8_t SparkFun_Bio_Sensor_Hub::readBPTAlgoData(uint8_t userArray[]){
1218+
1219+
const size_t numCalibVals = 824;
1220+
uint8_t status = readMultipleBytes(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_CALIB_DATA, numCalibVals, userArray);
1221+
return status;
1222+
11951223
}
11961224

1225+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1226+
// Write Byte: PATIENT_RESTING (0x05)
11971227
uint8_t SparkFun_Bio_Sensor_Hub::isPatientResting(uint8_t resting){ //
11981228

11991229
if (resting != 0x00 || resting != 0x01)
12001230
return INCORR_PARAM;
12011231

1202-
uint8_t status = writeByte(CHANGE_ALGORITHM_CONFIG, BPT_CALIB_DATA, PATIENT_RESTING, resting);
1232+
uint8_t status = writeByte(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, PATIENT_RESTING, resting);
12031233
return status;
12041234

12051235
}
12061236

1237+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1238+
// Write Byte: PATIENT_RESTING (0x05)
12071239
uint8_t SparkFun_Bio_Sensor_Hub::isPatientResting(){
12081240

1209-
uint8_t resting = writeByte(CHANGE_ALGORITHM_CONFIG, BPT_CALIB_DATA, PATIENT_RESTING);
1241+
uint8_t resting = writeByte(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, PATIENT_RESTING);
12101242
return resting;
12111243

12121244
}
12131245

1246+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1247+
// Write Byte: AGC_SP02_COEFS (0x0B)
12141248
uint8_t SparkFun_Bio_Sensor_Hub::writeSP02AlgoCoef(int32_t intA, int32_t intB, int32_t intC){
12151249

12161250

12171251
const size_t numCoefVals = 3;
12181252
int32_t coefVals[numCoefVals] = {intA, intB, intC};
1219-
uint8_t status = writeLongBytes(CHANGE_ALGORITHM_CONFIG, BPT_CALIB_DATA, AGC_SP02_COEFS, coefVals, numCoefVals);
1253+
uint8_t status = writeLongBytes(CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, AGC_SP02_COEFS, coefVals, numCoefVals);
12201254
return status;
12211255

12221256
}
12231257

1224-
uint8_t SparkFun_Bio_Sensor_Hub::readSP02AlgoCoef(){ // Have the user provide their own array here and pass the pointer to it
1258+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
1259+
// Write Byte: AGC_SP02_COEFS (0x0B)
1260+
uint8_t SparkFun_Bio_Sensor_Hub::readSP02AlgoCoef(int32_t userArray[]){ // Have the user provide their own array here and pass the pointer to it
12251261

1226-
uint8_t status = readLongByte(CHANGE_ALGORITHM_CONFIG, BPT_CALIB_DATA, AGC_SP02_COEFS);
1262+
const size_t numOfReads = 3;
1263+
uint8_t status = readMultipleBytes( CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, AGC_SP02_COEFS, numOfReads, userArray);
12271264
return status;
12281265

12291266
}
@@ -1425,7 +1462,7 @@ uint8_t SparkFun_Bio_Sensor_Hub::readByte(uint8_t _familyByte, uint8_t _indexBy
14251462
_i2cPort->endTransmission();
14261463
delay(CMD_DELAY);
14271464

1428-
_i2cPort->requestFrom(_address, sizeof(returnByte) + sizeof(statusByte));
1465+
_i2cPort->requestFrom(_address, static_cast<uint8_t>(sizeof(returnByte) + sizeof(statusByte)));
14291466
statusByte = _i2cPort->read();
14301467
if( statusByte )// SUCCESS (0x00)
14311468
return statusByte; // Return the error, see: READ_STATUS_BYTE_VALUE
@@ -1494,40 +1531,6 @@ uint16_t SparkFun_Bio_Sensor_Hub::readIntByte(uint8_t _familyByte, uint8_t _inde
14941531

14951532
}
14961533

1497-
// This function handles all read commands or stated another way, all information
1498-
// requests. It starts a request by writing the family byte, an index byte, and
1499-
// a write byte and then then delays 60 microseconds, during which the MAX32664
1500-
// retrieves the requested information. An I-squared-C request is then issued,
1501-
// and the information is read. This differs from the above read commands in
1502-
// that it returns three, four byte (uint32_t) integer instead of a single byte.
1503-
uint32_t SparkFun_Bio_Sensor_Hub::readLongByte(uint8_t _familyByte, uint8_t _indexByte,\
1504-
uint8_t _writeByte)
1505-
{
1506-
1507-
uint32_t returnByte = 0;
1508-
uint8_t statusByte;
1509-
1510-
_i2cPort->beginTransmission(_address);
1511-
_i2cPort->write(_familyByte);
1512-
_i2cPort->write(_indexByte);
1513-
_i2cPort->write(_writeByte);
1514-
_i2cPort->endTransmission();
1515-
delay(CMD_DELAY);
1516-
1517-
_i2cPort->requestFrom(_address, (sizeof(returnByte) * 3) + sizeof(statusByte) );
1518-
statusByte = _i2cPort->read();
1519-
if( statusByte ) // Pass through if SUCCESS (0x00).
1520-
return (uint32_t)statusByte; // Return the error, see: READ_STATUS_BYTE_VALUE
1521-
1522-
for(uint8_t i = 0; i < (sizeof(returnByte) * 3); i++){ // Reading three long bytes
1523-
returnByte |= (_i2cPort->read() << 24);
1524-
returnByte |= (_i2cPort->read() << 16);
1525-
returnByte |= (_i2cPort->read() << 8);
1526-
returnByte |= _i2cPort->read();
1527-
}
1528-
return returnByte;
1529-
1530-
}
15311534
// This function handles all read commands or stated another way, all information
15321535
// requests. It starts a request by writing the family byte, an index byte, and
15331536
// a write byte and then then delays 60 microseconds, during which the MAX32664
@@ -1550,18 +1553,17 @@ uint8_t SparkFun_Bio_Sensor_Hub::readMultipleBytes(uint8_t _familyByte, uint8_t
15501553

15511554
_i2cPort->requestFrom(_address, static_cast<uint8_t>(sizeof(int32_t) * _numOfReads + sizeof(statusByte)));
15521555
statusByte = _i2cPort->read();
1553-
if( statusByte ){ // Pass through if SUCCESS (0x00).
1556+
if( statusByte ) // Pass through if SUCCESS (0x00).
1557+
return statusByte;
1558+
else {
15541559
for(size_t i = 0; i < (sizeof(int32_t) * _numOfReads); i++){
1555-
userArray[i] = 0;
1556-
userArray[i] = 0;
1557-
userArray[i] = 0;
1558-
userArray[i] = 0;
1560+
userArray[i] = _i2cPort->read() << 24;
1561+
userArray[i] |= _i2cPort->read() << 16;
1562+
userArray[i] |= _i2cPort->read() << 8;
1563+
userArray[i] |= _i2cPort->read();
15591564
}
15601565
return statusByte;
15611566
}
1562-
1563-
else
1564-
return statusByte;
15651567
}
15661568

15671569
// This function handles all read commands or stated another way, all information
@@ -1584,18 +1586,14 @@ uint8_t SparkFun_Bio_Sensor_Hub::readMultipleBytes(uint8_t _familyByte, uint8_t
15841586
_i2cPort->endTransmission();
15851587
delay(CMD_DELAY);
15861588

1587-
_i2cPort->requestFrom(_address, static_cast<uint8_t>(sizeof(int32_t) * _numOfReads + sizeof(statusByte)));
1589+
_i2cPort->requestFrom(_address, static_cast<uint8_t>(_numOfReads + sizeof(statusByte)));
15881590
statusByte = _i2cPort->read();
1589-
if( statusByte ){ // Pass through if SUCCESS (0x00).
1590-
for(size_t i = 0; i < (sizeof(uint8_t) * _numOfReads); i++){
1591-
userArray[i] = 0;
1592-
userArray[i] = 0;
1593-
userArray[i] = 0;
1594-
userArray[i] = 0;
1591+
if( statusByte ) // Pass through if SUCCESS (0x00).
1592+
return statusByte;
1593+
else {
1594+
for(size_t i = 0; i < _numOfReads; i++){
1595+
userArray[i] = _i2cPort->read();
15951596
}
15961597
return statusByte;
15971598
}
1598-
1599-
else
1600-
return statusByte;
16011599
}

src/SparkFun_Bio_Sensor_Hub_Library.h

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ class SparkFun_Bio_Sensor_Hub
309309
// Variables ------------
310310
uint8_t bpmArr[MAXFAST_ARRAY_SIZE] {};
311311
uint8_t bpmArrTwo[MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA] {};
312-
uint8_t senArr[MAX30101_LED_ARRAY];
313-
uint8_t bpmSenArr[MAXFAST_ARRAY_SIZE + MAX30101_LED_ARRAY];
314-
uint8_t bpmSenArrTwo[MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA + MAX30101_LED_ARRAY];
312+
uint8_t senArr[MAX30101_LED_ARRAY] {};
313+
uint8_t bpmSenArr[MAXFAST_ARRAY_SIZE + MAX30101_LED_ARRAY] {};
314+
uint8_t bpmSenArrTwo[MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA + MAX30101_LED_ARRAY] {};
315315

316316
// Constructor ----------
317317
SparkFun_Bio_Sensor_Hub(uint16_t, uint16_t, uint8_t address = 0x55);
@@ -623,37 +623,61 @@ class SparkFun_Bio_Sensor_Hub
623623
// Family Byte: IDENTITY (0xFF), Index Byte: READ_ALGO_VERS (0x07)
624624
version readAlgorithmVersion();
625625

626+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
627+
// Write Byte: BPT_MEDICATION (0x00)
626628
uint8_t isPatientBPMedication(uint8_t);
627629

630+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
631+
// Write Byte: BPT_MEDICATION (0x00)
628632
uint8_t isPatientBPMedication();
629633

634+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
635+
// Write Byte: DIASTOLIC_VALUE (0x02)
630636
uint8_t writeDiastolicVals(uint8_t, uint8_t, uint8_t);
631637

632-
uint8_t writeSystolicVals(uint8_t, uint8_t, uint8_t);
638+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
639+
// Write Byte: DIASTOLIC_VALUE (0x02)
640+
uint8_t readDiastolicVals(uint8_t userArray[]);
633641

634-
uint8_t readSystolicVals();
642+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
643+
// Write Byte: SYSTOLIC_VALUE (0x01)
644+
uint8_t writeSystolicVals(uint8_t, uint8_t, uint8_t);
635645

636-
uint8_t readDiastolicVals(uint8_t userProvideArray[]);
646+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
647+
// Write Byte: SYSTOLIC_VALUE (0x01)
648+
uint8_t readSystolicVals(uint8_t userArray[]);
637649

638-
uint8_t writeBPTAlgoData(uint8_t*);
650+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
651+
// Write Byte: BPT_CALIB_DATA (0x03)
652+
uint8_t writeBPTAlgoData(uint8_t bptCalibData[]);
639653

640-
uint8_t readBPTAlgoData();
654+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
655+
// Write Byte: BPT_CALIB_DATA (0x03)
656+
uint8_t readBPTAlgoData(uint8_t userArray[]);
641657

658+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
659+
// Write Byte: PATIENT_RESTING (0x05)
642660
uint8_t isPatientResting(uint8_t);
643661

644-
uint8_t isPatientResting();
662+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
663+
// Write Byte: PATIENT_RESTING (0x05)
664+
uint8_t isPatientResting();
645665

666+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
667+
// Write Byte: AGC_SP02_COEFS (0x0B)
646668
uint8_t writeSP02AlgoCoef(int32_t, int32_t, int32_t);
647669

648-
uint8_t readSP02AlgoCoef();
670+
// Family Byte: CHANGE_ALGORITHM_CONFIG (0x50), Index Byte: BPT_CONFIG (0x04),
671+
// Write Byte: AGC_SP02_COEFS (0x0B)
672+
uint8_t readSP02AlgoCoef(int32_t userArray[]);
649673

650674
private:
651675

652676
// Variables -----------
653677
uint8_t _resetPin;
654678
uint8_t _mfioPin;
655679
uint8_t _address;
656-
uint32_t _writeCoefArr[3];
680+
uint32_t _writeCoefArr[3] {};
657681
uint8_t _userSelectedMode;
658682
uint8_t _sampleRate = 100;
659683

@@ -719,14 +743,6 @@ class SparkFun_Bio_Sensor_Hub
719743
// that it returns a 16 bit integer instead of 8.
720744
uint16_t readIntByte(uint8_t, uint8_t, uint8_t);
721745

722-
// This function handles all read commands or stated another way, all information
723-
// requests. It starts a request by writing the family byte, an index byte, and
724-
// a write byte and then then delays 60 microseconds, during which the MAX32664
725-
// retrieves the requested information. An I-squared-C request is then issued,
726-
// and the information is read. This differs from the above read commands in
727-
// that it returns a 4 byte (uint32_t) integer instead of 8.
728-
uint32_t readLongByte(uint8_t, uint8_t, uint8_t);
729-
730746
// This function handles all read commands or stated another way, all information
731747
// requests. It starts a request by writing the family byte, an index byte, and
732748
// a write byte and then then delays 60 microseconds, during which the MAX32664

0 commit comments

Comments
 (0)