Skip to content

Propagate the read status to the getEvent calls #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions Adafruit_LSM6DS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ Adafruit_Sensor *Adafruit_LSM6DS::getGyroSensor(void) { return gyro_sensor; }
Pointer to an Adafruit Unified sensor_event_t object to be filled
with temperature event data.

@return True on successful read
@return True on successful read; if false the data obtained are invalid
*/
/**************************************************************************/
bool Adafruit_LSM6DS::getEvent(sensors_event_t *accel, sensors_event_t *gyro,
sensors_event_t *temp) {
uint32_t t = millis();
_read();
if(!_read()){
return false;
}

// use helpers to fill in the events
fillAccelEvent(accel, t);
Expand Down Expand Up @@ -445,15 +447,18 @@ void Adafruit_LSM6DS::highPassFilter(bool filter_enabled,
/******************* Adafruit_Sensor functions *****************/
/*!
* @brief Updates the measurement data for all sensors simultaneously
* @return true on successful read, if false the data obtained are invalid
*/
/**************************************************************************/
void Adafruit_LSM6DS::_read(void) {
bool Adafruit_LSM6DS::_read(void) {
// get raw readings
Adafruit_BusIO_Register data_reg = Adafruit_BusIO_Register(
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUT_TEMP_L, 14);

uint8_t buffer[14];
data_reg.read(buffer, 14);
if(!data_reg.read(buffer, 14)){
return false;
}

rawTemp = buffer[1] << 8 | buffer[0];
temperature = (rawTemp / temperature_sensitivity) + 25.0;
Expand Down Expand Up @@ -499,6 +504,8 @@ void Adafruit_LSM6DS::_read(void) {
accX = rawAccX * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;
accY = rawAccY * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;
accZ = rawAccZ * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;

return true;
}

/**************************************************************************/
Expand Down Expand Up @@ -587,11 +594,13 @@ void Adafruit_LSM6DS_Gyro::getSensor(sensor_t *sensor) {
/*!
@brief Gets the gyroscope as a standard sensor event
@param event Sensor event object that will be populated
@returns True
@returns true on successful read; if false the data obtained are invalid
*/
/**************************************************************************/
bool Adafruit_LSM6DS_Gyro::getEvent(sensors_event_t *event) {
_theLSM6DS->_read();
if (!_theLSM6DS->_read()){
return false;
}
_theLSM6DS->fillGyroEvent(event, millis());

return true;
Expand Down Expand Up @@ -622,11 +631,13 @@ void Adafruit_LSM6DS_Accelerometer::getSensor(sensor_t *sensor) {
/*!
@brief Gets the accelerometer as a standard sensor event
@param event Sensor event object that will be populated
@returns True
@returns true on successful read; if false the data obtained are invalid
*/
/**************************************************************************/
bool Adafruit_LSM6DS_Accelerometer::getEvent(sensors_event_t *event) {
_theLSM6DS->_read();
if(!_theLSM6DS->_read()){
return false;
}
_theLSM6DS->fillAccelEvent(event, millis());

return true;
Expand Down Expand Up @@ -657,11 +668,13 @@ void Adafruit_LSM6DS_Temp::getSensor(sensor_t *sensor) {
/*!
@brief Gets the temperature as a standard sensor event
@param event Sensor event object that will be populated
@returns True
@returns true on successful read; if false the data obtained are invalid
*/
/**************************************************************************/
bool Adafruit_LSM6DS_Temp::getEvent(sensors_event_t *event) {
_theLSM6DS->_read();
if(!_theLSM6DS->_read()){
return false;
}
_theLSM6DS->fillTempEvent(event, millis());

return true;
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_LSM6DS.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Adafruit_LSM6DS {
gyroZ; ///< Last reading's gyro Z axis in rad/s
uint8_t chipID(void);
uint8_t status(void);
virtual void _read(void);
virtual bool _read(void);
virtual bool _init(int32_t sensor_id);

uint16_t _sensorid_accel, ///< ID number for accelerometer
Expand Down
8 changes: 6 additions & 2 deletions Adafruit_LSM6DSO32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ bool Adafruit_LSM6DSO32::_init(int32_t sensor_id) {
*/
/**************************************************************************/
// works for now, should refactor
void Adafruit_LSM6DSO32::_read(void) {
bool Adafruit_LSM6DSO32::_read(void) {
// get raw readings
Adafruit_BusIO_Register data_reg = Adafruit_BusIO_Register(
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_OUT_TEMP_L, 14);

uint8_t buffer[14];
data_reg.read(buffer, 14);
if (!data_reg.read(buffer, 14)){
return false;
}

rawTemp = buffer[1] << 8 | buffer[0];
temperature = (rawTemp / 256.0) + 25.0;
Expand Down Expand Up @@ -108,6 +110,8 @@ void Adafruit_LSM6DSO32::_read(void) {
accX = rawAccX * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;
accY = rawAccY * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;
accZ = rawAccZ * accel_scale * SENSORS_GRAVITY_STANDARD / 1000;

return true;
}

/**************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_LSM6DSO32.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Adafruit_LSM6DSO32 : public Adafruit_LSM6DSOX {

lsm6dso32_accel_range_t getAccelRange(void);
void setAccelRange(lsm6dso32_accel_range_t new_range);
void _read(void);
bool _read(void);

private:
bool _init(int32_t sensor_id);
Expand Down