![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code to control a Traxster robot using a Wimote and Android app
Fork of BlueUSB by
BlueUSB/Utils.cpp@1:accdaa84fe8d, 2014-04-28 (annotated)
- Committer:
- aswild
- Date:
- Mon Apr 28 16:06:32 2014 +0000
- Revision:
- 1:accdaa84fe8d
- Parent:
- Utils.cpp@0:606b230e5b4a
Wiimote controlled Traxster robot using BlueUSB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peterbarrett1967 | 0:606b230e5b4a | 1 | |
peterbarrett1967 | 0:606b230e5b4a | 2 | |
peterbarrett1967 | 0:606b230e5b4a | 3 | #include "mbed.h" |
peterbarrett1967 | 0:606b230e5b4a | 4 | #include "Utils.h" |
peterbarrett1967 | 0:606b230e5b4a | 5 | |
peterbarrett1967 | 0:606b230e5b4a | 6 | void printfBytes(const char* s, const u8* data, int len) |
peterbarrett1967 | 0:606b230e5b4a | 7 | { |
peterbarrett1967 | 0:606b230e5b4a | 8 | printf("%s %d:",s,len); |
peterbarrett1967 | 0:606b230e5b4a | 9 | if (len > 256) |
peterbarrett1967 | 0:606b230e5b4a | 10 | len = 256; |
peterbarrett1967 | 0:606b230e5b4a | 11 | while (len-- > 0) |
peterbarrett1967 | 0:606b230e5b4a | 12 | printf(" %02X",*data++); |
peterbarrett1967 | 0:606b230e5b4a | 13 | printf("\n"); |
peterbarrett1967 | 0:606b230e5b4a | 14 | } |
peterbarrett1967 | 0:606b230e5b4a | 15 | |
peterbarrett1967 | 0:606b230e5b4a | 16 | void printHexLine(const u8* d, int addr, int len) |
peterbarrett1967 | 0:606b230e5b4a | 17 | { |
peterbarrett1967 | 0:606b230e5b4a | 18 | printf("%04X ",addr); |
peterbarrett1967 | 0:606b230e5b4a | 19 | int i; |
peterbarrett1967 | 0:606b230e5b4a | 20 | for (i = 0; i < len; i++) |
peterbarrett1967 | 0:606b230e5b4a | 21 | printf("%02X ",d[i]); |
peterbarrett1967 | 0:606b230e5b4a | 22 | for (;i < 16; i++) |
peterbarrett1967 | 0:606b230e5b4a | 23 | printf(" "); |
peterbarrett1967 | 0:606b230e5b4a | 24 | char s[16+1]; |
peterbarrett1967 | 0:606b230e5b4a | 25 | memset(s,0,sizeof(s)); |
peterbarrett1967 | 0:606b230e5b4a | 26 | for (i = 0; i < len; i++) |
peterbarrett1967 | 0:606b230e5b4a | 27 | { |
peterbarrett1967 | 0:606b230e5b4a | 28 | int c = d[i]; |
peterbarrett1967 | 0:606b230e5b4a | 29 | if (c < 0x20 || c > 0x7E) |
peterbarrett1967 | 0:606b230e5b4a | 30 | c = '.'; |
peterbarrett1967 | 0:606b230e5b4a | 31 | s[i] = c; |
peterbarrett1967 | 0:606b230e5b4a | 32 | } |
peterbarrett1967 | 0:606b230e5b4a | 33 | printf("%s\n",s); |
peterbarrett1967 | 0:606b230e5b4a | 34 | } |
peterbarrett1967 | 0:606b230e5b4a | 35 | |
peterbarrett1967 | 0:606b230e5b4a | 36 | void printHex(const u8* d, int len) |
peterbarrett1967 | 0:606b230e5b4a | 37 | { |
peterbarrett1967 | 0:606b230e5b4a | 38 | int addr = 0; |
peterbarrett1967 | 0:606b230e5b4a | 39 | while (len) |
peterbarrett1967 | 0:606b230e5b4a | 40 | { |
peterbarrett1967 | 0:606b230e5b4a | 41 | int count = len; |
peterbarrett1967 | 0:606b230e5b4a | 42 | if (count > 16) |
peterbarrett1967 | 0:606b230e5b4a | 43 | count = 16; |
peterbarrett1967 | 0:606b230e5b4a | 44 | printHexLine(d+addr,addr,count); |
peterbarrett1967 | 0:606b230e5b4a | 45 | addr += 16; |
peterbarrett1967 | 0:606b230e5b4a | 46 | len -= count; |
peterbarrett1967 | 0:606b230e5b4a | 47 | } |
peterbarrett1967 | 0:606b230e5b4a | 48 | } |