-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtft_util.cpp
137 lines (128 loc) · 4.27 KB
/
tft_util.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
/*
Copyright 2018 Jan Pomikalek <[email protected]>
This file is part of the DAVEga firmware.
DAVEga firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAVEga firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DAVEga firmware. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tft_util.h"
// TODO: PROGMEM
const bool FONT_DIGITS_3x5[10][5][3] = {
{
{1, 1, 1},
{1, 0, 1},
{1, 0, 1},
{1, 0, 1},
{1, 1, 1},
},
{
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
},
{
{1, 1, 1},
{0, 0, 1},
{1, 1, 1},
{1, 0, 0},
{1, 1, 1},
},
{
{1, 1, 1},
{0, 0, 1},
{0, 1, 1},
{0, 0, 1},
{1, 1, 1},
},
{
{1, 0, 1},
{1, 0, 1},
{1, 1, 1},
{0, 0, 1},
{0, 0, 1},
},
{
{1, 1, 1},
{1, 0, 0},
{1, 1, 1},
{0, 0, 1},
{1, 1, 1},
},
{
{1, 1, 1},
{1, 0, 0},
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
},
{
{1, 1, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
},
{
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
},
{
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
{0, 0, 1},
{1, 1, 1},
}
};
void tft_util_draw_digit(
TFT_22_ILI9225* tft, uint8_t digit, uint8_t x, uint8_t y,
uint16_t fg_color, uint16_t bg_color, uint8_t magnify) {
for (int xx = 0; xx < 3; xx++) {
for (int yy = 0; yy < 5; yy++) {
uint16_t color = FONT_DIGITS_3x5[digit][yy][xx] ? fg_color : bg_color;
int x1 = x + xx * magnify;
int y1 = y + yy * magnify;
tft->fillRectangle(x1, y1, x1 + magnify - 1, y1 + magnify - 1, color);
}
}
}
void tft_util_draw_number(
TFT_22_ILI9225* tft, char *number, uint8_t x, uint8_t y,
uint16_t fg_color, uint16_t bg_color, uint8_t spacing, uint8_t magnify) {
int cursor_x = x;
int number_len = strlen(number);
for (int i=0; i < number_len; i++) {
char ch = number[i];
if (ch >= '0' and ch <= '9') {
tft_util_draw_digit(tft, ch - '0', cursor_x, y, fg_color, bg_color, magnify);
cursor_x += 3 * magnify + spacing;
} else if (ch == '.') {
tft->fillRectangle(cursor_x, y, cursor_x + magnify - 1, y + 5 * magnify - 1, bg_color);
tft->fillRectangle(cursor_x, y + 4 * magnify, cursor_x + magnify - 1, y + 5 * magnify - 1, fg_color);
cursor_x += magnify + spacing;
} else if (ch == '-') {
tft->fillRectangle(cursor_x, y, cursor_x + 3 * magnify - 1, y + 5 * magnify - 1, bg_color);
tft->fillRectangle(cursor_x, y + 2 * magnify, cursor_x + 3 * magnify - 1, y + 3 * magnify - 1, fg_color);
cursor_x += 3 * magnify + spacing;
} else if (ch == ' ') {
tft->fillRectangle(cursor_x, y, cursor_x + 3 * magnify - 1, y + 5 * magnify - 1, bg_color);
cursor_x += 3 * magnify + spacing;
}
}
}
uint16_t progress_to_color(float progress, TFT_22_ILI9225* tft) {
float brightness = 255.0 * (1.0 - progress);
return tft->setColor(brightness, brightness, brightness);
}