mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Change-Id: If6082f6b92b4be5e328278ba536d5a7681082c9f (+4 squashed commit) Squashed commit: [86b4ae7] * Port I2C to roboRIO in JNI and Java. Left read method as a transaction and added readOnly. Left write as a single byte and added writeBulk. Need to go back to C++ and update to match. Change-Id: I290d84211a4b7bb942d785730c0e6929449cf69f [7d37419] * Remove HiTechnic sensors from Java. May be added back later as examples Change-Id: Ie93e23a70fd953c99c03d50d9529220f86d32e03 [e62bfbf] * I2C ported to roboRIO i2clib in HAL and C++ Change-Id: Idb0e8cee5a1e8c1a0b0733ca94b528f659352915 [1059a48] * Remove HiTechnic sensors (Lego connector) may be added back as examples later Change-Id: I84b8e1e022db2c69d487ed9ad5b3ec0e7ea57282 (+2 squashed commit) Squashed commit: [e62bfbf] * I2C ported to roboRIO i2clib in HAL and C++ Change-Id: Idb0e8cee5a1e8c1a0b0733ca94b528f659352915 [1059a48] * Remove HiTechnic sensors (Lego connector) may be added back as examples later Change-Id: I84b8e1e022db2c69d487ed9ad5b3ec0e7ea57282
47 lines
1.6 KiB
C++
47 lines
1.6 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
/*----------------------------------------------------------------------------*/
|
|
#pragma once
|
|
|
|
#include "I2C.h"
|
|
|
|
/**
|
|
* ADXL345 Accelerometer on I2C.
|
|
*
|
|
* This class allows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
|
|
* This class assumes the default (not alternate) sensor address of 0x1D (7-bit address).
|
|
*/
|
|
class ADXL345_I2C : public I2C
|
|
{
|
|
protected:
|
|
static const uint8_t kAddress = 0x1D;
|
|
static const uint8_t kPowerCtlRegister = 0x2D;
|
|
static const uint8_t kDataFormatRegister = 0x31;
|
|
static const uint8_t kDataRegister = 0x32;
|
|
static constexpr double kGsPerLSB = 0.00390625;
|
|
enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04};
|
|
enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20,
|
|
kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04};
|
|
|
|
public:
|
|
enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03};
|
|
enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04};
|
|
struct AllAxes
|
|
{
|
|
double XAxis;
|
|
double YAxis;
|
|
double ZAxis;
|
|
};
|
|
|
|
public:
|
|
ADXL345_I2C(Port port, DataFormat_Range range=kRange_2G);
|
|
virtual ~ADXL345_I2C();
|
|
virtual double GetAcceleration(Axes axis);
|
|
virtual AllAxes GetAccelerations();
|
|
|
|
protected:
|
|
//I2C* m_i2c;
|
|
};
|