1
1
/* *****************************************************************************
2
- sfeBmv080 .cpp
2
+ sfeDevBMV080 .cpp
3
3
SparkFun BMV080 Library CPP file
4
4
5
5
by Pete Lewis @SparkFun Electronics
6
6
September 2024
7
7
8
- Development environment specifics:
9
- IDE: Arduino 2.3.3
10
- Hardware Platform: SparkFun IoT Redboard ESP32
11
8
BMV080 Breakout HW Version: v01
12
9
13
10
SPDX-License-Identifier: MIT
14
11
15
- Copyright (c) 2024 SparkFun Electronics
12
+ Copyright (c) 2025 SparkFun Electronics
16
13
17
14
Distributed as-is; no warranty is given.
18
15
******************************************************************************/
19
16
20
- #include " sfeBmv080 .h"
17
+ #include " sfeDevBMV080 .h"
21
18
#include " bmv080.h"
22
19
#include " bmv080_defs.h"
23
20
24
21
// need our bus I2C type for some I2C specific features
25
- #include " sfeTk/sfeToolkit.h"
26
22
#include " sfeTk/sfeTkII2C.h"
23
+ #include " sfeTk/sfeToolkit.h"
27
24
28
25
#include < cstring>
29
26
53
50
// Callback for reading data-- called from the Bosch supplied library
54
51
//
55
52
// static int8_t device_read_16bit_CB(bmv080_sercom_handle_t handle, uint16_t header, uint16_t *payload,
56
- int8_t sfeBmv080 ::device_read_16bit_CB (bmv080_sercom_handle_t handle, uint16_t header, uint16_t *payload,
57
- uint16_t payload_length)
53
+ int8_t sfeDevBMV080 ::device_read_16bit_CB (bmv080_sercom_handle_t handle, uint16_t header, uint16_t *payload,
54
+ uint16_t payload_length)
58
55
{
59
56
if (handle == nullptr )
60
57
return E_COMBRIDGE_ERROR_NULLPTR;
@@ -79,8 +76,8 @@ int8_t sfeBmv080::device_read_16bit_CB(bmv080_sercom_handle_t handle, uint16_t h
79
76
// --------------------------------------------------------------------------------------------
80
77
// Callback for reading data-- called from the Bosch supplied library
81
78
//
82
- int8_t sfeBmv080 ::device_write_16bit_CB (bmv080_sercom_handle_t handle, uint16_t header, const uint16_t *payload,
83
- uint16_t payload_length)
79
+ int8_t sfeDevBMV080 ::device_write_16bit_CB (bmv080_sercom_handle_t handle, uint16_t header, const uint16_t *payload,
80
+ uint16_t payload_length)
84
81
{
85
82
if (handle == nullptr )
86
83
return E_COMBRIDGE_ERROR_NULLPTR;
@@ -99,7 +96,7 @@ int8_t sfeBmv080::device_write_16bit_CB(bmv080_sercom_handle_t handle, uint16_t
99
96
// --------------------------------------------------------------------------------------------
100
97
// Delay callback function for the Bosch library
101
98
//
102
- int8_t sfeBmv080 ::device_delay_CB (uint32_t period)
99
+ int8_t sfeDevBMV080 ::device_delay_CB (uint32_t period)
103
100
{
104
101
sfeTk_delay_ms (period);
105
102
// delay(period);
@@ -108,12 +105,12 @@ int8_t sfeBmv080::device_delay_CB(uint32_t period)
108
105
}
109
106
110
107
// ---------------------------------------------------------------------
111
- // This function is just used in this file, so declaring it static
108
+ // helpful class method/callback
112
109
113
110
/* Custom function for consuming sensor readings */
114
- void sfeBmv080 ::set_sensor_value (bmv080_output_t bmv080_output, void *callback_parameters)
111
+ void sfeDevBMV080 ::set_sensor_value (bmv080_output_t bmv080_output, void *callback_parameters)
115
112
{
116
- ((sfeBmv080 *)callback_parameters)->setSensorValue (bmv080_output);
113
+ ((sfeDevBMV080 *)callback_parameters)->setSensorValue (bmv080_output);
117
114
}
118
115
119
116
// ---------------------------------------------------------------------
@@ -122,7 +119,7 @@ void sfeBmv080::set_sensor_value(bmv080_output_t bmv080_output, void *callback_p
122
119
// ---------------------------------------------------------------------
123
120
// Core object implementation
124
121
// ---------------------------------------------------------------------
125
- sfeTkError_t sfeBmv080 ::begin (sfeTkIBus *theBus)
122
+ sfeTkError_t sfeDevBMV080 ::begin (sfeTkIBus *theBus)
126
123
{
127
124
// Nullptr check
128
125
if (theBus == nullptr )
@@ -135,25 +132,25 @@ sfeTkError_t sfeBmv080::begin(sfeTkIBus *theBus)
135
132
}
136
133
137
134
// ---------------------------------------------------------------------
138
- float sfeBmv080 ::PM25 ()
135
+ float sfeDevBMV080 ::PM25 ()
139
136
{
140
137
return _sensorValue.pm2_5_mass_concentration ;
141
138
}
142
139
143
140
// ---------------------------------------------------------------------
144
- float sfeBmv080 ::PM1 ()
141
+ float sfeDevBMV080 ::PM1 ()
145
142
{
146
143
return _sensorValue.pm1_mass_concentration ;
147
144
}
148
145
149
146
// ---------------------------------------------------------------------
150
- bool sfeBmv080 ::isObstructed ()
147
+ bool sfeDevBMV080 ::isObstructed ()
151
148
{
152
149
return _sensorValue.is_obstructed ;
153
150
}
154
151
155
152
// ---------------------------------------------------------------------
156
- void sfeBmv080 ::setSensorValue (bmv080_output_t bmv080_output)
153
+ void sfeDevBMV080 ::setSensorValue (bmv080_output_t bmv080_output)
157
154
{
158
155
// TODO: should here be a mode where the library user can set register a callback function to handle the data?
159
156
// This way the end user can get all the sensor data at once - possible issue is stack/re-entrancy
@@ -167,7 +164,7 @@ void sfeBmv080::setSensorValue(bmv080_output_t bmv080_output)
167
164
// Read the latest values from the sensor.
168
165
//
169
166
// Stash the values internally. If the
170
- bool sfeBmv080 ::readSensor (bmv080_output_t *bmv080_output /* default is nullptr*/ )
167
+ bool sfeDevBMV080 ::readSensor (bmv080_output_t *bmv080_output /* default is nullptr*/ )
171
168
{
172
169
_dataAvailable = false ;
173
170
if (!sensorServiceRoutine ())
@@ -180,9 +177,9 @@ bool sfeBmv080::readSensor(bmv080_output_t *bmv080_output /* default is nullptr*
180
177
}
181
178
182
179
// ---------------------------------------------------------------------
183
- bool sfeBmv080 ::setMode (uint8_t mode)
180
+ bool sfeDevBMV080 ::setMode (uint8_t mode)
184
181
{
185
- bmv080_status_code_t bmv080_current_status; // return status from the Bosch API function
182
+ bmv080_status_code_t bmv080_current_status = E_BMV080_ERROR_PARAM_INVALID_VALUE ; // return status from the Bosch API function
186
183
187
184
if (mode == SFE_BMV080_MODE_CONTINUOUS)
188
185
{
@@ -196,21 +193,14 @@ bool sfeBmv080::setMode(uint8_t mode)
196
193
}
197
194
198
195
// check if the mode was set correctly
199
- if (bmv080_current_status == E_BMV080_OK)
200
- {
201
- return true ;
202
- }
203
- else
204
- {
205
- return false ;
206
- }
196
+ return (bmv080_current_status == E_BMV080_OK);
207
197
}
208
198
209
199
// ---------------------------------------------------------------------
210
200
// Called to pump the service routine of the BMV080 sensor driver
211
201
//
212
202
213
- bool sfeBmv080 ::sensorServiceRoutine (void )
203
+ bool sfeDevBMV080 ::sensorServiceRoutine (void )
214
204
{
215
205
if (_bmv080_handle_class == NULL )
216
206
return false ;
@@ -223,7 +213,7 @@ bool sfeBmv080::sensorServiceRoutine(void)
223
213
224
214
// ---------------------------------------------------------------------
225
215
// Our init method
226
- bool sfeBmv080 ::init ()
216
+ bool sfeDevBMV080 ::init ()
227
217
{
228
218
// Do we have a bus?
229
219
if (_theBus == nullptr )
@@ -238,7 +228,7 @@ bool sfeBmv080::init()
238
228
}
239
229
240
230
// ---------------------------------------------------------------------
241
- bool sfeBmv080 ::open ()
231
+ bool sfeDevBMV080 ::open ()
242
232
{
243
233
if (_theBus == nullptr )
244
234
return false ;
@@ -254,14 +244,14 @@ bool sfeBmv080::open()
254
244
}
255
245
256
246
// ---------------------------------------------------------------------
257
- bool sfeBmv080 ::reset ()
247
+ bool sfeDevBMV080 ::reset ()
258
248
{
259
249
bmv080_status_code_t bmv080_current_status = bmv080_reset (_bmv080_handle_class);
260
250
261
251
return (bmv080_current_status == E_BMV080_OK);
262
252
}
263
253
// ---------------------------------------------------------------------
264
- bool sfeBmv080 ::driverVersion (uint16_t &major, uint16_t &minor, uint16_t &patch)
254
+ bool sfeDevBMV080 ::driverVersion (uint16_t &major, uint16_t &minor, uint16_t &patch)
265
255
{
266
256
char git_hash[12 ];
267
257
int32_t commits_ahead = 0 ;
@@ -275,7 +265,7 @@ bool sfeBmv080::driverVersion(uint16_t &major, uint16_t &minor, uint16_t &patch)
275
265
// ---------------------------------------------------------------------
276
266
277
267
// Method to get the ID
278
- bool sfeBmv080 ::ID (char idOut[kBMV800IDLength ])
268
+ bool sfeDevBMV080 ::ID (char idOut[kBMV800IDLength ])
279
269
{
280
270
memset (idOut, 0x00 , kBMV800IDLength );
281
271
bmv080_status_code_t bmv080_current_status = bmv080_get_sensor_id (_bmv080_handle_class, idOut);
@@ -284,7 +274,7 @@ bool sfeBmv080::ID(char idOut[kBMV800IDLength])
284
274
}
285
275
286
276
// ---------------------------------------------------------------------
287
- uint16_t sfeBmv080 ::dutyCyclingPeriod ()
277
+ uint16_t sfeDevBMV080 ::dutyCyclingPeriod ()
288
278
{
289
279
uint16_t duty_cycling_period = 0 ;
290
280
bmv080_status_code_t bmv080_current_status =
@@ -294,7 +284,7 @@ uint16_t sfeBmv080::dutyCyclingPeriod()
294
284
}
295
285
296
286
// ---------------------------------------------------------------------
297
- bool sfeBmv080 ::setDutyCyclingPeriod (uint16_t duty_cycling_period)
287
+ bool sfeDevBMV080 ::setDutyCyclingPeriod (uint16_t duty_cycling_period)
298
288
{
299
289
bmv080_status_code_t bmv080_current_status =
300
290
bmv080_set_parameter (_bmv080_handle_class, " duty_cycling_period" , (void *)&duty_cycling_period);
@@ -303,7 +293,7 @@ bool sfeBmv080::setDutyCyclingPeriod(uint16_t duty_cycling_period)
303
293
}
304
294
305
295
// ---------------------------------------------------------------------
306
- float sfeBmv080 ::volumetricMassDensity ()
296
+ float sfeDevBMV080 ::volumetricMassDensity ()
307
297
{
308
298
float volumetric_mass_density = 0.0 ;
309
299
bmv080_status_code_t bmv080_current_status =
@@ -313,7 +303,7 @@ float sfeBmv080::volumetricMassDensity()
313
303
}
314
304
315
305
// ---------------------------------------------------------------------
316
- bool sfeBmv080 ::setVolumetricMassDensity (float volumetric_mass_density)
306
+ bool sfeDevBMV080 ::setVolumetricMassDensity (float volumetric_mass_density)
317
307
{
318
308
bmv080_status_code_t bmv080_current_status =
319
309
bmv080_set_parameter (_bmv080_handle_class, " volumetric_mass_density" , (void *)&volumetric_mass_density);
@@ -322,7 +312,7 @@ bool sfeBmv080::setVolumetricMassDensity(float volumetric_mass_density)
322
312
}
323
313
324
314
// ---------------------------------------------------------------------
325
- float sfeBmv080 ::integrationTime ()
315
+ float sfeDevBMV080 ::integrationTime ()
326
316
{
327
317
float integration_time = 0.0 ;
328
318
bmv080_status_code_t bmv080_current_status =
@@ -332,7 +322,7 @@ float sfeBmv080::integrationTime()
332
322
}
333
323
334
324
// ---------------------------------------------------------------------
335
- bool sfeBmv080 ::setIntegrationTime (float integration_time)
325
+ bool sfeDevBMV080 ::setIntegrationTime (float integration_time)
336
326
{
337
327
bmv080_status_code_t bmv080_current_status =
338
328
bmv080_set_parameter (_bmv080_handle_class, " integration_time" , (void *)&integration_time);
@@ -341,7 +331,7 @@ bool sfeBmv080::setIntegrationTime(float integration_time)
341
331
}
342
332
343
333
// ---------------------------------------------------------------------
344
- uint32_t sfeBmv080 ::distributionId ()
334
+ uint32_t sfeDevBMV080 ::distributionId ()
345
335
{
346
336
uint32_t distribution_id = 0 ;
347
337
bmv080_status_code_t bmv080_current_status =
@@ -352,7 +342,7 @@ uint32_t sfeBmv080::distributionId()
352
342
353
343
// ---------------------------------------------------------------------
354
344
355
- bool sfeBmv080 ::setDistributionId (uint32_t distribution_id)
345
+ bool sfeDevBMV080 ::setDistributionId (uint32_t distribution_id)
356
346
{
357
347
bmv080_status_code_t bmv080_current_status =
358
348
bmv080_set_parameter (_bmv080_handle_class, " distribution_id" , (void *)&distribution_id);
@@ -361,7 +351,7 @@ bool sfeBmv080::setDistributionId(uint32_t distribution_id)
361
351
}
362
352
363
353
// ---------------------------------------------------------------------
364
- bool sfeBmv080 ::doObstructionDetection ()
354
+ bool sfeDevBMV080 ::doObstructionDetection ()
365
355
{
366
356
bool do_obstruction_detection = false ;
367
357
bmv080_status_code_t bmv080_current_status =
@@ -371,7 +361,7 @@ bool sfeBmv080::doObstructionDetection()
371
361
}
372
362
373
363
// ---------------------------------------------------------------------
374
- bool sfeBmv080 ::setDoObstructionDetection (bool do_obstruction_detection)
364
+ bool sfeDevBMV080 ::setDoObstructionDetection (bool do_obstruction_detection)
375
365
{
376
366
bmv080_status_code_t bmv080_current_status =
377
367
bmv080_set_parameter (_bmv080_handle_class, " do_obstruction_detection" , (void *)&do_obstruction_detection);
@@ -380,7 +370,7 @@ bool sfeBmv080::setDoObstructionDetection(bool do_obstruction_detection)
380
370
}
381
371
382
372
// ---------------------------------------------------------------------
383
- bool sfeBmv080 ::doVibrationFiltering ()
373
+ bool sfeDevBMV080 ::doVibrationFiltering ()
384
374
{
385
375
bool do_vibration_filtering = false ;
386
376
bmv080_status_code_t bmv080_current_status =
@@ -390,7 +380,7 @@ bool sfeBmv080::doVibrationFiltering()
390
380
}
391
381
392
382
// ---------------------------------------------------------------------
393
- bool sfeBmv080 ::setDoVibrationFiltering (bool do_vibration_filtering)
383
+ bool sfeDevBMV080 ::setDoVibrationFiltering (bool do_vibration_filtering)
394
384
{
395
385
bmv080_status_code_t bmv080_current_status =
396
386
bmv080_set_parameter (_bmv080_handle_class, " do_vibration_filtering" , (void *)&do_vibration_filtering);
@@ -399,7 +389,7 @@ bool sfeBmv080::setDoVibrationFiltering(bool do_vibration_filtering)
399
389
}
400
390
401
391
// ---------------------------------------------------------------------
402
- uint8_t sfeBmv080 ::measurementAlgorithm ()
392
+ uint8_t sfeDevBMV080 ::measurementAlgorithm ()
403
393
{
404
394
bmv080_measurement_algorithm_t measurement_algorithm;
405
395
bmv080_status_code_t bmv080_current_status =
@@ -409,7 +399,7 @@ uint8_t sfeBmv080::measurementAlgorithm()
409
399
}
410
400
411
401
// ---------------------------------------------------------------------
412
- bool sfeBmv080 ::setMeasurementAlgorithm (uint8_t measurement_algorithm)
402
+ bool sfeDevBMV080 ::setMeasurementAlgorithm (uint8_t measurement_algorithm)
413
403
{
414
404
bmv080_measurement_algorithm_t bmv080_measurement_algorithm = (bmv080_measurement_algorithm_t )measurement_algorithm;
415
405
bmv080_status_code_t bmv080_current_status =
0 commit comments