|
1 /* |
|
2 |
|
3 u8x8_u16toa.c |
|
4 |
|
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
6 |
|
7 Copyright (c) 2016, olikraus@gmail.com |
|
8 All rights reserved. |
|
9 |
|
10 Redistribution and use in source and binary forms, with or without modification, |
|
11 are permitted provided that the following conditions are met: |
|
12 |
|
13 * Redistributions of source code must retain the above copyright notice, this list |
|
14 of conditions and the following disclaimer. |
|
15 |
|
16 * Redistributions in binary form must reproduce the above copyright notice, this |
|
17 list of conditions and the following disclaimer in the documentation and/or other |
|
18 materials provided with the distribution. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
33 |
|
34 |
|
35 */ |
|
36 |
|
37 |
|
38 #include "u8x8.h" |
|
39 |
|
40 const char *u8x8_u16toap(char * dest, uint16_t v) |
|
41 { |
|
42 uint8_t pos; |
|
43 uint8_t d; |
|
44 uint16_t c; |
|
45 c = 10000; |
|
46 for( pos = 0; pos < 5; pos++ ) |
|
47 { |
|
48 d = '0'; |
|
49 while( v >= c ) |
|
50 { |
|
51 v -= c; |
|
52 d++; |
|
53 } |
|
54 dest[pos] = d; |
|
55 c /= 10; |
|
56 } |
|
57 dest[5] = '\0'; |
|
58 return dest; |
|
59 } |
|
60 |
|
61 /* v = value, d = number of digits */ |
|
62 const char *u8x8_u16toa(uint16_t v, uint8_t d) |
|
63 { |
|
64 static char buf[6]; |
|
65 d = 5-d; |
|
66 return u8x8_u16toap(buf, v) + d; |
|
67 } |
|
68 |