Skip to content

Commit c6aad08

Browse files
committed
ex1 and 5 working with sdk v10.0.0
-added in functionality to read PM 1 -added in functionality to get or set the measurement algorithm
1 parent f232cb5 commit c6aad08

File tree

8 files changed

+143
-19
lines changed

8 files changed

+143
-19
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ void loop()
7575
if (bmv080.dataAvailable())
7676
{
7777
float pm25 = bmv080.getPM25();
78+
float pm1 = bmv080.getPM1();
7879

7980
Serial.print(pm25);
81+
Serial.print("\t");
82+
Serial.print(pm1);
8083

8184
if (bmv080.getIsObstructed() == true)
8285
{

examples/Example_05_Parameters/Example_05_Parameters.ino

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
distribution_id
1010
do_obstruction_detection
1111
do_vibration_filtering
12+
measurement_algorithm
1213
1314
After these parameters are read and set, This example shows how to use the
1415
sensor in "continuous mode" to get particulate matter readings once every
@@ -108,6 +109,7 @@ void getSetParameters(void)
108109
uint32_t distribution_id = 0;
109110
bool do_obstruction_detection = false;
110111
bool do_vibration_filtering = false;
112+
uint8_t measurementAlgorithm = E_BMV080_MEASUREMENT_ALGORITHM_BALANCED;
111113

112114
/***************************************************************************
113115
*
@@ -155,6 +157,25 @@ void getSetParameters(void)
155157
Serial.println("false");
156158
}
157159

160+
/* Get default parameter "measurement_algorithm" */
161+
measurementAlgorithm = bmv080.getMeasurementAlgorithm();
162+
Serial.print("BMV080 parameter 'measurement_algorithm' READ: ");
163+
switch (measurementAlgorithm)
164+
{
165+
case E_BMV080_MEASUREMENT_ALGORITHM_FAST_RESPONSE:
166+
Serial.println("Fast Response");
167+
break;
168+
case E_BMV080_MEASUREMENT_ALGORITHM_BALANCED:
169+
Serial.println("Balanced");
170+
break;
171+
case E_BMV080_MEASUREMENT_ALGORITHM_HIGH_PRECISION:
172+
Serial.println("High Precision");
173+
break;
174+
default:
175+
Serial.println("Unknown");
176+
break;
177+
}
178+
158179

159180
/***************************************************************************
160181
*
@@ -169,6 +190,7 @@ void getSetParameters(void)
169190
// distribution_id = 3;
170191
// do_obstruction_detection = true;
171192
// do_vibration_filtering = false;
193+
// measurementAlgorithm = E_BMV080_MEASUREMENT_ALGORITHM_BALANCED;
172194

173195
/* Set custom parameter "volumetric_mass_density" */
174196
if(bmv080.setVolumetricMassDensity(volumetric_mass_density) == true)
@@ -239,5 +261,30 @@ void getSetParameters(void)
239261
Serial.println("Error setting BMV080 parameter 'do_vibration_filtering'");
240262
}
241263

264+
/* Set custom parameter "measurement_algorithm" */
265+
if(bmv080.setMeasurementAlgorithm(measurementAlgorithm) == true)
266+
{
267+
Serial.print("BMV080 parameter 'measurement_algorithm' SET TO: ");
268+
switch (measurementAlgorithm)
269+
{
270+
case E_BMV080_MEASUREMENT_ALGORITHM_FAST_RESPONSE:
271+
Serial.println("Fast Response");
272+
break;
273+
case E_BMV080_MEASUREMENT_ALGORITHM_BALANCED:
274+
Serial.println("Balanced");
275+
break;
276+
case E_BMV080_MEASUREMENT_ALGORITHM_HIGH_PRECISION:
277+
Serial.println("High Precision");
278+
break;
279+
default:
280+
Serial.println("Unknown");
281+
break;
282+
}
283+
}
284+
else
285+
{
286+
Serial.println("Error setting BMV080 parameter 'measurement_algorithm'");
287+
}
288+
242289
Serial.println();
243290
}

