11/* *****************************************************************************
2- sfeBmv080 .cpp
2+ sfeDevBMV080 .cpp
33 SparkFun BMV080 Library CPP file
44
55 by Pete Lewis @SparkFun Electronics
66 September 2024
77
8- Development environment specifics:
9- IDE: Arduino 2.3.3
10- Hardware Platform: SparkFun IoT Redboard ESP32
118 BMV080 Breakout HW Version: v01
129
1310 SPDX-License-Identifier: MIT
1411
15- Copyright (c) 2024 SparkFun Electronics
12+ Copyright (c) 2025 SparkFun Electronics
1613
1714 Distributed as-is; no warranty is given.
1815******************************************************************************/
1916
20- #include " sfeBmv080 .h"
17+ #include " sfeDevBMV080 .h"
2118#include " bmv080.h"
2219#include " bmv080_defs.h"
2320
2421// need our bus I2C type for some I2C specific features
25- #include " sfeTk/sfeToolkit.h"
2622#include " sfeTk/sfeTkII2C.h"
23+ #include " sfeTk/sfeToolkit.h"
2724
2825#include < cstring>
2926
5350// Callback for reading data-- called from the Bosch supplied library
5451//
5552// 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)
5855{
5956 if (handle == nullptr )
6057 return E_COMBRIDGE_ERROR_NULLPTR;
@@ -79,8 +76,8 @@ int8_t sfeBmv080::device_read_16bit_CB(bmv080_sercom_handle_t handle, uint16_t h
7976// --------------------------------------------------------------------------------------------
8077// Callback for reading data-- called from the Bosch supplied library
8178//
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)
8481{
8582 if (handle == nullptr )
8683 return E_COMBRIDGE_ERROR_NULLPTR;
@@ -99,7 +96,7 @@ int8_t sfeBmv080::device_write_16bit_CB(bmv080_sercom_handle_t handle, uint16_t
9996// --------------------------------------------------------------------------------------------
10097// Delay callback function for the Bosch library
10198//
102- int8_t sfeBmv080 ::device_delay_CB (uint32_t period)
99+ int8_t sfeDevBMV080 ::device_delay_CB (uint32_t period)
103100{
104101 sfeTk_delay_ms (period);
105102 // delay(period);
@@ -108,12 +105,12 @@ int8_t sfeBmv080::device_delay_CB(uint32_t period)
108105}
109106
110107// ---------------------------------------------------------------------
111- // This function is just used in this file, so declaring it static
108+ // helpful class method/callback
112109
113110/* 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)
115112{
116- ((sfeBmv080 *)callback_parameters)->setSensorValue (bmv080_output);
113+ ((sfeDevBMV080 *)callback_parameters)->setSensorValue (bmv080_output);
117114}
118115
119116// ---------------------------------------------------------------------
@@ -122,7 +119,7 @@ void sfeBmv080::set_sensor_value(bmv080_output_t bmv080_output, void *callback_p
122119// ---------------------------------------------------------------------
123120// Core object implementation
124121// ---------------------------------------------------------------------
125- sfeTkError_t sfeBmv080 ::begin (sfeTkIBus *theBus)
122+ sfeTkError_t sfeDevBMV080 ::begin (sfeTkIBus *theBus)
126123{
127124 // Nullptr check
128125 if (theBus == nullptr )
@@ -135,25 +132,25 @@ sfeTkError_t sfeBmv080::begin(sfeTkIBus *theBus)
135132}
136133
137134// ---------------------------------------------------------------------
138- float sfeBmv080 ::PM25 ()
135+ float sfeDevBMV080 ::PM25 ()
139136{
140137 return _sensorValue.pm2_5_mass_concentration ;
141138}
142139
143140// ---------------------------------------------------------------------
144- float sfeBmv080 ::PM1 ()
141+ float sfeDevBMV080 ::PM1 ()
145142{
146143 return _sensorValue.pm1_mass_concentration ;
147144}
148145
149146// ---------------------------------------------------------------------
150- bool sfeBmv080 ::isObstructed ()
147+ bool sfeDevBMV080 ::isObstructed ()
151148{
152149 return _sensorValue.is_obstructed ;
153150}
154151
155152// ---------------------------------------------------------------------
156- void sfeBmv080 ::setSensorValue (bmv080_output_t bmv080_output)
153+ void sfeDevBMV080 ::setSensorValue (bmv080_output_t bmv080_output)
157154{
158155 // TODO: should here be a mode where the library user can set register a callback function to handle the data?
159156 // 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)
167164// Read the latest values from the sensor.
168165//
169166// 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*/ )
171168{
172169 _dataAvailable = false ;
173170 if (!sensorServiceRoutine ())
@@ -180,9 +177,9 @@ bool sfeBmv080::readSensor(bmv080_output_t *bmv080_output /* default is nullptr*
180177}
181178
182179// ---------------------------------------------------------------------
183- bool sfeBmv080 ::setMode (uint8_t mode)
180+ bool sfeDevBMV080 ::setMode (uint8_t mode)
184181{
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
186183
187184 if (mode == SFE_BMV080_MODE_CONTINUOUS)
188185 {
@@ -196,21 +193,14 @@ bool sfeBmv080::setMode(uint8_t mode)
196193 }
197194
198195 // 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);
207197}
208198
209199// ---------------------------------------------------------------------
210200// Called to pump the service routine of the BMV080 sensor driver
211201//
212202
213- bool sfeBmv080 ::sensorServiceRoutine (void )
203+ bool sfeDevBMV080 ::sensorServiceRoutine (void )
214204{
215205 if (_bmv080_handle_class == NULL )
216206 return false ;
@@ -223,7 +213,7 @@ bool sfeBmv080::sensorServiceRoutine(void)
223213
224214// ---------------------------------------------------------------------
225215// Our init method
226- bool sfeBmv080 ::init ()
216+ bool sfeDevBMV080 ::init ()
227217{
228218 // Do we have a bus?
229219 if (_theBus == nullptr )
@@ -238,7 +228,7 @@ bool sfeBmv080::init()
238228}
239229
240230// ---------------------------------------------------------------------
241- bool sfeBmv080 ::open ()
231+ bool sfeDevBMV080 ::open ()
242232{
243233 if (_theBus == nullptr )
244234 return false ;
@@ -254,14 +244,14 @@ bool sfeBmv080::open()
254244}
255245
256246// ---------------------------------------------------------------------
257- bool sfeBmv080 ::reset ()
247+ bool sfeDevBMV080 ::reset ()
258248{
259249 bmv080_status_code_t bmv080_current_status = bmv080_reset (_bmv080_handle_class);
260250
261251 return (bmv080_current_status == E_BMV080_OK);
262252}
263253// ---------------------------------------------------------------------
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)
265255{
266256 char git_hash[12 ];
267257 int32_t commits_ahead = 0 ;
@@ -275,7 +265,7 @@ bool sfeBmv080::driverVersion(uint16_t &major, uint16_t &minor, uint16_t &patch)
275265// ---------------------------------------------------------------------
276266
277267// Method to get the ID
278- bool sfeBmv080 ::ID (char idOut[kBMV800IDLength ])
268+ bool sfeDevBMV080 ::ID (char idOut[kBMV800IDLength ])
279269{
280270 memset (idOut, 0x00 , kBMV800IDLength );
281271 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])
284274}
285275
286276// ---------------------------------------------------------------------
287- uint16_t sfeBmv080 ::dutyCyclingPeriod ()
277+ uint16_t sfeDevBMV080 ::dutyCyclingPeriod ()
288278{
289279 uint16_t duty_cycling_period = 0 ;
290280 bmv080_status_code_t bmv080_current_status =
@@ -294,7 +284,7 @@ uint16_t sfeBmv080::dutyCyclingPeriod()
294284}
295285
296286// ---------------------------------------------------------------------
297- bool sfeBmv080 ::setDutyCyclingPeriod (uint16_t duty_cycling_period)
287+ bool sfeDevBMV080 ::setDutyCyclingPeriod (uint16_t duty_cycling_period)
298288{
299289 bmv080_status_code_t bmv080_current_status =
300290 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)
303293}
304294
305295// ---------------------------------------------------------------------
306- float sfeBmv080 ::volumetricMassDensity ()
296+ float sfeDevBMV080 ::volumetricMassDensity ()
307297{
308298 float volumetric_mass_density = 0.0 ;
309299 bmv080_status_code_t bmv080_current_status =
@@ -313,7 +303,7 @@ float sfeBmv080::volumetricMassDensity()
313303}
314304
315305// ---------------------------------------------------------------------
316- bool sfeBmv080 ::setVolumetricMassDensity (float volumetric_mass_density)
306+ bool sfeDevBMV080 ::setVolumetricMassDensity (float volumetric_mass_density)
317307{
318308 bmv080_status_code_t bmv080_current_status =
319309 bmv080_set_parameter (_bmv080_handle_class, " volumetric_mass_density" , (void *)&volumetric_mass_density);
@@ -322,7 +312,7 @@ bool sfeBmv080::setVolumetricMassDensity(float volumetric_mass_density)
322312}
323313
324314// ---------------------------------------------------------------------
325- float sfeBmv080 ::integrationTime ()
315+ float sfeDevBMV080 ::integrationTime ()
326316{
327317 float integration_time = 0.0 ;
328318 bmv080_status_code_t bmv080_current_status =
@@ -332,7 +322,7 @@ float sfeBmv080::integrationTime()
332322}
333323
334324// ---------------------------------------------------------------------
335- bool sfeBmv080 ::setIntegrationTime (float integration_time)
325+ bool sfeDevBMV080 ::setIntegrationTime (float integration_time)
336326{
337327 bmv080_status_code_t bmv080_current_status =
338328 bmv080_set_parameter (_bmv080_handle_class, " integration_time" , (void *)&integration_time);
@@ -341,7 +331,7 @@ bool sfeBmv080::setIntegrationTime(float integration_time)
341331}
342332
343333// ---------------------------------------------------------------------
344- uint32_t sfeBmv080 ::distributionId ()
334+ uint32_t sfeDevBMV080 ::distributionId ()
345335{
346336 uint32_t distribution_id = 0 ;
347337 bmv080_status_code_t bmv080_current_status =
@@ -352,7 +342,7 @@ uint32_t sfeBmv080::distributionId()
352342
353343// ---------------------------------------------------------------------
354344
355- bool sfeBmv080 ::setDistributionId (uint32_t distribution_id)
345+ bool sfeDevBMV080 ::setDistributionId (uint32_t distribution_id)
356346{
357347 bmv080_status_code_t bmv080_current_status =
358348 bmv080_set_parameter (_bmv080_handle_class, " distribution_id" , (void *)&distribution_id);
@@ -361,7 +351,7 @@ bool sfeBmv080::setDistributionId(uint32_t distribution_id)
361351}
362352
363353// ---------------------------------------------------------------------
364- bool sfeBmv080 ::doObstructionDetection ()
354+ bool sfeDevBMV080 ::doObstructionDetection ()
365355{
366356 bool do_obstruction_detection = false ;
367357 bmv080_status_code_t bmv080_current_status =
@@ -371,7 +361,7 @@ bool sfeBmv080::doObstructionDetection()
371361}
372362
373363// ---------------------------------------------------------------------
374- bool sfeBmv080 ::setDoObstructionDetection (bool do_obstruction_detection)
364+ bool sfeDevBMV080 ::setDoObstructionDetection (bool do_obstruction_detection)
375365{
376366 bmv080_status_code_t bmv080_current_status =
377367 bmv080_set_parameter (_bmv080_handle_class, " do_obstruction_detection" , (void *)&do_obstruction_detection);
@@ -380,7 +370,7 @@ bool sfeBmv080::setDoObstructionDetection(bool do_obstruction_detection)
380370}
381371
382372// ---------------------------------------------------------------------
383- bool sfeBmv080 ::doVibrationFiltering ()
373+ bool sfeDevBMV080 ::doVibrationFiltering ()
384374{
385375 bool do_vibration_filtering = false ;
386376 bmv080_status_code_t bmv080_current_status =
@@ -390,7 +380,7 @@ bool sfeBmv080::doVibrationFiltering()
390380}
391381
392382// ---------------------------------------------------------------------
393- bool sfeBmv080 ::setDoVibrationFiltering (bool do_vibration_filtering)
383+ bool sfeDevBMV080 ::setDoVibrationFiltering (bool do_vibration_filtering)
394384{
395385 bmv080_status_code_t bmv080_current_status =
396386 bmv080_set_parameter (_bmv080_handle_class, " do_vibration_filtering" , (void *)&do_vibration_filtering);
@@ -399,7 +389,7 @@ bool sfeBmv080::setDoVibrationFiltering(bool do_vibration_filtering)
399389}
400390
401391// ---------------------------------------------------------------------
402- uint8_t sfeBmv080 ::measurementAlgorithm ()
392+ uint8_t sfeDevBMV080 ::measurementAlgorithm ()
403393{
404394 bmv080_measurement_algorithm_t measurement_algorithm;
405395 bmv080_status_code_t bmv080_current_status =
@@ -409,7 +399,7 @@ uint8_t sfeBmv080::measurementAlgorithm()
409399}
410400
411401// ---------------------------------------------------------------------
412- bool sfeBmv080 ::setMeasurementAlgorithm (uint8_t measurement_algorithm)
402+ bool sfeDevBMV080 ::setMeasurementAlgorithm (uint8_t measurement_algorithm)
413403{
414404 bmv080_measurement_algorithm_t bmv080_measurement_algorithm = (bmv080_measurement_algorithm_t )measurement_algorithm;
415405 bmv080_status_code_t bmv080_current_status =
0 commit comments