2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-07-22 18:04:00 -04:00
|
|
|
#include "interfaces/Accelerometer.h"
|
2014-06-18 15:38:02 -04:00
|
|
|
#include "I2C.h"
|
2014-12-30 18:20:35 -08:00
|
|
|
#include "LiveWindow/LiveWindowSendable.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ADXL345 Accelerometer on I2C.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* 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).
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class ADXL345_I2C : public Accelerometer,
|
|
|
|
|
public I2C,
|
|
|
|
|
public LiveWindowSendable {
|
|
|
|
|
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 Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
|
|
|
|
|
struct AllAxes {
|
|
|
|
|
double XAxis;
|
|
|
|
|
double YAxis;
|
|
|
|
|
double ZAxis;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ADXL345_I2C(Port port, Range range = kRange_2G);
|
|
|
|
|
virtual ~ADXL345_I2C();
|
|
|
|
|
|
|
|
|
|
// Accelerometer interface
|
|
|
|
|
virtual void SetRange(Range range) override;
|
|
|
|
|
virtual double GetX() override;
|
|
|
|
|
virtual double GetY() override;
|
|
|
|
|
virtual double GetZ() override;
|
|
|
|
|
|
|
|
|
|
virtual double GetAcceleration(Axes axis);
|
|
|
|
|
virtual AllAxes GetAccelerations();
|
|
|
|
|
|
|
|
|
|
virtual std::string GetSmartDashboardType() const override;
|
|
|
|
|
virtual void InitTable(ITable *subtable) override;
|
|
|
|
|
virtual void UpdateTable() override;
|
|
|
|
|
virtual ITable *GetTable() const override;
|
|
|
|
|
virtual void StartLiveWindowMode() override {}
|
|
|
|
|
virtual void StopLiveWindowMode() override {}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// I2C* m_i2c;
|
|
|
|
|
private:
|
|
|
|
|
ITable *m_table;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|