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.
Fork of ESDC2014 by
compass.h@4:a377ecb9364f, 2014-07-04 (annotated)
- Committer:
- terryLAI
- Date:
- Fri Jul 04 13:05:15 2014 +0000
- Revision:
- 4:a377ecb9364f
- Parent:
- 3:4306d042af6f
test;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| terryLAI | 4:a377ecb9364f | 1 | #ifndef _COMPASS_H |
| terryLAI | 4:a377ecb9364f | 2 | #define _COMPASS_H |
| TonyYI | 0:3417ca0a36c0 | 3 | |
| TonyYI | 0:3417ca0a36c0 | 4 | #include "mbed.h" |
| terryLAI | 1:cbec1283a16a | 5 | #include "define.h" |
| terryLAI | 4:a377ecb9364f | 6 | #include "math.h" |
| TonyYI | 0:3417ca0a36c0 | 7 | |
| terryLAI | 1:cbec1283a16a | 8 | |
| terryLAI | 4:a377ecb9364f | 9 | #define RUN_MSB 0xC7 |
| terryLAI | 4:a377ecb9364f | 10 | #define RUN_LSB 0x10 |
| terryLAI | 4:a377ecb9364f | 11 | #define ACK_RUN_MSB 0xC7 |
| terryLAI | 4:a377ecb9364f | 12 | #define ACK_RUN_LSB 0x10 |
| TonyYI | 0:3417ca0a36c0 | 13 | |
| terryLAI | 4:a377ecb9364f | 14 | #define STOP_MSB 0xC6 |
| terryLAI | 4:a377ecb9364f | 15 | #define STOP_LSB 0x10 |
| terryLAI | 4:a377ecb9364f | 16 | #define ACK_STOP_MSB 0xD6 |
| terryLAI | 4:a377ecb9364f | 17 | #define ACK_STOP_LSB 0x01 |
| TonyYI | 0:3417ca0a36c0 | 18 | |
| terryLAI | 4:a377ecb9364f | 19 | #define RESUME_MSB 0xD1 |
| terryLAI | 4:a377ecb9364f | 20 | #define RESUME_LSB 0x10 |
| terryLAI | 4:a377ecb9364f | 21 | #define ACK_RESUME_MSB 0xD1 |
| terryLAI | 4:a377ecb9364f | 22 | #define ACK_RESUME_LSB 0x10 |
| terryLAI | 1:cbec1283a16a | 23 | |
| terryLAI | 4:a377ecb9364f | 24 | #define RST_MSB 0xC2 |
| terryLAI | 4:a377ecb9364f | 25 | #define RST_LSB 0x10 |
| TonyYI | 0:3417ca0a36c0 | 26 | |
| TonyYI | 0:3417ca0a36c0 | 27 | #define DECLINATIONANGLE -0.0457 |
| TonyYI | 0:3417ca0a36c0 | 28 | |
| terryLAI | 4:a377ecb9364f | 29 | #define DATA_BUFFER_SIZE 256 |
| TonyYI | 0:3417ca0a36c0 | 30 | |
| terryLAI | 4:a377ecb9364f | 31 | class Compass |
| TonyYI | 0:3417ca0a36c0 | 32 | { |
| TonyYI | 0:3417ca0a36c0 | 33 | public: |
| terryLAI | 4:a377ecb9364f | 34 | Compass(MySerial _compassSerial); |
| terryLAI | 4:a377ecb9364f | 35 | ~Compass(); |
| terryLAI | 4:a377ecb9364f | 36 | void putToBuffer(uint8_t _x); |
| terryLAI | 4:a377ecb9364f | 37 | void clearBuffer(); |
| terryLAI | 4:a377ecb9364f | 38 | int read(); |
| TonyYI | 0:3417ca0a36c0 | 39 | |
| terryLAI | 4:a377ecb9364f | 40 | private: |
| terryLAI | 4:a377ecb9364f | 41 | MySerial* _compassSerial; |
| terryLAI | 4:a377ecb9364f | 42 | MySerial* temp; |
| terryLAI | 4:a377ecb9364f | 43 | uint8_t* buffer; |
| terryLAI | 4:a377ecb9364f | 44 | uint8_t _MSB; |
| terryLAI | 4:a377ecb9364f | 45 | uint8_t _LSB; |
| terryLAI | 4:a377ecb9364f | 46 | |
| terryLAI | 4:a377ecb9364f | 47 | uint8_t _in; |
| terryLAI | 4:a377ecb9364f | 48 | uint8_t _out; |
| TonyYI | 0:3417ca0a36c0 | 49 | |
| terryLAI | 4:a377ecb9364f | 50 | uint32_t add; |
| terryLAI | 4:a377ecb9364f | 51 | |
| TonyYI | 3:4306d042af6f | 52 | uint16_t _degree; |
| TonyYI | 0:3417ca0a36c0 | 53 | |
| TonyYI | 3:4306d042af6f | 54 | void write2Bytes(char msb, char lsb); |
| terryLAI | 1:cbec1283a16a | 55 | void run(); |
| terryLAI | 1:cbec1283a16a | 56 | void stop(); |
| terryLAI | 1:cbec1283a16a | 57 | void resume(); |
| terryLAI | 1:cbec1283a16a | 58 | void reset(); |
| TonyYI | 0:3417ca0a36c0 | 59 | }; |
| TonyYI | 0:3417ca0a36c0 | 60 | |
| terryLAI | 4:a377ecb9364f | 61 | #endif |
