df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
dupm2216
Date:
Sat Jan 14 23:32:29 2017 +0000
Revision:
4:303fb83498fd
Parent:
3:1a9d0f0a50bf
Child:
5:f59b51ac4b40
Add function is_almost_equal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dupm2216 3:1a9d0f0a50bf 1 #ifndef ACCELEROMETER_HPP
dupm2216 3:1a9d0f0a50bf 2 #define ACCELEROMETER_HPP
dupm2216 1:7becb0e903e3 3
dupm2216 1:7becb0e903e3 4 #include "mbed.h"
dupm2216 1:7becb0e903e3 5
dupm2216 1:7becb0e903e3 6 const int NUMBER_OF_DATA_REGISTERS = 6;
dupm2216 1:7becb0e903e3 7 const char OUT_X_MSB_REGISTER = 0x01;
dupm2216 1:7becb0e903e3 8 const char OUT_X_LSB_REGISTER = 0x02;
dupm2216 1:7becb0e903e3 9 const char OUT_Y_MSB_REGISTER = 0x03;
dupm2216 1:7becb0e903e3 10 const char OUT_Y_LSB_REGISTER = 0x04;
dupm2216 1:7becb0e903e3 11 const char OUT_Z_MSB_REGISTER = 0x05;
dupm2216 1:7becb0e903e3 12 const char OUT_Z_LSB_REGISTER = 0x06;
dupm2216 1:7becb0e903e3 13
dupm2216 1:7becb0e903e3 14 const char WHO_AM_I_REGISTER = 0x0D;
dupm2216 1:7becb0e903e3 15 const char CTRL_REG1_REGISTER_ADDRESS = 0x2A;
dupm2216 1:7becb0e903e3 16
dupm2216 3:1a9d0f0a50bf 17 const int I2C_ACCELEROMETER_ADDRESS = 0x1D;
dupm2216 3:1a9d0f0a50bf 18
dupm2216 3:1a9d0f0a50bf 19 enum Axis
dupm2216 3:1a9d0f0a50bf 20 {
dupm2216 3:1a9d0f0a50bf 21 AXIS_X,
dupm2216 3:1a9d0f0a50bf 22 AXIS_Y,
dupm2216 3:1a9d0f0a50bf 23 AXIS_Z,
dupm2216 3:1a9d0f0a50bf 24 AXIS_INVALID
dupm2216 3:1a9d0f0a50bf 25 };
dupm2216 3:1a9d0f0a50bf 26
dupm2216 3:1a9d0f0a50bf 27 int raw_axis_data_to_int(signed char raw_axis_data);
dupm2216 3:1a9d0f0a50bf 28 void test_raw_axis_data_to_int();
dupm2216 3:1a9d0f0a50bf 29 char get_axis_register(Axis axis);
dupm2216 4:303fb83498fd 30 bool is_almost_equal(double a, double b, double tolerance);
dupm2216 3:1a9d0f0a50bf 31
dupm2216 1:7becb0e903e3 32 class Accelerometer
dupm2216 1:7becb0e903e3 33 {
dupm2216 3:1a9d0f0a50bf 34 public:
dupm2216 3:1a9d0f0a50bf 35 Accelerometer(
dupm2216 3:1a9d0f0a50bf 36 PinName sda_pin,
dupm2216 3:1a9d0f0a50bf 37 PinName scl_pin,
dupm2216 3:1a9d0f0a50bf 38 const int slave_address = I2C_ACCELEROMETER_ADDRESS
dupm2216 3:1a9d0f0a50bf 39 );
dupm2216 1:7becb0e903e3 40
dupm2216 1:7becb0e903e3 41 void write_register(const char register_address, const char new_value);
dupm2216 1:7becb0e903e3 42 char read_register(const char register_address);
dupm2216 1:7becb0e903e3 43
dupm2216 3:1a9d0f0a50bf 44 //axis_data must be an array of length 6
dupm2216 3:1a9d0f0a50bf 45 void read_all_axis(signed char* axis_data);
dupm2216 1:7becb0e903e3 46 void print_all_axis_data();
dupm2216 1:7becb0e903e3 47
dupm2216 1:7becb0e903e3 48 void set_standby();
dupm2216 1:7becb0e903e3 49 void set_active();
dupm2216 1:7becb0e903e3 50 void init();
dupm2216 3:1a9d0f0a50bf 51
dupm2216 3:1a9d0f0a50bf 52 //Read data from the 8 most significant bits (MSB) of a given axis
dupm2216 3:1a9d0f0a50bf 53 int read_axis_data_8_bits(Axis axis);
dupm2216 1:7becb0e903e3 54
dupm2216 1:7becb0e903e3 55 private:
dupm2216 3:1a9d0f0a50bf 56 I2C device;
dupm2216 1:7becb0e903e3 57 const int slave_address;
dupm2216 3:1a9d0f0a50bf 58 };
dupm2216 3:1a9d0f0a50bf 59
dupm2216 3:1a9d0f0a50bf 60 #endif