src/bmv080.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ bmv080_status_code_t bmv080_reset(const bmv080_handle_t handle);
151151
* <tr> <td> "distribution_id" <td> uint32_t <td> <td> 3 <td> For internal use only.
152152
* <tr> <td> "do_obstruction_detection" <td> bool <td> <td> true <td> Set if obstruction detection feature is enabled.
153153
* <tr> <td> "do_vibration_filtering" <td> bool <td> <td> false <td> Set if vibration filter is enabled.
154+
* <tr> <td> "measurement_algorithm" <td> bmv080_measurement_algorithm_t <td> <td> E_BMV080_MEASUREMENT_ALGORITHM_HIGH_PRECISION (3) <td> Selection of measurement algorithm based on the
155+
* <br> use case, as defined by the type bmv080_measurement_algorithm_t,
156+
* <br> in bmv080_defs.h. For a duty cycling measurement, this parameter is
157+
* <br> fixed to E_BMV080_MEASUREMENT_ALGORITHM_FAST_RESPONSE.
154158
* </table>
155159
*
156160
* @pre A valid _handle_ generated by _bmv080_open_ is required.
@@ -192,7 +196,11 @@ bmv080_status_code_t bmv080_get_parameter(const bmv080_handle_t handle, const ch
192196
* <tr> <td> "distribution_id" <td> uint32_t <td> <td> 3 <td> For internal use only.
193197
* <tr> <td> "do_obstruction_detection" <td> bool <td> <td> true <td> Set if obstruction detection feature is enabled.
194198
* <tr> <td> "do_vibration_filtering" <td> bool <td> <td> false <td> Set if vibration filter is enabled.
195-
* </table>s
199+
* <tr> <td> "measurement_algorithm" <td> bmv080_measurement_algorithm_t <td> <td> E_BMV080_MEASUREMENT_ALGORITHM_HIGH_PRECISION (3) <td> Selection of measurement algorithm based on the
200+
* <br> use case, as defined by the type bmv080_measurement_algorithm_t,
201+
* <br> in bmv080_defs.h. For a duty cycling measurement, this parameter is
202+
* <br> fixed to E_BMV080_MEASUREMENT_ALGORITHM_FAST_RESPONSE.
203+
* </table>
196204
*
197205
* @pre A valid _handle_ generated by _bmv080_open_ is required.
198206
* @pre This function must be called before _bmv080_start_continuous_measurement_ or _bmv080_start_duty_cycling_measurement_

src/bmv080_defs.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ typedef enum
364364
E_BMV080_DUTY_CYCLING_MODE_0 = 0
365365
} bmv080_duty_cycling_mode_t;
366366

367+
/*!
368+
* @brief Measurement algorithm choices.
369+
*/
370+
typedef enum
371+
{
372+
E_BMV080_MEASUREMENT_ALGORITHM_FAST_RESPONSE = 1,
373+
E_BMV080_MEASUREMENT_ALGORITHM_BALANCED = 2,
374+
E_BMV080_MEASUREMENT_ALGORITHM_HIGH_PRECISION = 3
375+
} bmv080_measurement_algorithm_t;
376+
367377
/*!
368378
* @brief Placeholder structure for extended sensor output information.
369379
*/
@@ -374,27 +384,36 @@ struct bmv080_extended_info_s;
374384
*/
375385
typedef struct
376386
{
387+
/*! runtime_in_sec: estimate of the time passed since the start of the measurement, in seconds */
388+
float runtime_in_sec;
389+
/*! pm2_5_mass_concentration: PM2.5 value in ug/m3 */
390+
float pm2_5_mass_concentration;
391+
/*! pm1_mass_concentration: PM1 value in ug/m3 */
392+
float pm1_mass_concentration;
393+
/*! is_obstructed: flag to indicate whether the sensor is obstructed and cannot perform a valid measurement */
394+
bool is_obstructed;
395+
/*! is_outside_measurement_range: flag to indicate whether the PM2.5 concentration is
396+
* outside the specified measurement range (0..1000 ug/m3)
397+
*/
398+
bool is_outside_measurement_range;
377399
/*! reserved_0: for internal use only */
378400
float reserved_0;
379401
/*! reserved_1: for internal use only */
380402
float reserved_1;
381403
/*! reserved_2: for internal use only */
382404
float reserved_2;
383-
/*! pm2_5: PM2.5 value in ug/m3 */
384-
float pm2_5;
385-
/*! runtime_in_sec: estimate of the time passed since the start of the measurement, in seconds */
386-
float runtime_in_sec;
387-
/*! is_obstructed: flag to indicate whether the sensor is obstructed and cannot perform a valid measurement */
388-
bool is_obstructed;
389-
/*! is_outside_detection_limits: flag to indicate whether the PM2.5 concentration is outside the detection limits
390-
* and a valid measurement cannot be performed
391-
*/
392-
bool is_outside_detection_limits;
405+
/*! reserved_3: for internal use only */
406+
float reserved_3;
407+
/*! reserved_4: for internal use only */
408+
float reserved_4;
409+
/*! reserved_5: for internal use only */
410+
float reserved_5;
411+
/*! reserved_6: for internal use only */
412+
float reserved_6;
393413
/*! extended_info: for internal use only */
394414
struct bmv080_extended_info_s *extended_info;
395415
}bmv080_output_t;
396416

397-
398417
/*********************************************************************************************************************
399418
* Callback definitions
400419
*********************************************************************************************************************/
@@ -464,8 +483,4 @@ typedef uint32_t(*bmv080_callback_tick_t)(void);
464483
*/
465484
typedef void(*bmv080_callback_data_ready_t)(bmv080_output_t bmv080_output, void* callback_parameters);
466485

