@@ -608,10 +608,11 @@ uint8_t SparkFun_Bio_Sensor_Hub::getMcuType() {
608
608
int32_t SparkFun_Bio_Sensor_Hub::getBootloaderInf () {
609
609
610
610
int32_t bootVers = 0 ;
611
- int32_t revNum[4 ] = {0 };
612
- readMultipleBytes (BOOTLOADER_INFO, BOOTLOADER_VERS, 0x00 , 4 , revNum);
611
+ const size_t sizeOfRev = 4 ;
612
+ int32_t revNum[sizeOfRev] = {};
613
+ uint8_t status = readMultipleBytes (BOOTLOADER_INFO, BOOTLOADER_VERS, 0x00 , 4 , revNum);
613
614
614
- if ( revNum[ 1 ] != SUCCESS )
615
+ if (!status )
615
616
return ERR_UNKNOWN;
616
617
else {
617
618
bootVers |= (int32_t (revNum[1 ]) << 16 );
@@ -785,7 +786,7 @@ uint8_t SparkFun_Bio_Sensor_Hub::readRegisterAccel(uint8_t regAddr) {
785
786
sensorAttr SparkFun_Bio_Sensor_Hub::getAfeAttributesMAX30101 () {
786
787
787
788
sensorAttr maxAttr;
788
- uint8_t tempArray[2 ];
789
+ uint8_t tempArray[2 ] {} ;
789
790
790
791
readFillArray (READ_ATTRIBUTES_AFE, RETRIEVE_AFE_MAX30101, 2 , tempArray);
791
792
@@ -805,7 +806,7 @@ sensorAttr SparkFun_Bio_Sensor_Hub::getAfeAttributesMAX30101() {
805
806
sensorAttr SparkFun_Bio_Sensor_Hub::getAfeAttributesAccelerometer () {
806
807
807
808
sensorAttr maxAttr;
808
- uint8_t tempArray[2 ];
809
+ uint8_t tempArray[2 ] {} ;
809
810
810
811
readFillArray (READ_ATTRIBUTES_AFE, RETRIEVE_AFE_ACCELEROMETER, 2 , tempArray);
811
812
@@ -819,22 +820,23 @@ sensorAttr SparkFun_Bio_Sensor_Hub::getAfeAttributesAccelerometer() {
819
820
// Family Byte: DUMP_REGISTERS (0x43), Index Byte: DUMP_REGISTER_MAX30101 (0x03)
820
821
// This function returns all registers and register values sequentially of the
821
822
// MAX30101 sensor: register zero and register value zero to register n and
822
- // register value n.
823
- uint8_t * SparkFun_Bio_Sensor_Hub::dumpRegisterMAX30101 (uint8_t numReg, uint8_t regArray[255 ]) {
823
+ // register value n. There are 36 registers in this case.
824
+ uint8_t SparkFun_Bio_Sensor_Hub::dumpRegisterMAX30101 (uint8_t regArray[]) {
824
825
825
- readFillArray (DUMP_REGISTERS, DUMP_REGISTER_MAX30101, numReg, regArray);
826
- return regArray;
826
+ uint8_t numOfBytes = 36 ;
827
+ uint8_t status = readFillArray (DUMP_REGISTERS, DUMP_REGISTER_MAX30101, numOfBytes, regArray);
828
+ return status;
827
829
828
830
}
829
831
830
832
// Family Byte: DUMP_REGISTERS (0x43), Index Byte: DUMP_REGISTER_ACCELEROMETER (0x04)
831
833
// This function returns all registers and register values sequentially of the
832
834
// Accelerometer: register zero and register value zero to register n and
833
835
// register value n.
834
- uint8_t * SparkFun_Bio_Sensor_Hub::dumpRegisterAccelerometer (uint8_t numReg, uint8_t regArray[]) {
836
+ uint8_t SparkFun_Bio_Sensor_Hub::dumpRegisterAccelerometer (uint8_t numReg, uint8_t regArray[]) {
835
837
836
- readFillArray (DUMP_REGISTERS, DUMP_REGISTER_ACCELEROMETER, numReg, regArray); // Fake read amount
837
- return regArray ;
838
+ uint8_t status = readFillArray (DUMP_REGISTERS, DUMP_REGISTER_ACCELEROMETER, numReg, regArray); // Fake read amount
839
+ return status ;
838
840
839
841
}
840
842
@@ -973,14 +975,14 @@ uint8_t SparkFun_Bio_Sensor_Hub::readAlgoSamples() {
973
975
// This function reads the maximum age for the wrist heart rate monitor
974
976
// (WHRM) algorithm. It returns three uint32_t integers that are
975
977
// multiplied by 100,000.
976
- int32_t * SparkFun_Bio_Sensor_Hub::readMaximFastCoef (int32_t coefArr[3 ]) {
978
+ uint8_t SparkFun_Bio_Sensor_Hub::readMaximFastCoef (int32_t coefArr[3 ]) {
977
979
978
- uint8_t numOfReads = 3 ;
979
- readMultipleBytes ( READ_ALGORITHM_CONFIG, READ_MAX_FAST_COEF, READ_MAX_FAST_COEF_ID, numOfReads, coefArr );
980
+ const size_t numOfReads = 3 ;
981
+ uint8_t status = readMultipleBytes ( READ_ALGORITHM_CONFIG, READ_MAX_FAST_COEF, READ_MAX_FAST_COEF_ID, numOfReads, coefArr );
980
982
coefArr[0 ] = coefArr[0 ] * 100000 ;
981
983
coefArr[1 ] = coefArr[1 ] * 100000 ;
982
984
coefArr[2 ] = coefArr[2 ] * 100000 ;
983
- return coefArr ;
985
+ return status ;
984
986
}
985
987
986
988
// Family Byte: ENABLE_ALGORITHM (0x52), Index Byte:
@@ -1138,14 +1140,14 @@ uint8_t SparkFun_Bio_Sensor_Hub::isPatientBPMedication(uint8_t medication){
1138
1140
if (medication != 0x01 || medication != 0x00 )
1139
1141
return INCORR_PARAM;
1140
1142
1141
- uint8_t status = _writeByte (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_MEDICATION, medication);
1143
+ uint8_t status = writeByte (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_MEDICATION, medication);
1142
1144
return status;
1143
1145
1144
1146
}
1145
1147
1146
1148
uint8_t SparkFun_Bio_Sensor_Hub::isPatientBPMedication (){
1147
1149
1148
- uint8_t medication = _readByte (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_MEDICATION);
1150
+ uint8_t medication = readByte (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_MEDICATION);
1149
1151
return medication;
1150
1152
1151
1153
}
@@ -1173,15 +1175,18 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeDiastolicVals(uint8_t diasVal1, uint8_t di
1173
1175
1174
1176
}
1175
1177
1176
- uint8_t SparkFun_Bio_Sensor_Hub::readDiastolicVals (uint8_t ){
1178
+ uint8_t SparkFun_Bio_Sensor_Hub::readDiastolicVals (uint8_t userProvidedArray[] ){
1177
1179
1180
+ const size_t numDiasVals = 3 ;
1181
+ uint8_t status = readMultipleBytes (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, DIASTOLIC_VALUE, numDiasVals, userProvidedArray);
1182
+ return status;
1178
1183
1179
1184
}
1180
1185
1181
1186
uint8_t SparkFun_Bio_Sensor_Hub::writeBPTAlgoData (uint8_t bptCalibData[]){
1182
1187
1183
1188
const size_t numCalibVals = 824 ;
1184
- uint8_t status = writeBytes (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_CALIB_DATA, bptCalibData, numCalibVals)
1189
+ uint8_t status = writeBytes (CHANGE_ALGORITHM_CONFIG, BPT_CONFIG, BPT_CALIB_DATA, bptCalibData, numCalibVals);
1185
1190
return status;
1186
1191
1187
1192
}
@@ -1216,7 +1221,11 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeSP02AlgoCoef(int32_t intA, int32_t intB, i
1216
1221
1217
1222
}
1218
1223
1219
- uint8_t SparkFun_Bio_Sensor_Hub::readBPTAlgoCoef (){ // overload for read and write
1224
+ uint8_t SparkFun_Bio_Sensor_Hub::readSP02AlgoCoef (){ // Have the user provide their own array here and pass the pointer to it
1225
+
1226
+ uint8_t status = readLongByte (CHANGE_ALGORITHM_CONFIG, BPT_CALIB_DATA, AGC_SP02_COEFS);
1227
+ return status;
1228
+
1220
1229
}
1221
1230
1222
1231
// -------------------Private Functions-----------------------
@@ -1318,7 +1327,7 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeByte(uint8_t _familyByte, uint8_t _indexBy
1318
1327
// register address and register value as parameters. Again there is the write
1319
1328
// of the specific bytes followed by a read to confirm positive transmission.
1320
1329
uint8_t SparkFun_Bio_Sensor_Hub::writeLongBytes (uint8_t _familyByte, uint8_t _indexByte,\
1321
- uint8_t _writeByte, const int32_t _writeVal[], const size_t _size)
1330
+ uint8_t _writeByte, int32_t _writeVal[], const size_t _size)
1322
1331
{
1323
1332
1324
1333
_i2cPort->beginTransmission (_address);
@@ -1348,7 +1357,7 @@ uint8_t SparkFun_Bio_Sensor_Hub::writeLongBytes(uint8_t _familyByte, uint8_t _in
1348
1357
// register address and register value as parameters. Again there is the write
1349
1358
// of the specific bytes followed by a read to confirm positive transmission.
1350
1359
uint8_t SparkFun_Bio_Sensor_Hub::writeBytes (uint8_t _familyByte, uint8_t _indexByte,\
1351
- uint8_t _writeByte, const uint8_t _writeVal[], size_t _size)
1360
+ uint8_t _writeByte, uint8_t _writeVal[], size_t _size)
1352
1361
{
1353
1362
1354
1363
_i2cPort->beginTransmission (_address);
@@ -1426,8 +1435,8 @@ uint8_t SparkFun_Bio_Sensor_Hub::readByte(uint8_t _familyByte, uint8_t _indexBy
1426
1435
1427
1436
}
1428
1437
1429
- uint8_t * SparkFun_Bio_Sensor_Hub::readFillArray (uint8_t _familyByte, uint8_t _indexByte,\
1430
- uint8_t arraySize , uint8_t array[] )
1438
+ uint8_t SparkFun_Bio_Sensor_Hub::readFillArray (uint8_t _familyByte, uint8_t _indexByte,\
1439
+ uint8_t _numOfReads , uint8_t array[] )
1431
1440
{
1432
1441
1433
1442
uint8_t statusByte;
@@ -1438,27 +1447,27 @@ uint8_t* SparkFun_Bio_Sensor_Hub::readFillArray(uint8_t _familyByte, uint8_t _in
1438
1447
_i2cPort->endTransmission ();
1439
1448
delay (CMD_DELAY);
1440
1449
1441
- _i2cPort->requestFrom (_address, static_cast <uint8_t >(arraySize + sizeof (statusByte)));
1442
- statusByte = _i2cPort->read (); // Got it
1443
- if ( statusByte ){// SUCCESS ( 0x00)
1444
- for (uint8_t i = 0 ; i < arraySize ; i++){
1450
+ _i2cPort->requestFrom (_address, static_cast <uint8_t >(_numOfReads + sizeof (statusByte)));
1451
+ statusByte = _i2cPort->read ();
1452
+ if ( statusByte ){// SUCCESS: 0x00
1453
+ for (size_t i = 0 ; i < _numOfReads ; i++){
1445
1454
array[i] = 0 ;
1446
1455
}
1447
- return array ;
1456
+ return statusByte ;
1448
1457
}
1449
1458
1450
- for (uint8_t i = 0 ; i < arraySize ; i++){
1459
+ for (size_t i = 0 ; i < _numOfReads ; i++){
1451
1460
array[i] = _i2cPort->read ();
1452
1461
}
1453
- return array; // If good then return the array.
1462
+ return statusByte;
1454
1463
1455
1464
}
1456
1465
// This function handles all read commands or stated another way, all information
1457
1466
// requests. It starts a request by writing the family byte, an index byte, and
1458
1467
// a write byte and then then delays 60 microseconds, during which the MAX32664
1459
1468
// retrieves the requested information. An I-squared-C request is then issued,
1460
1469
// and the information is read. This differs from the above read commands in
1461
- // that it returns a 16 bit integer instead of 8 .
1470
+ // that it returns a 16 bit integer instead of a single byte .
1462
1471
uint16_t SparkFun_Bio_Sensor_Hub::readIntByte (uint8_t _familyByte, uint8_t _indexByte,\
1463
1472
uint8_t _writeByte )
1464
1473
{
@@ -1490,7 +1499,7 @@ uint16_t SparkFun_Bio_Sensor_Hub::readIntByte(uint8_t _familyByte, uint8_t _inde
1490
1499
// a write byte and then then delays 60 microseconds, during which the MAX32664
1491
1500
// retrieves the requested information. An I-squared-C request is then issued,
1492
1501
// and the information is read. This differs from the above read commands in
1493
- // that it returns a 4 byte (uint32_t) integer instead of 8 .
1502
+ // that it returns three, four byte (uint32_t) integer instead of a single byte .
1494
1503
uint32_t SparkFun_Bio_Sensor_Hub::readLongByte (uint8_t _familyByte, uint8_t _indexByte,\
1495
1504
uint8_t _writeByte)
1496
1505
{
@@ -1525,9 +1534,9 @@ uint32_t SparkFun_Bio_Sensor_Hub::readLongByte(uint8_t _familyByte, uint8_t _ind
1525
1534
// retrieves the requested information. An I-squared-C request is then issued,
1526
1535
// and the information is read. This function is very similar to the one above
1527
1536
// except it returns three uint32_t bytes instead of one.
1528
- int32_t * SparkFun_Bio_Sensor_Hub::readMultipleBytes (uint8_t _familyByte, uint8_t _indexByte,\
1529
- uint8_t _writeByte, uint8_t _numOfReads,\
1530
- int32_t * array )
1537
+ uint8_t SparkFun_Bio_Sensor_Hub::readMultipleBytes (uint8_t _familyByte, uint8_t _indexByte,\
1538
+ uint8_t _writeByte, const size_t _numOfReads,\
1539
+ int32_t userArray[] )
1531
1540
{
1532
1541
1533
1542
uint8_t statusByte;
@@ -1542,21 +1551,51 @@ int32_t* SparkFun_Bio_Sensor_Hub::readMultipleBytes(uint8_t _familyByte, uint8_t
1542
1551
_i2cPort->requestFrom (_address, static_cast <uint8_t >(sizeof (int32_t ) * _numOfReads + sizeof (statusByte)));
1543
1552
statusByte = _i2cPort->read ();
1544
1553
if ( statusByte ){ // Pass through if SUCCESS (0x00).
1545
- for (uint8_t i = 0 ; i < (sizeof (int32_t ) * _numOfReads); i++){
1546
- array [i] = 0 ;
1547
- array [i] = 0 ;
1548
- array [i] = 0 ;
1549
- array [i] = 0 ;
1554
+ 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 ;
1550
1559
}
1551
- return array ;
1560
+ return statusByte ;
1552
1561
}
1562
+
1563
+ else
1564
+ return statusByte;
1565
+ }
1553
1566
1554
- for (uint8_t i = 0 ; i < (sizeof (int32_t ) * _numOfReads); i++){
1555
- array[i] |= (_i2cPort->read () << 24 );
1556
- array[i] |= (_i2cPort->read () << 16 );
1557
- array[i] |= (_i2cPort->read () << 8 );
1558
- array[i] |= _i2cPort->read ();
1559
- }
1560
- return array;
1567
+ // This function handles all read commands or stated another way, all information
1568
+ // requests. It starts a request by writing the family byte, an index byte, and
1569
+ // a write byte and then then delays 60 microseconds, during which the MAX32664
1570
+ // retrieves the requested information. An I-squared-C request is then issued,
1571
+ // and the information is read. This function is very similar to the one above
1572
+ // except it returns three uint32_t bytes instead of one.
1573
+ uint8_t SparkFun_Bio_Sensor_Hub::readMultipleBytes (uint8_t _familyByte, uint8_t _indexByte,\
1574
+ uint8_t _writeByte, const size_t _numOfReads,\
1575
+ uint8_t userArray[])
1576
+ {
1577
+
1578
+ uint8_t statusByte;
1579
+
1580
+ _i2cPort->beginTransmission (_address);
1581
+ _i2cPort->write (_familyByte);
1582
+ _i2cPort->write (_indexByte);
1583
+ _i2cPort->write (_writeByte);
1584
+ _i2cPort->endTransmission ();
1585
+ delay (CMD_DELAY);
1561
1586
1587
+ _i2cPort->requestFrom (_address, static_cast <uint8_t >(sizeof (int32_t ) * _numOfReads + sizeof (statusByte)));
1588
+ 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 ;
1595
+ }
1596
+ return statusByte;
1597
+ }
1598
+
1599
+ else
1600
+ return statusByte;
1562
1601
}
0 commit comments