Adafruit 9DOF - LSM303DLHC
Fork of LSM303DLHC by
Revision 1:cd027bdb4892, committed 2016-07-14
- Comitter:
- afmiee
- Date:
- Thu Jul 14 20:23:10 2016 +0000
- Parent:
- 0:ffed7ef0b248
- Commit message:
- First Revision of 9DOF with nRF51, Adafruit 9DOF and sparkfun microSD shield.
Changed in this revision
LSM303DLHC.cpp | Show annotated file Show diff for this revision Revisions of this file |
Vector.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r ffed7ef0b248 -r cd027bdb4892 LSM303DLHC.cpp --- a/LSM303DLHC.cpp Sat Apr 09 04:26:50 2016 +0000 +++ b/LSM303DLHC.cpp Thu Jul 14 20:23:10 2016 +0000 @@ -29,6 +29,7 @@ _data[1] = 0x2F; // 0b00101111 _device.write(ACC_ADDRESS, _data, 2); } + void LSM303DLHC::read(int a[3], int m[3]) {
diff -r ffed7ef0b248 -r cd027bdb4892 Vector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Vector.h Thu Jul 14 20:23:10 2016 +0000 @@ -0,0 +1,47 @@ +#ifndef VECTOR_H +#define VECTOR_H + +#include "mbed.h" + +class Vector { +public: + float x, y, z; + + Vector(): x(0), y(0), z(0) {} + + Vector(float x, float y, float z) : x(x), y(y), z(z) {} + + Vector(const Vector& v) { + x = v.x, y = v.y, z = v.z; + } + + Vector product(const Vector& v) { + return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); + } + + float dot(const Vector& v) { + return x * v.x + y * v.y + z * v.z; + } + + Vector scale(const float c) { + return Vector(c * x, c * y, c * z); + } + + float norm() { + return sqrt(x * x + y * y + z * z); + } + + Vector operator*(const Vector& v) { + return product(v); + } + + Vector operator /=(float c) { + return *this = scale(1 / c); + } + + Vector operator *=(float c) { + return *this = scale(c); + } +}; + +#endif \ No newline at end of file