-
Notifications
You must be signed in to change notification settings - Fork 2
/
std_lib.h
59 lines (54 loc) · 911 Bytes
/
std_lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
void int_to_string(unsigned int data, unsigned char buf[])
{
unsigned int mx = 10000;
unsigned char i = 0;
unsigned char c = 0;
if (data == 0)
{
buf[c] = 48;
c++;
}
else
{
while(i<5)
{
if (data>=mx)
{
buf[c] = (data/mx)%10 + 48;
c++;
}
mx = mx/10;
i++;
}
}
buf[c] = 0;
}
void reset_array(unsigned char array[], unsigned char number_of_elements)
{
unsigned char i;
for (i = 0; i < number_of_elements; i++)
{
array[i] = 0;
}
}
void string_to_int(unsigned char buf[])
{
unsigned int array[4];
unsigned int res = 0;
unsigned char i = 0, k;
for (k = 0; k < 4; k++)
{
while (buf[i] != ',' && i < 25)
{
res = res*10 + (buf[i] - '0');
i++;
}
array[k] = res;
res = 0;
i++;
}
wire_thickness = array[0];
coil_width = array[1];
number_of_turns = array[2];
rotation_speed = array[3];
}