Skip to content

Commit 1cac22e

Browse files
committed
setMode
1 parent 148ebf3 commit 1cac22e

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ void setup()
8686

8787
setup_sensor();
8888

89-
/* Start particle measurement in continuous mode */
90-
bmv080_status_code_t bmv080_current_status = bmv080_start_continuous_measurement(bmv080_handle);
91-
92-
if (bmv080_current_status != E_BMV080_OK)
89+
/* Set the sensor mode to continuous mode */
90+
if(bmv080.setMode(SFE_BMV080_MODE_CONTINUOUS) == true)
9391
{
94-
printf("Error starting BMV080 continuous measurement: %d\n", bmv080_current_status);
92+
Serial.println("BMV080 set to continuous mode");
9593
}
9694
else
9795
{
98-
printf("BMV080 continuous measurement started successfully\n");
96+
Serial.println("Error setting BMV080 mode");
9997
}
10098
}
10199

src/sfeBmv080.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ void sfeBmv080::setSensorValue(bmv080_output_t bmv080_output)
119119
_sensorValue.is_outside_detection_limits = bmv080_output.is_outside_detection_limits;
120120
}
121121

122+
bool sfeBmv080::setMode(uint8_t mode)
123+
{
124+
bmv080_status_code_t bmv080_current_status; // return status from the Bosch API function
125+
126+
if(mode == SFE_BMV080_MODE_CONTINUOUS)
127+
{
128+
bmv080_current_status = bmv080_start_continuous_measurement(bmv080_handle_class);
129+
}
130+
else if(mode == SFE_BMV080_MODE_DUTY_CYCLE)
131+
{
132+
bmv080_current_status = bmv080_start_duty_cycling_measurement(bmv080_handle_class, (bmv080_callback_tick_t)millis, E_BMV080_DUTY_CYCLING_MODE_0);
133+
}
134+
135+
// check if the mode was set correctly
136+
if (bmv080_current_status == E_BMV080_OK)
137+
{
138+
return true;
139+
}
140+
else
141+
{
142+
return false;
143+
}
144+
}
145+
122146
// void print_to_serial(const char *format, ...)
123147
// {
124148
// char print_buffer[1024];

src/sfeBmv080.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#define SFE_BMV080_DEFAULT_ADDRESS 0x57
3131
#define SFE_BMV080_DEFAULT_IRQ_PIN 14
3232

33+
#define SFE_BMV080_MODE_CONTINUOUS 0
34+
#define SFE_BMV080_MODE_DUTY_CYCLE 1
35+
3336

3437

3538
class sfeBmv080
@@ -51,6 +54,11 @@ class sfeBmv080
5154

5255
void setHandle(bmv080_handle_t handle);
5356

57+
/// @brief Set the mode of the sensor
58+
/// @param mode // 0: Continuous mode, 1: Duty cycling mode
59+
/// @return // True if successful, false otherwise
60+
bool setMode(uint8_t mode);
61+
5462
float getPM25();
5563
bool getIsObstructed();
5664
//void use_sensor_output(bmv080_output_t bmv080_output, void* callback_parameters);

0 commit comments

Comments
 (0)