Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
Accelerometer.hpp@1:7becb0e903e3, 2017-01-14 (annotated)
- Committer:
- dupm2216
- Date:
- Sat Jan 14 18:53:39 2017 +0000
- Revision:
- 1:7becb0e903e3
- Child:
- 3:1a9d0f0a50bf
Move Accelerometer to its own class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupm2216 | 1:7becb0e903e3 | 1 | #include <memory> |
dupm2216 | 1:7becb0e903e3 | 2 | |
dupm2216 | 1:7becb0e903e3 | 3 | #include "mbed.h" |
dupm2216 | 1:7becb0e903e3 | 4 | |
dupm2216 | 1:7becb0e903e3 | 5 | const int NUMBER_OF_DATA_REGISTERS = 6; |
dupm2216 | 1:7becb0e903e3 | 6 | const char OUT_X_MSB_REGISTER = 0x01; |
dupm2216 | 1:7becb0e903e3 | 7 | const char OUT_X_LSB_REGISTER = 0x02; |
dupm2216 | 1:7becb0e903e3 | 8 | const char OUT_Y_MSB_REGISTER = 0x03; |
dupm2216 | 1:7becb0e903e3 | 9 | const char OUT_Y_LSB_REGISTER = 0x04; |
dupm2216 | 1:7becb0e903e3 | 10 | const char OUT_Z_MSB_REGISTER = 0x05; |
dupm2216 | 1:7becb0e903e3 | 11 | const char OUT_Z_LSB_REGISTER = 0x06; |
dupm2216 | 1:7becb0e903e3 | 12 | |
dupm2216 | 1:7becb0e903e3 | 13 | const char WHO_AM_I_REGISTER = 0x0D; |
dupm2216 | 1:7becb0e903e3 | 14 | const char CTRL_REG1_REGISTER_ADDRESS = 0x2A; |
dupm2216 | 1:7becb0e903e3 | 15 | |
dupm2216 | 1:7becb0e903e3 | 16 | class Accelerometer |
dupm2216 | 1:7becb0e903e3 | 17 | { |
dupm2216 | 1:7becb0e903e3 | 18 | public: |
dupm2216 | 1:7becb0e903e3 | 19 | Accelerometer(I2C& device, const int slave_address); |
dupm2216 | 1:7becb0e903e3 | 20 | |
dupm2216 | 1:7becb0e903e3 | 21 | void write_register(const char register_address, const char new_value); |
dupm2216 | 1:7becb0e903e3 | 22 | char read_register(const char register_address); |
dupm2216 | 1:7becb0e903e3 | 23 | |
dupm2216 | 1:7becb0e903e3 | 24 | //axis_data must be an array of 6 bytes |
dupm2216 | 1:7becb0e903e3 | 25 | void read_all_axis(char* axis_data); |
dupm2216 | 1:7becb0e903e3 | 26 | void print_all_axis_data(); |
dupm2216 | 1:7becb0e903e3 | 27 | |
dupm2216 | 1:7becb0e903e3 | 28 | void set_standby(); |
dupm2216 | 1:7becb0e903e3 | 29 | void set_active(); |
dupm2216 | 1:7becb0e903e3 | 30 | void init(); |
dupm2216 | 1:7becb0e903e3 | 31 | |
dupm2216 | 1:7becb0e903e3 | 32 | private: |
dupm2216 | 1:7becb0e903e3 | 33 | I2C& device; |
dupm2216 | 1:7becb0e903e3 | 34 | const int slave_address; |
dupm2216 | 1:7becb0e903e3 | 35 | }; |