HapticLib  0.7
Haptic Feedback Library for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hl_debug.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Leonardo Guardati <leonardo@guardati.it>
3  *
4  * Permission to use, copy, modify, and/or distribute this
5  * software for any purpose with or without fee is hereby
6  * granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
10  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
11  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
12  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
15  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
17  * USE OR PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
79 #ifndef HL_DEBUG
80 #define HL_DEBUG
81 #undef HL_DEBUG
82 #endif
83 
84 #include "hl_debug.h"
85 
86 #ifdef HL_DEBUG
87 
126 uint32_t send_int(uint32_t val)
127 {
128  uint8_t i=0;
129  uint8_t front_pad_skip = 1;
130  uint8_t str_val[8] = { 0,0,0,0,0,0,0,0 };
131 
132  // Print in hex format.
133  for( i=0 ; i<8 ; i++ )
134  {
135  str_val[i] = (uint8_t) ( ( val >> (4*(7-i)) ) & 0xF ) ;
136  str_val[i] += ( str_val[i] > 9 ) ? ( 65 - 10 ) : 48 ;
137  }
138 
139  send_char('0');
140  send_char('x');
141 
142  for(i=0;i<8;i++)
143  {
144  if( front_pad_skip && str_val[i] == '0' && i != 7)
145  {
146  //Skip useless 0x00000...zeros
147  }
148  else {
149  send_char( str_val[i] );
150  front_pad_skip = 0;
151  }
152 
153  str_val[i] = 0;
154  }
155 
156  // For small number, print the decimal value too.
157  if( val < 10 )
158  str_val[0] = (uint8_t) ( val + 48 );
159  else if ( val < 100 )
160  {
161  str_val[0] = (uint8_t) ( val/10 + 48 );
162  str_val[1] = (uint8_t) ( val%10 + 48 );
163  }
164  else if ( val < 1000 )
165  {
166  str_val[0] = (uint8_t) ( val/100 + 48 );
167  str_val[1] = (uint8_t) ( (val%100)/10 + 48 );
168  str_val[2] = (uint8_t) ( (val%100)%10 + 48 );
169  }
170  else if ( val < 10000 )
171  {
172  str_val[0] = (uint8_t) ( val/1000 + 48 );
173  str_val[1] = (uint8_t) ( (val%1000)/100 + 48 );
174  str_val[2] = (uint8_t) ( ((val%1000)%100)/10 + 48 );
175  str_val[3] = (uint8_t) ( ((val%1000)%100)%10 + 48 );
176  }
177  else if (val < 100000 )
178  {
179  str_val[0] = (uint8_t) ( val/10000 + 48 );
180  str_val[1] = (uint8_t) ( (val%10000)/1000 + 48 );
181  str_val[2] = (uint8_t) ( ((val%10000)%1000)/100 + 48 );
182  str_val[3] = (uint8_t) ( (((val%10000)%1000)%100)/10 + 48 );
183  str_val[4] = (uint8_t) ( (((val%10000)%1000)%100)%10 + 48 );
184  }
185 
186  send_char(' ');
187  send_char('(');
188  for(i=0;i<8;i++)
189  {
190  send_char( str_val[i] );
191  str_val[i] = 0;
192  }
193  send_char(')');
194 
195  return val;
196 }
197 
226 void send_string(char *string)
227 {
228  uint8_t i=0;
229  while( string[i] != 0 && i < 255 )
230  send_char(string[i++]);
231 }
232 #endif