-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADXL345_I2C.h
53 lines (44 loc) · 1.68 KB
/
ADXL345_I2C.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#ifndef __ADXL345_I2C_h__
#define __ADXL345_I2C_h__
#include "SensorBase.h"
class I2C;
/**
* ADXL345 Accelerometer on I2C.
*
* This class alows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
* This class assumes the default (not alternate) sensor address of 0x3A (8-bit address).
*/
class ADXL345_I2C : public SensorBase
{
private:
static const UINT8 kAddress = 0x3A;
static const UINT8 kPowerCtlRegister = 0x2D;
static const UINT8 kDataFormatRegister = 0x31;
static const UINT8 kDataRegister = 0x32;
static const double kGsPerLSB = 0.004;
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:
explicit ADXL345_I2C(UINT32 slot, DataFormat_Range range=kRange_2G);
virtual ~ADXL345_I2C();
double GetAcceleration(Axes axis);
AllAxes GetAccelerations();
private:
I2C* m_i2c;
};
#endif