Framework of classes and program to measure tilt angles using accelerometers
Fork of tilt_angles by
ENGO333_I2C.cpp@1:64f1aefe1842, 2016-11-25 (annotated)
- Committer:
- mpetovello
- Date:
- Fri Nov 25 15:18:28 2016 +0000
- Revision:
- 1:64f1aefe1842
- Parent:
- 0:3bffc1862262
Removed MMA7660 library (unnecessary)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mpetovello | 0:3bffc1862262 | 1 | #include "ENGO333_I2C.h" |
mpetovello | 0:3bffc1862262 | 2 | |
mpetovello | 0:3bffc1862262 | 3 | ENGO333_I2C::ENGO333_I2C(PinName sda, PinName scl) : i2c(sda, scl) |
mpetovello | 0:3bffc1862262 | 4 | { |
mpetovello | 0:3bffc1862262 | 5 | // Do nothing |
mpetovello | 0:3bffc1862262 | 6 | } |
mpetovello | 0:3bffc1862262 | 7 | |
mpetovello | 0:3bffc1862262 | 8 | ENGO333_I2C::~ENGO333_I2C() |
mpetovello | 0:3bffc1862262 | 9 | { |
mpetovello | 0:3bffc1862262 | 10 | // Do nothing |
mpetovello | 0:3bffc1862262 | 11 | } |
mpetovello | 0:3bffc1862262 | 12 | |
mpetovello | 0:3bffc1862262 | 13 | void ENGO333_I2C::setSpeed(int freq) |
mpetovello | 0:3bffc1862262 | 14 | { |
mpetovello | 0:3bffc1862262 | 15 | this->i2c.frequency(freq); |
mpetovello | 0:3bffc1862262 | 16 | } |
mpetovello | 0:3bffc1862262 | 17 | |
mpetovello | 0:3bffc1862262 | 18 | void ENGO333_I2C::writeOneByte(char deviceAddress, char registerAddress, char value) |
mpetovello | 0:3bffc1862262 | 19 | { |
mpetovello | 0:3bffc1862262 | 20 | char temp[2]; |
mpetovello | 0:3bffc1862262 | 21 | temp[0] = registerAddress; |
mpetovello | 0:3bffc1862262 | 22 | temp[1] = value; |
mpetovello | 0:3bffc1862262 | 23 | this->i2c.write(deviceAddress, temp, 2); |
mpetovello | 0:3bffc1862262 | 24 | } |
mpetovello | 0:3bffc1862262 | 25 | |
mpetovello | 0:3bffc1862262 | 26 | char ENGO333_I2C::readOneByte(char deviceAddress, char registerAddress) |
mpetovello | 0:3bffc1862262 | 27 | { |
mpetovello | 0:3bffc1862262 | 28 | char temp = 0; |
mpetovello | 0:3bffc1862262 | 29 | this->i2c.write(deviceAddress, ®isterAddress, 1); |
mpetovello | 0:3bffc1862262 | 30 | this->i2c.read(deviceAddress, &temp, 1); |
mpetovello | 0:3bffc1862262 | 31 | return (char)temp; |
mpetovello | 0:3bffc1862262 | 32 | } |
mpetovello | 0:3bffc1862262 | 33 | |
mpetovello | 0:3bffc1862262 | 34 | void ENGO333_I2C::readBytes(char deviceAddress, char registerAddress, char* value, int length) |
mpetovello | 0:3bffc1862262 | 35 | { |
mpetovello | 0:3bffc1862262 | 36 | this->i2c.write(deviceAddress, ®isterAddress, 1); |
mpetovello | 0:3bffc1862262 | 37 | this->i2c.read(deviceAddress, value, length); |
mpetovello | 0:3bffc1862262 | 38 | } |
mpetovello | 0:3bffc1862262 | 39 |