38 #pragma message ( "avr_utils.h included" ) 47 void UTILS_ReverseBuffer(uint8_t *Buffer,
size_t Size)
50 uint8_t *begin_ptr = Buffer;
51 uint8_t *end_ptr = Buffer + Size - 1;
52 for (
size_t i = 0; i < Size / 2; i++)
55 *end_ptr = *begin_ptr;
68 void UTILS_ReverseString(
char *Buffer)
72 char *begin_ptr = Buffer;
73 char *end_ptr = Buffer;
75 size = end_ptr - begin_ptr;
76 for (
size_t i = 0; i < size / 2; i++)
79 *end_ptr = *begin_ptr;
93 uint8_t UTILS_IntToString(
int Number,
char *Buffer)
104 Buffer[i++] = Number % 10 +
'0';
106 while ((Number /= 10) > 0);
111 UTILS_ReverseBuffer((uint8_t*)Buffer,i);
123 uint8_t UTILS_LongToString(
long Number,
char *Buffer)
134 Buffer[i++] = Number % 10 +
'0';
136 while ((Number /= 10) > 0);
141 UTILS_ReverseBuffer((uint8_t*)Buffer,i);
154 uint8_t UTILS_FloatToString(
float Number,
char *Buffer, uint8_t Precision)
156 int ipart = (int)Number;
157 float fpart = Number - (float)ipart;
158 size_t length1 = UTILS_IntToString(ipart,Buffer);
161 Buffer[length1] =
'.';
163 if ((fpart < 0.1 && fpart > 0.0) || (fpart < -0.0 && fpart > -1.0))
166 Buffer[length1] =
'0';
168 fpart = fpart * pow(10, Precision);
170 size_t length2 = UTILS_IntToString((
int)fpart,Buffer+length1+1);
171 Buffer[length1 + 1 + length2] =
'\0';
172 return length1 + 1 + length2;
181 int UTILS_StringToInt(
char* Buffer)
192 number = number*10 + (*Buffer -
'0');
197 number = (-1) * number;
208 int UTILS_StringToLong(
char* Buffer)
219 number = number*10 + (*Buffer -
'0');
224 number = (-1) * number;
Post a Comment