Skip to content

Commit

Permalink
Merge pull request #4 from adafruit/fix-timestamp-hardfault
Browse files Browse the repository at this point in the history
fix hardfault when accelEvent is NULL
  • Loading branch information
ladyada authored Jan 13, 2020
2 parents 4832aa1 + 6ad3cf5 commit f4ae261
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Adafruit_FXOS8700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ bool Adafruit_FXOS8700::getEvent(sensors_event_t* accelEvent, sensors_event_t* m
uint8_t mzlo = Wire.receive();
#endif

uint32_t const timestamp = millis();

if (accelEvent) {
/* Clear the event */
Expand All @@ -272,7 +273,7 @@ bool Adafruit_FXOS8700::getEvent(sensors_event_t* accelEvent, sensors_event_t* m
accelEvent->type = SENSOR_TYPE_ACCELEROMETER;

/* Set the timestamps */
accelEvent->timestamp = millis();
accelEvent->timestamp = timestamp;

/* Shift values to create properly formed integers */
/* Note, accel data is 14-bit and left-aligned, so we shift two bit right */
Expand Down Expand Up @@ -317,7 +318,7 @@ bool Adafruit_FXOS8700::getEvent(sensors_event_t* accelEvent, sensors_event_t* m
magEvent->sensor_id = _magSensorID;
magEvent->type = SENSOR_TYPE_MAGNETIC_FIELD;

magEvent->timestamp = accelEvent->timestamp;
magEvent->timestamp = timestamp;

magEvent->magnetic.x = (int16_t)((mxhi << 8) | mxlo);
magEvent->magnetic.y = (int16_t)((myhi << 8) | mylo);
Expand Down

0 comments on commit f4ae261

Please sign in to comment.