/** * Get the acceleration of all axes in Gs. * * @return An object containing the acceleration measured on each axis of the * ADXL345 in Gs. */ ADXL345_I2C::AllAxes ADXL345_I2C::GetAccelerations() { AllAxes data = AllAxes(); int16_t rawData[3]; Read(kDataRegister, sizeof(rawData), (uint8_t *)rawData); data.XAxis = rawData[0] * kGsPerLSB; data.YAxis = rawData[1] * kGsPerLSB; data.ZAxis = rawData[2] * kGsPerLSB; return data; }
/** * Get the acceleration of all axes in Gs. * * @return An object containing the acceleration measured on each axis of the ADXL345 in Gs. */ ADXL345_SPI::AllAxes ADXL345_SPI::GetAccelerations() { AllAxes data = AllAxes(); uint8_t dataBuffer[7] = {0,0,0,0,0,0,0}; int16_t rawData[3]; if (m_spi) { // Select the data address. dataBuffer[0] = (kAddress_Read | kAddress_MultiByte | kDataRegister); m_spi->Transaction(dataBuffer, dataBuffer, 7); for (int32_t i=0; i<3; i++) { // Sensor is little endian... swap bytes rawData[i] = dataBuffer[i*2+2] << 8 | dataBuffer[i*2+1]; } data.XAxis = rawData[0] * kGsPerLSB; data.YAxis = rawData[1] * kGsPerLSB; data.ZAxis = rawData[2] * kGsPerLSB; } return data; }