Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Renamed raw output to .raw
Browse files Browse the repository at this point in the history
  • Loading branch information
microbuilder committed Oct 10, 2016
1 parent 62dda10 commit 421141d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
50 changes: 25 additions & 25 deletions Adafruit_LSM303_U.cpp
Expand Up @@ -121,9 +121,9 @@ void Adafruit_LSM303_Accel_Unified::read()
#endif

// Shift values to create properly formed integer (low byte first)
accelData.x = (int16_t)(xlo | (xhi << 8)) >> 4;
accelData.y = (int16_t)(ylo | (yhi << 8)) >> 4;
accelData.z = (int16_t)(zlo | (zhi << 8)) >> 4;
raw.x = (int16_t)(xlo | (xhi << 8)) >> 4;
raw.y = (int16_t)(ylo | (yhi << 8)) >> 4;
raw.z = (int16_t)(zlo | (zhi << 8)) >> 4;
}

/***************************************************************************
Expand All @@ -139,9 +139,9 @@ Adafruit_LSM303_Accel_Unified::Adafruit_LSM303_Accel_Unified(int32_t sensorID) {
_sensorID = sensorID;

// Clear the raw accel data
accelData.x = 0;
accelData.y = 0;
accelData.z = 0;
raw.x = 0;
raw.y = 0;
raw.z = 0;
}

/***************************************************************************
Expand Down Expand Up @@ -188,9 +188,9 @@ bool Adafruit_LSM303_Accel_Unified::getEvent(sensors_event_t *event) {
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_ACCELEROMETER;
event->timestamp = millis();
event->acceleration.x = accelData.x * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
event->acceleration.y = accelData.y * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
event->acceleration.z = accelData.z * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
event->acceleration.x = (float)raw.x * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
event->acceleration.y = (float)raw.y * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;
event->acceleration.z = (float)raw.z * _lsm303Accel_MG_LSB * SENSORS_GRAVITY_STANDARD;

return true;
}
Expand Down Expand Up @@ -306,9 +306,9 @@ void Adafruit_LSM303_Mag_Unified::read()
#endif

// Shift values to create properly formed integer (low byte first)
magData.x = (int16_t)(xlo | ((int16_t)xhi << 8));
magData.y = (int16_t)(ylo | ((int16_t)yhi << 8));
magData.z = (int16_t)(zlo | ((int16_t)zhi << 8));
raw.x = (int16_t)(xlo | ((int16_t)xhi << 8));
raw.y = (int16_t)(ylo | ((int16_t)yhi << 8));
raw.z = (int16_t)(zlo | ((int16_t)zhi << 8));
}

/***************************************************************************
Expand All @@ -324,10 +324,10 @@ Adafruit_LSM303_Mag_Unified::Adafruit_LSM303_Mag_Unified(int32_t sensorID) {
_sensorID = sensorID;
autoRangeEnabled = false;

// Clear the raw accel data
magData.x = 0;
magData.y = 0;
magData.z = 0;
// Clear the raw mag data
raw.x = 0;
raw.y = 0;
raw.z = 0;
}

/***************************************************************************
Expand Down Expand Up @@ -457,14 +457,14 @@ bool Adafruit_LSM303_Mag_Unified::getEvent(sensors_event_t *event) {
else
{
#ifdef LSM303_DEBUG
Serial.print(magData.x); Serial.print(" ");
Serial.print(magData.y); Serial.print(" ");
Serial.print(magData.z); Serial.println(" ");
Serial.print(raw.x); Serial.print(" ");
Serial.print(raw.y); Serial.print(" ");
Serial.print(raw.z); Serial.println(" ");
#endif
/* Check if the sensor is saturating or not */
if ( (magData.x >= 2040) | (magData.x <= -2040) |
(magData.y >= 2040) | (magData.y <= -2040) |
(magData.z >= 2040) | (magData.z <= -2040) )
if ( (raw.x >= 2040) | (raw.x <= -2040) |
(raw.y >= 2040) | (raw.y <= -2040) |
(raw.z >= 2040) | (raw.z <= -2040) )
{
/* Saturating .... increase the range if we can */
switch(magGain)
Expand Down Expand Up @@ -528,9 +528,9 @@ bool Adafruit_LSM303_Mag_Unified::getEvent(sensors_event_t *event) {
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_MAGNETIC_FIELD;
event->timestamp = millis();
event->magnetic.x = magData.x / _lsm303Mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
event->magnetic.y = magData.y / _lsm303Mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
event->magnetic.z = magData.z / _lsm303Mag_Gauss_LSB_Z * SENSORS_GAUSS_TO_MICROTESLA;
event->magnetic.x = (float)raw.x / _lsm303Mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
event->magnetic.y = (float)raw.y / _lsm303Mag_Gauss_LSB_XY * SENSORS_GAUSS_TO_MICROTESLA;
event->magnetic.z = (float)raw.z / _lsm303Mag_Gauss_LSB_Z * SENSORS_GAUSS_TO_MICROTESLA;

return true;
}
Expand Down
18 changes: 9 additions & 9 deletions Adafruit_LSM303_U.h
Expand Up @@ -125,9 +125,9 @@
-----------------------------------------------------------------------*/
typedef struct lsm303MagData_s
{
float x;
float y;
float z;
int16_t x;
int16_t y;
int16_t z;
} lsm303MagData;
/*=========================================================================*/

Expand All @@ -136,9 +136,9 @@
-----------------------------------------------------------------------*/
typedef struct lsm303AccelData_s
{
float x;
float y;
float z;
int16_t x;
int16_t y;
int16_t z;
} lsm303AccelData;
/*=========================================================================*/

Expand All @@ -158,7 +158,7 @@ class Adafruit_LSM303_Accel_Unified : public Adafruit_Sensor
bool getEvent(sensors_event_t*);
void getSensor(sensor_t*);

lsm303AccelData accelData; // Last read accelerometer data will be available here
lsm303AccelData raw; // Last read accelerometer data will be available here

private:
int32_t _sensorID;
Expand All @@ -181,13 +181,13 @@ class Adafruit_LSM303_Mag_Unified : public Adafruit_Sensor
bool getEvent(sensors_event_t*);
void getSensor(sensor_t*);

lsm303MagData magData; // Last read magnetometer data will be available here
lsm303MagData raw; // Last read magnetometer data will be available here
lsm303MagGain magGain;
bool autoRangeEnabled;

private:
int32_t _sensorID;

void write8(byte address, byte reg, byte value);
byte read8(byte address, byte reg);
void read(void);
Expand Down
6 changes: 3 additions & 3 deletions examples/accelsensor/accelsensor.pde
Expand Up @@ -55,9 +55,9 @@ void loop(void)
/* Note: You can also get the raw (non unified values) for */
/* the last data sample as follows. The .getEvent call populates */
/* the raw values used below. */
//Serial.print("X Raw: "); Serial.print(accel.accelData.x); Serial.print(" ");
//Serial.print("Y Raw: "); Serial.print(accel.accelData.y); Serial.print(" ");
//Serial.print("Z Raw: "); Serial.print(accel.accelData.z); Serial.println("");
//Serial.print("X Raw: "); Serial.print(accel.raw.x); Serial.print(" ");
//Serial.print("Y Raw: "); Serial.print(accel.raw.y); Serial.print(" ");
//Serial.print("Z Raw: "); Serial.print(accel.raw.z); Serial.println("");

/* Delay before the next sample */
delay(500);
Expand Down
6 changes: 3 additions & 3 deletions examples/magsensor/magsensor.pde
Expand Up @@ -58,9 +58,9 @@ void loop(void)
/* Note: You can also get the raw (non unified values) for */
/* the last data sample as follows. The .getEvent call populates */
/* the raw values used below. */
// Serial.print("X Raw: "); Serial.print(mag.magData.x); Serial.print(" ");
// Serial.print("Y Raw: "); Serial.print(mag.magData.y); Serial.print(" ");
// Serial.print("Z Raw: "); Serial.print(mag.magData.z); Serial.println("");
// Serial.print("X Raw: "); Serial.print(mag.raw.x); Serial.print(" ");
// Serial.print("Y Raw: "); Serial.print(mag.raw.y); Serial.print(" ");
// Serial.print("Z Raw: "); Serial.print(mag.raw.z); Serial.println("");

/* Delay before the next sample */
delay(500);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=Adafruit LSM303DLHC
version=1.0.1
version=1.0.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Unified sensor driver for Adafruit's LSM303 Breakout (Accelerometer + Magnetometer)
Expand Down

0 comments on commit 421141d

Please sign in to comment.