From 376fc6be6fd344a9c428667422ef9ac532327a91 Mon Sep 17 00:00:00 2001 From: Joe Ross Date: Thu, 31 Dec 2015 14:56:11 -0800 Subject: [PATCH] Artf4179: Allow alternate I2C addresses for ADXL345_I2C Change-Id: I43e65251b4a7a5b90afb698b753b86672110e837 --- wpilibc/Athena/include/ADXL345_I2C.h | 2 +- wpilibc/Athena/src/ADXL345_I2C.cpp | 5 +++-- .../java/edu/wpi/first/wpilibj/ADXL345_I2C.java | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/wpilibc/Athena/include/ADXL345_I2C.h b/wpilibc/Athena/include/ADXL345_I2C.h index e55e00724e..53a608ae2f 100644 --- a/wpilibc/Athena/include/ADXL345_I2C.h +++ b/wpilibc/Athena/include/ADXL345_I2C.h @@ -51,7 +51,7 @@ class ADXL345_I2C : public Accelerometer, }; public: - explicit ADXL345_I2C(Port port, Range range = kRange_2G); + explicit ADXL345_I2C(Port port, Range range = kRange_2G, int deviceAddress = kAddress); virtual ~ADXL345_I2C() = default; ADXL345_I2C(const ADXL345_I2C&) = delete; diff --git a/wpilibc/Athena/src/ADXL345_I2C.cpp b/wpilibc/Athena/src/ADXL345_I2C.cpp index 000d4b8570..92cdb65aa2 100644 --- a/wpilibc/Athena/src/ADXL345_I2C.cpp +++ b/wpilibc/Athena/src/ADXL345_I2C.cpp @@ -17,12 +17,13 @@ const uint8_t ADXL345_I2C::kDataRegister; constexpr double ADXL345_I2C::kGsPerLSB; /** - * Constructor. + * Constructs the ADXL345 Accelerometer over I2C. * * @param port The I2C port the accelerometer is attached to * @param range The range (+ or -) that the accelerometer will measure. + * @param deviceAddress the I2C address of the accelerometer (0x1D or 0x53) */ -ADXL345_I2C::ADXL345_I2C(Port port, Range range) : I2C(port, kAddress) { +ADXL345_I2C::ADXL345_I2C(Port port, Range range, int deviceAddress) : I2C(port, deviceAddress) { // Turn on the measurements Write(kPowerCtlRegister, kPowerCtl_Measure); // Specify the data format to read diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java index e94b0a8e4f..fd9049e791 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java @@ -58,13 +58,24 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindow private I2C m_i2c; /** - * Constructor. + * Constructs the ADXL345 Accelerometer with I2C address 0x1D. *$ * @param port The I2C port the accelerometer is attached to * @param range The range (+ or -) that the accelerometer will measure. */ public ADXL345_I2C(I2C.Port port, Range range) { - m_i2c = new I2C(port, kAddress); + this(port, range, kAddress); + } + + /** + * Constructs the ADXL345 Accelerometer over I2C. + *$ + * @param port The I2C port the accelerometer is attached to + * @param range The range (+ or -) that the accelerometer will measure. + * @param the I2C address of the accelerometer (0x1D or 0x53) + */ + public ADXL345_I2C(I2C.Port port, Range range, int deviceAddress) { + m_i2c = new I2C(port, deviceAddress); // Turn on the measurements m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);