iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_u16toa.c Source File

u8g_u16toa.c

00001 /*
00002 
00003   u8g_u16toa.c
00004 
00005 
00006   Universal 8bit Graphics Library
00007   
00008   Copyright (c) 2012, olikraus@gmail.com
00009   All rights reserved.
00010 
00011   Redistribution and use in source and binary forms, with or without modification, 
00012   are permitted provided that the following conditions are met:
00013 
00014   * Redistributions of source code must retain the above copyright notice, this list 
00015     of conditions and the following disclaimer.
00016     
00017   * Redistributions in binary form must reproduce the above copyright notice, this 
00018     list of conditions and the following disclaimer in the documentation and/or other 
00019     materials provided with the distribution.
00020 
00021   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00022   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00023   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00024   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00025   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00026   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00028   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00029   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00030   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00031   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00032   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00033   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00034   
00035 */
00036 
00037 
00038 #include "u8g.h"
00039 
00040 const char *u8g_u16toap(char * dest, uint16_t v)
00041 {
00042   uint8_t pos;
00043   uint8_t d;
00044   uint16_t c;
00045   c = 10000;
00046   for( pos = 0; pos < 5; pos++ )
00047   {
00048       d = '0';
00049       while( v >= c )
00050       {
00051     v -= c;
00052     d++;
00053       }
00054       dest[pos] = d;
00055       c /= 10;
00056   }  
00057   dest[5] = '\0';
00058   return dest;
00059 }
00060 
00061 /* v = value, d = number of digits */
00062 const char *u8g_u16toa(uint16_t v, uint8_t d)
00063 {
00064   static char buf[6];
00065   d = 5-d;
00066   return u8g_u16toap(buf, v) + d;
00067 }
00068 
00069