Skip to content

Commit

Permalink
Merge pull request #47 from maidnl/add_sensor_configuration
Browse files Browse the repository at this point in the history
Added configuration parameter to select the sensor present
  • Loading branch information
facchinm authored Nov 4, 2024
2 parents d4e5ee3 + a749179 commit 551c099
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/BMI270.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void BoschSensorClass::onInterrupt(mbed::Callback<void(void)> cb)
irq.rise(mbed::callback(this, &BoschSensorClass::interrupt_handler));
}
#endif
int BoschSensorClass::begin() {
int BoschSensorClass::begin(CfgBoshSensor_t cfg) {

_wire->begin();

Expand All @@ -60,23 +60,29 @@ int BoschSensorClass::begin() {
mag_dev_info._wire = _wire;
mag_dev_info.dev_addr = bmm1.chip_id;

int8_t bmi270InitResult = bmi270_init(&bmi2);
print_rslt(bmi270InitResult);
int8_t result = 0;

int8_t bmi270ConfigResult = configure_sensor(&bmi2);
print_rslt(bmi270ConfigResult);
if(cfg != BOSCH_MAGNETOMETER_ONLY) {

int8_t bmm150InitResult = bmm150_init(&bmm1);
print_rslt(bmm150InitResult);
result |= bmi270_init(&bmi2);
print_rslt(result);

int8_t bmm150ConfigResult = configure_sensor(&bmm1);
print_rslt(bmm150ConfigResult);
result |= configure_sensor(&bmi2);
print_rslt(result);
}

if(cfg != BOSCH_ACCELEROMETER_ONLY) {

result |= bmm150_init(&bmm1);
print_rslt(result);

result = configure_sensor(&bmm1);
print_rslt(result);
}

bool success = bmi270InitResult == BMI2_OK && bmi270ConfigResult == BMI2_OK &&
bmm150InitResult == BMM150_OK && bmm150ConfigResult == BMM150_OK;
_initialized = success;
_initialized = (result == 0);

return success;
return _initialized;
}


Expand Down
8 changes: 7 additions & 1 deletion src/BoschSensorClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include "utilities/BMI270-Sensor-API/bmi270.h"
#include "utilities/BMM150-Sensor-API/bmm150.h"

typedef enum {
BOSCH_ACCELEROMETER_ONLY,
BOSCH_MAGNETOMETER_ONLY,
BOSCH_ACCEL_AND_MAGN
} CfgBoshSensor_t;

struct dev_info {
TwoWire* _wire;
uint8_t dev_addr;
Expand All @@ -35,7 +41,7 @@ class BoschSensorClass {
void setContinuousMode();
void oneShotMode();

int begin();
int begin(CfgBoshSensor_t cfg = BOSCH_ACCEL_AND_MAGN);
void end();

void debug(Stream&);
Expand Down

0 comments on commit 551c099

Please sign in to comment.