Skip to content

Commit b5af56c

Browse files
author
Elias Santistevan
committed
Changes example code to be more clear on the values returned from function calls
1 parent 8953746 commit b5af56c

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

Examples/Example1_config_BPM_Mode1/Example1_config_BPM_Mode1.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ bioData body;
4343
// You can choose another variable name other than "body", like "blood", or
4444
// "readings", but I chose "body". Using this "body" varible in the
4545
// following way gives us access to the following data:
46-
// body.heartrate - Heartrate
46+
// body.heartrate - Heartrate
4747
// body.confidence - Confidence in the heartrate value
48-
// body.oxygen - Blood oxygen level
49-
// body.status - Has a finger been sensed?
48+
// body.oxygen - Blood oxygen level
49+
// body.status - Has a finger been sensed?
5050

5151

5252
void setup(){
@@ -55,14 +55,14 @@ void setup(){
5555

5656
Wire.begin();
5757
int result = bioHub.begin();
58-
if (!result)
58+
if (result == 0) // Zero errors!
5959
Serial.println("Sensor started!");
6060
else
6161
Serial.println("Could not communicate with the sensor!!!");
6262

6363
Serial.println("Configuring Sensor....");
6464
int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings.
65-
if(!error){
65+
if(error == 0){ // Zero errors!
6666
Serial.println("Sensor configured.");
6767
}
6868
else {
@@ -74,6 +74,7 @@ void setup(){
7474
// Data lags a bit behind the sensor, if you're finger is on the sensor when
7575
// it's being configured this delay will give some time for the data to catch
7676
// up.
77+
Serial.println("Loading up the buffer with data....");
7778
delay(4000);
7879

7980
}

Examples/Example2_config_BPM_Mode2/Example2_config_BPM_Mode2.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ bioData body;
4545
// You can choose another variable name other than "body", like "blood", or
4646
// "readings", but I chose "body". Using this "body" varible in the
4747
// following way gives us access to the following data:
48-
// body.heartrate - Heartrate
48+
// body.heartrate - Heartrate
4949
// body.confidence - Confidence in the heartrate value
50-
// body.oxygen - Blood oxygen level
51-
// body.status - Has a finger been sensed?
52-
// body.extStatus - What else is the finger up to?
53-
// body.rValue - Blood oxygen correlation coefficient.
50+
// body.oxygen - Blood oxygen level
51+
// body.status - Has a finger been sensed?
52+
// body.extStatus - What else is the finger up to?
53+
// body.rValue - Blood oxygen correlation coefficient.
5454

5555

5656
void setup(){
@@ -59,14 +59,14 @@ void setup(){
5959

6060
Wire.begin();
6161
int result = bioHub.begin();
62-
if (!result)
62+
if (result == 0) //Zero errors!
6363
Serial.println("Sensor started!");
6464
else
6565
Serial.println("Could not communicate with the sensor!!!");
6666

6767
Serial.println("Configuring Sensor....");
6868
int error = bioHub.configBpm(MODE_TWO); // Configuring just the BPM settings.
69-
if(!error){
69+
if(error == 0){ // Zero errors
7070
Serial.println("Sensor configured.");
7171
}
7272
else {
@@ -78,6 +78,7 @@ void setup(){
7878
// Data lags a bit behind the sensor, if you're finger is on the sensor when
7979
// it's being configured this delay will give some time for the data to catch
8080
// up.
81+
Serial.println("Loading up the buffer with data....");
8182
delay(4000);
8283

8384
}

Examples/Example3_modify_AGC_Algo/Example3_modify_AGC_Algo.ino

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ int algoSamp = 10; // Number of samples to average (0-255)
3939
// Takes address, reset pin, and MFIO pin.
4040
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin);
4141

42-
sensorAttr attributes;
4342
bioData body;
4443
// What's this!? This is a type (like int, byte, long) unique to the SparkFun
4544
// Pulse Oximeter and Heart Rate Monitor. Unlike those other types it holds
@@ -48,38 +47,38 @@ bioData body;
4847
// You can choose another variable name other than "body", like "blood", or
4948
// "readings", but I chose "body". Using this "body" varible in the
5049
// following way gives us access to the following data:
51-
// body.heartrate - Heartrate
50+
// body.heartrate - Heartrate
5251
// body.confidence - Confidence in the heartrate value
53-
// body.oxygen - Blood oxygen level
54-
// body.status - Has a finger been sensed?
52+
// body.oxygen - Blood oxygen level
53+
// body.status - Has a finger been sensed?
5554

5655
void setup(){
5756

5857
Serial.begin(115200);
5958

6059
Wire.begin();
6160
int result = bioHub.begin();
62-
if (!result)
61+
if (result == 0) // Zero errors!
6362
Serial.println("Sensor started!");
6463

6564
// Adjusting the Automatic Gain Control (AGC) Algorithm
6665
int error = bioHub.setAlgoRange(algoRange));
67-
if (error){
66+
if (error > 0){
6867
Serial.println("Could not set algorithm's Range.");
6968
}
7069

7170
error = bioHub.setAlgoStepSize(algoStepSize);
72-
if (error){
71+
if (error > 0){
7372
Serial.println("Could not set the step size.");
7473
}
7574

7675
error = bioHub.setAlgoSensitivity(algoSens);
77-
if (error){
76+
if (error > 0){
7877
Serial.println("Could not set the sensitivity.");
7978
}
8079

8180
error = bioHub.setAlgoSamples(algoSamp);
82-
if (error){
81+
if (error > 0){
8382
Serial.println("Could not set the sample size.");
8483
}
8584

@@ -102,10 +101,14 @@ void setup(){
102101

103102
Serial.println("Configuing Sensor.");
104103
error = configBpm(MODE_ONE);
105-
if (error){
104+
if (error > 0){
106105
Serial.println("Could not configure the sensor.");
107106
}
108107

108+
// Data lags a bit behind the sensor, if you're finger is on the sensor when
109+
// it's being configured this delay will give some time for the data to catch
110+
// up.
111+
Serial.println("Loading up the buffer with data....");
109112
delay(4000);
110113

111114
}

Examples/Example4_config_LEDs_BPM/Example4_config_LEDs_BPM.ino

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ bioData body;
5656
// "body" but you could use another variable name like "blood", "readings",
5757
// "ledBody" or whatever. Using the variable in the following way gives the
5858
// following data:
59-
// body.irLed - Infrared LED counts.
60-
// body.redLed - Red LED counts.
61-
// body.heartrate - Heartrate
59+
// body.irLed - Infrared LED counts.
60+
// body.redLed - Red LED counts.
61+
// body.heartrate - Heartrate
6262
// body.confidence - Confidence in the heartrate value
63-
// body.oxygen - Blood oxygen level
64-
// body.status - Has a finger been sensed?
63+
// body.oxygen - Blood oxygen level
64+
// body.status - Has a finger been sensed?
6565

6666
void setup(){
6767

6868
Serial.begin(115200);
6969

7070
Wire.begin();
7171
int result = bioHub.begin();
72-
if (!result)
72+
if (result == 0) // Zero errors!
7373
Serial.println("Sensor started!");
7474

7575
Serial.println("Configuring Sensor....");
7676
int error = bioHub.configSensorBpm(MODE_ONE); // Configure Sensor and BPM mode , MODE_TWO also available
77-
if(!error){
77+
if (error == 0){// Zero errors.
7878
Serial.println("Sensor configured.");
7979
}
8080
else {
@@ -85,7 +85,7 @@ void setup(){
8585

8686
// Set pulse width.
8787
error = bioHub.setPulseWidth(width);
88-
if (!error){
88+
if (error == 0){// Zero errors.
8989
Serial.println("Pulse Width Set.");
9090
}
9191
else {
@@ -102,7 +102,7 @@ void setup(){
102102
// Set sample rate per second. Remember that not every sample rate is
103103
// available with every pulse width. Check hookup guide for more information.
104104
error = bioHub.setSampleRate(samples);
105-
if (!error){
105+
if (error == 0){// Zero errors.
106106
Serial.println("Sample Rate Set.");
107107
}
108108
else {
@@ -116,7 +116,10 @@ void setup(){
116116
Serial.print("Sample rate is set to: ");
117117
Serial.println(sampleVal);
118118

119-
// Some time to read your settings.
119+
// Data lags a bit behind the sensor, if you're finger is on the sensor when
120+
// it's being configured this delay will give some time for the data to catch
121+
// up.
122+
Serial.println("Loading up the buffer with data....");
120123
delay(4000);
121124

122125
}

0 commit comments

Comments
 (0)