Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dsp mbed-rtos mbed
Dependents: MAE433_Library_Tester RobotBalancerv2
FXOS8700CQ.hpp
00001 /** 00002 * @file FXOS8700CQ.hpp 00003 * @author Weimen Li 00004 * @date June 5th, 2016 00005 * @class FXOS8700CQ 00006 * @brief This class represents the FXOS8700CQ sensor. Only accelerometer reading is currently supported. 00007 * @remark WARNING: I2C Reading is unreliable when built outside of the mbed compiler. If you're compiling this outside 00008 * of the mBed compiler, ensure that the accelerometer is reading reliably. My testing shows that the readings often glitch. 00009 */ 00010 00011 #ifndef FXOS8700CQ_HPP_ 00012 #define FXOS8700CQ_HPP_ 00013 #include <mbed.h> 00014 00015 class FXOS8700CQ { 00016 public: 00017 /// Possible accelerometer sensitivity settings. 00018 enum AccelerometerSensitivity {TWO, FOUR, EIGHT}; 00019 /** 00020 * @brief Constructor for the FXOS8700CQ Accelerometer/Magnetometer. Pin assignments have default values for the K22F board. 00021 * @param SDA The SDA Pin. 00022 * @param SCL the SCL Pin. 00023 * @param INT1 The pin that the INT1 line is connected to. 00024 * @param INT2 The pin that the INT2 line is connect to. 00025 * @param setting (optional) The maximum measurement acceleration in g's. May be TWO, FOUR, or EIGHT for 00026 * +/- 2/4/8 g's. A smaller maximum measurement allows for greater sensitivity. 00027 */ 00028 FXOS8700CQ(PinName SDA = PTB3, PinName SCL = PTB2, PinName INT1 = PTD0, PinName INT2 = PTD1, AccelerometerSensitivity setting = TWO); 00029 virtual ~FXOS8700CQ(); 00030 /** 00031 * @brief Read data from the accelerometer. Takes pointers to floats that store these variables. 00032 * Example code: 00033 * @code 00034 * float xAccel; 00035 * float yAccel; 00036 * float zAccel; 00037 * ... 00038 * readAccelerometer(&xAccel, &yAccel, &zAccel); 00039 * ... 00040 * @endcode 00041 */ 00042 void readAccelerometer(float *xAccel, float *yAccel, float *zAccel); 00043 /** 00044 * @brief Set offset compensation values that are subtracted from the readings to zero them. 00045 */ 00046 void setOffset(float x, float y, float z) { 00047 xOffset = x; 00048 yOffset = y; 00049 zOffset = z; 00050 } 00051 private: 00052 /// Member function to handle data-ready interrupt. 00053 void dataReadyISR(void); 00054 private: 00055 /// I2C Object to handle bus communications. 00056 I2C I2CObj; 00057 /// Interrupt object for a data-ready signal. 00058 InterruptIn dataReadyInt; 00059 /// The accelerometer sensitivity setting specified by the caller. 00060 const AccelerometerSensitivity accelSensitivitySetting; 00061 /// The conversion constant to convert the read int16_t type data to a float. 00062 const float accelInt2Float; 00063 /// The latest x Acceleration value in g's. 00064 float lastxAccel; 00065 /// The latest y Acceleration value in g's. 00066 float lastyAccel; 00067 /// The latest z Acceleration values in g's. 00068 float lastzAccel; 00069 /// The x offset 00070 float xOffset; 00071 /// The y offset 00072 float yOffset; 00073 /// The z offset 00074 float zOffset; 00075 }; 00076 00077 #endif /* FXOS8700CQ_HPP_ */ 00078
Generated on Tue Jul 12 2022 16:20:51 by
1.7.2