![](/media/cache/profiles/0f2c9a93eea6f38fabb3acb1c31488c6.50x50_q85.jpg)
A USB/360deg Rotational device, communicating via blue-tooth, test code
Dependencies: FatFileSystem mbed
Utils.h@0:87da38093be9, 2012-12-21 (annotated)
- Committer:
- lolpcc
- Date:
- Fri Dec 21 11:37:38 2012 +0000
- Revision:
- 0:87da38093be9
Used to test the Lazy Susan at work, hence the A2D code in Utils.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lolpcc | 0:87da38093be9 | 1 | |
lolpcc | 0:87da38093be9 | 2 | typedef unsigned char u8; |
lolpcc | 0:87da38093be9 | 3 | typedef unsigned short u16; |
lolpcc | 0:87da38093be9 | 4 | typedef unsigned long u32; |
lolpcc | 0:87da38093be9 | 5 | |
lolpcc | 0:87da38093be9 | 6 | void DelayMS(int ms); |
lolpcc | 0:87da38093be9 | 7 | int read_ana(void); |
lolpcc | 0:87da38093be9 | 8 | void send_out(char *buf); |
lolpcc | 0:87da38093be9 | 9 | void setup_rs232(void); |
lolpcc | 0:87da38093be9 | 10 | void printfBytes(const char* label,const u8* data, int len); |
lolpcc | 0:87da38093be9 | 11 | void printHex(const u8* d, int len); |
lolpcc | 0:87da38093be9 | 12 | |
lolpcc | 0:87da38093be9 | 13 | #ifndef min |
lolpcc | 0:87da38093be9 | 14 | #define min(_a,_b) ((_a) < (_b) ? (_a) : (_b)) |
lolpcc | 0:87da38093be9 | 15 | #endif |
lolpcc | 0:87da38093be9 | 16 | |
lolpcc | 0:87da38093be9 | 17 | inline int LE16(const u8* d) |
lolpcc | 0:87da38093be9 | 18 | { |
lolpcc | 0:87da38093be9 | 19 | return d[0] | (d[1] << 8); |
lolpcc | 0:87da38093be9 | 20 | } |
lolpcc | 0:87da38093be9 | 21 | |
lolpcc | 0:87da38093be9 | 22 | inline u32 BE32(const u8* d) |
lolpcc | 0:87da38093be9 | 23 | { |
lolpcc | 0:87da38093be9 | 24 | return (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | d[3]; |
lolpcc | 0:87da38093be9 | 25 | } |
lolpcc | 0:87da38093be9 | 26 | |
lolpcc | 0:87da38093be9 | 27 | inline void BE32(u32 n, u8* d) |
lolpcc | 0:87da38093be9 | 28 | { |
lolpcc | 0:87da38093be9 | 29 | d[0] = (u8)(n >> 24); |
lolpcc | 0:87da38093be9 | 30 | d[1] = (u8)(n >> 16); |
lolpcc | 0:87da38093be9 | 31 | d[2] = (u8)(n >> 8); |
lolpcc | 0:87da38093be9 | 32 | d[3] = (u8)n; |
lolpcc | 0:87da38093be9 | 33 | } |
lolpcc | 0:87da38093be9 | 34 | |
lolpcc | 0:87da38093be9 | 35 | inline void BE16(u32 n, u8* d) |
lolpcc | 0:87da38093be9 | 36 | { |
lolpcc | 0:87da38093be9 | 37 | d[0] = (u8)(n >> 8); |
lolpcc | 0:87da38093be9 | 38 | d[1] = (u8)n; |
lolpcc | 0:87da38093be9 | 39 | } |
lolpcc | 0:87da38093be9 | 40 | |
lolpcc | 0:87da38093be9 | 41 | inline const long ftoi(float x) { |
lolpcc | 0:87da38093be9 | 42 | return (-(long)(x < 0)) + (long)x; |
lolpcc | 0:87da38093be9 | 43 | } |