467-
468-
/* Function pointer to facilitate printing output / status information to the console */
469-
typedef int (*print_function_t)(const char *const _format, ...);
470-
471486
#endif /* BMV080_DEFS_H_ */

src/esp32/libbmv080.a

5.47 KB
Binary file not shown.

src/esp32/libpostProcessor.a

64.7 KB
Binary file not shown.

src/sfeBmv080.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ sfeTkError_t sfeBmv080::begin(sfeTkIBus *theBus)
141141

142142
float sfeBmv080::getPM25()
143143
{
144-
return _sensorValue.pm2_5;
144+
return _sensorValue.pm2_5_mass_concentration;
145+
}
146+
147+
float sfeBmv080::getPM1()
148+
{
149+
return _sensorValue.pm1_mass_concentration;
145150
}
146151

147152
bool sfeBmv080::getIsObstructed()
@@ -152,10 +157,11 @@ bool sfeBmv080::getIsObstructed()
152157
void sfeBmv080::setSensorValue(bmv080_output_t bmv080_output)
153158
{
154159
_dataAvailable = true;
155-
_sensorValue.pm2_5 = bmv080_output.pm2_5;
160+
_sensorValue.pm2_5_mass_concentration = bmv080_output.pm2_5_mass_concentration;
161+
_sensorValue.pm1_mass_concentration = bmv080_output.pm1_mass_concentration;
156162
_sensorValue.runtime_in_sec = bmv080_output.runtime_in_sec;
157163
_sensorValue.is_obstructed = bmv080_output.is_obstructed;
158-
_sensorValue.is_outside_detection_limits = bmv080_output.is_outside_detection_limits;
164+
_sensorValue.is_outside_measurement_range = bmv080_output.is_outside_measurement_range;
159165
}
160166

161167
bool sfeBmv080::setMode(uint8_t mode)
@@ -476,4 +482,36 @@ bool sfeBmv080::setDoVibrationFiltering(bool do_vibration_filtering)
476482
{
477483
return true;
478484
}
485+
}
486+
487+
uint8_t sfeBmv080::getMeasurementAlgorithm()
488+
{
489+
bmv080_measurement_algorithm_t measurement_algorithm;
490+
bmv080_status_code_t bmv080_current_status =
491+
bmv080_get_parameter(bmv080_handle_class, "measurement_algorithm", (void *)&measurement_algorithm);
492+
if (bmv080_current_status != E_BMV080_OK)
493+
{
494+
printf("Error getting BMV080 Measurement Algorithm: %d\n", bmv080_current_status);
495+
return 0;
496+
}
497+
else
498+
{
499+
return (uint8_t)measurement_algorithm;
500+
}
501+
}
502+
503+
bool sfeBmv080::setMeasurementAlgorithm(uint8_t measurement_algorithm)
504+
{
505+
bmv080_measurement_algorithm_t bmv080_measurement_algorithm = (bmv080_measurement_algorithm_t)measurement_algorithm;
506+
bmv080_status_code_t bmv080_current_status =
507+
bmv080_set_parameter(bmv080_handle_class, "measurement_algorithm", (void *)&bmv080_measurement_algorithm);
508+
if (bmv080_current_status != E_BMV080_OK)
509+
{
510+
printf("Error setting BMV080 Measurement Algorithm: %d\n", bmv080_current_status);
511+
return false;
512+
}
513+
else
514+
{
515+
return true;
516+
}
479517
}

src/sfeBmv080.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class sfeBmv080
8989
/// @return The PM2.5 value as a float in ug/m3
9090
float getPM25();
9191

92+
/// @brief Get the PM1 value
93+
/// @return The PM1 value as a float in ug/m3
94+
float getPM1();
95+
9296
/// @brief Get the obstruction status
9397
/// @return True if obstructed, false otherwise
9498
bool getIsObstructed();
@@ -155,6 +159,15 @@ class sfeBmv080
155159
/// @return True if successful, false otherwise
156160
bool setDoVibrationFiltering(bool do_vibration_filtering);
157161

162+
/// @brief Get a parameter: "measurement_algorithm"
163+
/// @return uint8_t measurement_algorithm
164+
uint8_t getMeasurementAlgorithm();
165+
166+
/// @brief Set a parameter: "measurement_algorithm"
167+
/// @param measurement_algorithm
168+
/// @return True if successful, false otherwise
169+
bool setMeasurementAlgorithm(uint8_t measurement_algorithm);
170+
158171
private:
159172
bmv080_handle_t bmv080_handle_class = NULL;
160173
bool _dataAvailable = false;

0 commit comments

Comments
 (0)