-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cpp
137 lines (109 loc) · 1.74 KB
/
Utility.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "Globals.h"
char* PrintFloat(char* Str, unsigned char precision, bool padminus)
{
if (*Str == '-')
{
gLCD.print(*Str);
Str++;
}
else if (padminus)
{
gLCD.print(' ');
}
while (isdigit(*Str))
{
gLCD.print(*Str);
Str++;
}
if (*Str == '.')
{
gLCD.print(*Str);
Str++;
while (isdigit(*Str) && precision > 0)
{
gLCD.print(*Str);
Str++;
precision--;
}
}
return Str;
}
void DrawStrP(PGM_P Str)
{
char val;
while (true)
{
val = pgm_read_byte(Str);
if (!val)
break;
gLCD.print(val);
Str++;
}
}
void DrawStrP(const int x, const int y, PGM_P Str)
{
gLCD.setCursor(x, y);
DrawStrP(Str);
}
void DrawStrJ(const char* Str, int Len)
{
const char* End = Str + Len;
while (Str != End)
{
gLCD.print(*Str);
Str++;
}
}
void DrawStrJ(const int x, const int y, const char* Str, int Len)
{
gLCD.setCursor(x, y);
DrawStrJ(Str, Len);
}
unsigned int StrWidthP(PGM_P Str)
{
char Buf[2];
unsigned int Width = 0;
Buf[1] = 0;
while (true)
{
Buf[0] = pgm_read_byte(Str);
if (!Buf[0])
break;
if (Width > 0)
Width += 1;
Width += gLCD.getStrWidth(Buf);
Str++;
}
return Width;
}
char strcmpJP(PGM_P str1, char* str2, const int str2len)
{
char val;
const char* str2end = str2 + str2len;
while (true)
{
val = pgm_read_byte(str1);
if (val != *str2)
{
if (val < *str2)
return -1;
else
return 1;
}
str1++;
str2++;
if (str2 == str2end)
return 0;
}
}
void strcpyJ(char* dest, char* src, int srclen)
{
while (srclen > 0)
{
*dest = *src;
dest++;
src++;
srclen--;
}
*dest = NULL;
}