bzr branch
http://bzr.ed.am/elec/propeller-clock
59
by edam
removed ulibc, fixed button, added text rendering |
1 |
/* |
2 |
* text_renderer.cc |
|
3 |
* |
|
4 |
* Copyright (C) 2011 Tim Marston <tim@ed.am> and Dan Marston. |
|
5 |
* |
|
6 |
* This file is part of propeller-clock (hereafter referred to as "this |
|
7 |
* program"). See http://ed.am/dev/software/arduino/propeller-clock for more |
|
8 |
* information. |
|
9 |
* |
|
10 |
* This program is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU Lesser General Public License as published |
|
12 |
* by the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU Lesser General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU Lesser General Public License |
|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22 |
*/ |
|
23 |
#include "text_renderer.h" |
|
24 |
#include "config.h" |
|
25 |
#include "Arduino.h" |
|
26 |
#include <avr/pgmspace.h> |
|
27 |
#include "display.h" |
|
28 |
||
29 |
||
60
by edam
remove TextRenderer singleton and save space |
30 |
#define MAX_MESSAGE_LENGTH 64 |
31 |
||
32 |
||
33 |
// the buffer for the message |
|
34 |
static char _message_buffer[ MAX_MESSAGE_LENGTH ]; |
|
35 |
||
36 |
// the current message |
|
37 |
static PString _message( _message_buffer, sizeof( _message_buffer ) ); |
|
38 |
||
39 |
// cached glyph |
|
40 |
static char _glyph_cache[ 8 ]; |
|
41 |
||
42 |
// the character the current cached glyph is for |
|
43 |
static char _glyph_cache_char; |
|
44 |
||
45 |
// selected font |
|
46 |
static int _font = 0; |
|
47 |
||
48 |
// time last frame |
|
49 |
static unsigned long _last_millis; |
|
50 |
||
51 |
// duration last frame (in case we can't calculate it this frame!) |
|
52 |
static unsigned long _duration; |
|
53 |
||
54 |
// scroll position (in segments ) |
|
55 |
static signed long _scroll; |
|
56 |
||
57 |
||
58 |
// cache a glyph |
|
59 |
void cache_glyph( char c ) |
|
59
by edam
removed ulibc, fixed button, added text rendering |
60 |
{ |
61 |
static char fonts[][ 66 * 8 ] PROGMEM = { |
|
62 |
{ // INVD-A |
|
63 |
0x00, 0x7c, 0x7e, 0x12, 0x12, 0x12, 0x7e, 0x7c, // A |
|
64 |
0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // B |
|
65 |
0x00, 0x3c, 0x7e, 0x42, 0x42, 0x42, 0x66, 0x24, // C |
|
66 |
0x00, 0x7e, 0x7e, 0x42, 0x42, 0x66, 0x3c, 0x18, // D |
|
67 |
0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x42, 0x00, // E |
|
68 |
0x00, 0x7e, 0x7e, 0x0a, 0x0a, 0x0a, 0x02, 0x00, // F |
|
69 |
0x00, 0x3c, 0x7e, 0x42, 0x52, 0x52, 0x76, 0x34, // G |
|
70 |
0x00, 0x7e, 0x7e, 0x08, 0x08, 0x08, 0x7e, 0x7e, // H |
|
71 |
0x00, 0x42, 0x42, 0x7e, 0x7e, 0x42, 0x42, 0x00, // I |
|
72 |
0x00, 0x30, 0x70, 0x40, 0x40, 0x40, 0x7e, 0x3e, // J |
|
73 |
0x00, 0x7e, 0x7e, 0x08, 0x1c, 0x36, 0x62, 0x40, // K |
|
74 |
0x00, 0x7e, 0x7e, 0x40, 0x40, 0x40, 0x40, 0x00, // L |
|
75 |
0x00, 0x7e, 0x7e, 0x0c, 0x18, 0x0c, 0x7e, 0x7e, // M |
|
76 |
0x00, 0x7e, 0x7e, 0x0c, 0x18, 0x30, 0x7e, 0x7e, // N |
|
77 |
0x00, 0x3c, 0x7e, 0x42, 0x42, 0x42, 0x7e, 0x3c, // O |
|
78 |
0x00, 0x7e, 0x7e, 0x12, 0x12, 0x12, 0x1e, 0x0c, // P |
|
79 |
0x00, 0x3c, 0x7e, 0x52, 0x52, 0x62, 0x7e, 0x3c, // Q |
|
80 |
0x00, 0x7e, 0x7e, 0x12, 0x12, 0x32, 0x7e, 0x4c, // R |
|
81 |
0x00, 0x24, 0x6e, 0x4a, 0x4a, 0x4a, 0x7a, 0x30, // S |
|
82 |
0x00, 0x02, 0x02, 0x7e, 0x7e, 0x02, 0x02, 0x00, // T |
|
83 |
0x00, 0x3e, 0x7e, 0x40, 0x40, 0x40, 0x7e, 0x3e, // U |
|
84 |
0x00, 0x1e, 0x3e, 0x60, 0x40, 0x60, 0x3e, 0x1e, // V |
|
85 |
0x00, 0x3e, 0x7e, 0x60, 0x30, 0x60, 0x7e, 0x3e, // W |
|
86 |
0x00, 0x42, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0x42, // X |
|
87 |
0x02, 0x06, 0x0c, 0x78, 0x78, 0x0c, 0x06, 0x02, // Y |
|
88 |
0x00, 0x42, 0x62, 0x72, 0x5a, 0x4e, 0x46, 0x42, // Z |
|
89 |
0x00, 0x20, 0x74, 0x54, 0x54, 0x7c, 0x78, 0x00, // a |
|
90 |
0x00, 0x00, 0x7e, 0x7e, 0x48, 0x48, 0x78, 0x30, // b |
|
91 |
0x00, 0x00, 0x38, 0x7c, 0x44, 0x44, 0x00, 0x00, // c |
|
92 |
0x00, 0x30, 0x78, 0x48, 0x48, 0x7e, 0x7e, 0x00, // d |
|
93 |
0x00, 0x38, 0x7c, 0x54, 0x54, 0x5c, 0x08, 0x00, // e |
|
94 |
0x00, 0x00, 0x7c, 0x7e, 0x0a, 0x02, 0x00, 0x00, // f |
|
95 |
0x00, 0x18, 0xbc, 0xa4, 0xa4, 0xfc, 0x7c, 0x00, // g |
|
96 |
0x00, 0x7e, 0x7e, 0x08, 0x08, 0x78, 0x70, 0x00, // h |
|
97 |
0x00, 0x00, 0x48, 0x7a, 0x7a, 0x40, 0x00, 0x00, // i |
|
98 |
0x00, 0x00, 0x40, 0xc0, 0x80, 0xfa, 0x7a, 0x00, // j |
|
99 |
0x00, 0x00, 0x7e, 0x7e, 0x10, 0x3c, 0x64, 0x40, // k |
|
100 |
0x00, 0x00, 0x00, 0x3e, 0x7e, 0x40, 0x40, 0x00, // l |
|
101 |
0x7c, 0x7c, 0x04, 0x78, 0x7c, 0x04, 0x7c, 0x78, // m |
|
102 |
0x00, 0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x78, 0x00, // n |
|
103 |
0x00, 0x38, 0x7c, 0x44, 0x44, 0x7c, 0x38, 0x00, // o |
|
104 |
0x00, 0xfc, 0xfc, 0x24, 0x24, 0x3c, 0x18, 0x00, // p |
|
105 |
0x00, 0x18, 0x3c, 0x24, 0x24, 0xfc, 0xfc, 0x80, // q |
|
106 |
0x00, 0x00, 0x78, 0x7c, 0x04, 0x04, 0x00, 0x00, // r |
|
107 |
0x00, 0x48, 0x5c, 0x54, 0x54, 0x74, 0x20, 0x00, // s |
|
108 |
0x00, 0x04, 0x3e, 0x7e, 0x44, 0x44, 0x00, 0x00, // t |
|
109 |
0x00, 0x3c, 0x7c, 0x40, 0x40, 0x7c, 0x3c, 0x00, // u |
|
110 |
0x00, 0x0c, 0x3c, 0x70, 0x60, 0x3c, 0x0c, 0x00, // v |
|
111 |
0x3c, 0x7c, 0x40, 0x30, 0x40, 0x7c, 0x3c, 0x00, // w |
|
112 |
0x00, 0x44, 0x6c, 0x38, 0x38, 0x6c, 0x44, 0x00, // x |
|
113 |
0x00, 0x1c, 0xbc, 0xa0, 0xa0, 0xfc, 0x7c, 0x00, // y |
|
114 |
0x00, 0x44, 0x64, 0x74, 0x5c, 0x4c, 0x44, 0x00, // z |
|
115 |
0x00, 0x3c, 0x7e, 0x52, 0x4a, 0x46, 0x7e, 0x3c, // 0 |
|
116 |
0x00, 0x00, 0x44, 0x44, 0x7e, 0x7e, 0x40, 0x40, // 1 |
|
117 |
0x00, 0x64, 0x76, 0x52, 0x52, 0x52, 0x5e, 0x4c, // 2 |
|
118 |
0x00, 0x24, 0x66, 0x42, 0x4a, 0x4a, 0x7e, 0x34, // 3 |
|
119 |
0x00, 0x30, 0x28, 0x24, 0x7e, 0x7e, 0x20, 0x20, // 4 |
|
120 |
0x00, 0x2e, 0x6e, 0x4a, 0x4a, 0x4a, 0x7a, 0x32, // 5 |
|
121 |
0x00, 0x3c, 0x7e, 0x4a, 0x4a, 0x4a, 0x7a, 0x30, // 6 |
|
122 |
0x00, 0x02, 0x02, 0x62, 0x72, 0x1a, 0x0e, 0x06, // 7 |
|
123 |
0x00, 0x34, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // 8 |
|
124 |
0x00, 0x0c, 0x5e, 0x52, 0x52, 0x52, 0x7e, 0x3c, // 9 |
|
125 |
0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, // - |
|
126 |
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // : |
|
127 |
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // . |
|
128 |
0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, // , |
|
129 |
}, { // INVD-D |
|
130 |
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x7f, // A |
|
131 |
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x77, // B |
|
132 |
0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x77, 0x77, // C |
|
133 |
0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f, 0x3e, // D |
|
134 |
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x63, 0x63, // E |
|
135 |
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x03, 0x03, // F |
|
136 |
0x00, 0x7f, 0x7f, 0x41, 0x49, 0x49, 0x7b, 0x7b, // G |
|
137 |
0x00, 0x7f, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x7f, // H |
|
138 |
0x00, 0x41, 0x41, 0x7f, 0x7f, 0x41, 0x41, 0x00, // I |
|
139 |
0x00, 0x60, 0x60, 0x40, 0x40, 0x40, 0x7f, 0x7f, // J |
|
140 |
0x00, 0x7f, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x77, // K |
|
141 |
0x00, 0x7f, 0x7f, 0x40, 0x40, 0x40, 0x60, 0x60, // L |
|
142 |
0x00, 0x7f, 0x7f, 0x02, 0x04, 0x02, 0x7f, 0x7f, // M |
|
143 |
0x00, 0x7f, 0x7f, 0x06, 0x0c, 0x18, 0x7f, 0x7f, // N |
|
144 |
0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f, 0x7f, // O |
|
145 |
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x0f, 0x0f, // P |
|
146 |
0x00, 0x7f, 0x7f, 0x41, 0x51, 0x21, 0x7f, 0x7f, // Q |
|
147 |
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x77, // R |
|
148 |
0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x7b, 0x7b, // S |
|
149 |
0x00, 0x01, 0x01, 0x7f, 0x7f, 0x01, 0x01, 0x00, // T |
|
150 |
0x00, 0x7f, 0x7f, 0x40, 0x40, 0x40, 0x7f, 0x7f, // U |
|
151 |
0x00, 0x1f, 0x3f, 0x60, 0x40, 0x60, 0x3f, 0x1f, // V |
|
152 |
0x00, 0x7f, 0x7f, 0x20, 0x10, 0x20, 0x7f, 0x7f, // W |
|
153 |
0x00, 0x77, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x77, // X |
|
154 |
0x00, 0x6f, 0x6f, 0x48, 0x48, 0x48, 0x7f, 0x7f, // Y |
|
155 |
0x00, 0x63, 0x73, 0x59, 0x4d, 0x47, 0x63, 0x61, // Z |
|
156 |
0x00, 0x74, 0x74, 0x54, 0x54, 0x7c, 0x7c, 0x00, // a |
|
157 |
0x00, 0x7f, 0x7f, 0x44, 0x44, 0x7c, 0x7c, 0x00, // b |
|
158 |
0x00, 0x7c, 0x7c, 0x44, 0x44, 0x6c, 0x6c, 0x00, // c |
|
159 |
0x00, 0x7c, 0x7c, 0x44, 0x44, 0x7f, 0x7f, 0x00, // d |
|
160 |
0x00, 0x7c, 0x7c, 0x54, 0x54, 0x5c, 0x5c, 0x00, // e |
|
161 |
0x00, 0x00, 0x04, 0x7f, 0x7f, 0x05, 0x05, 0x01, // f |
|
162 |
0x00, 0xbc, 0xbc, 0xa4, 0xa4, 0xfc, 0xfc, 0x00, // g |
|
163 |
0x00, 0x7f, 0x7f, 0x04, 0x04, 0x7c, 0x7c, 0x00, // h |
|
164 |
0x00, 0x44, 0x44, 0x7d, 0x7d, 0x40, 0x40, 0x00, // i |
|
165 |
0x00, 0x80, 0x80, 0xfd, 0xfd, 0x00, 0x00, 0x00, // j |
|
166 |
0x00, 0x7f, 0x7f, 0x10, 0x10, 0x7c, 0x6c, 0x00, // k |
|
167 |
0x00, 0x00, 0x00, 0x7f, 0x7f, 0x40, 0x40, 0x00, // l |
|
168 |
0x00, 0x7c, 0x7c, 0x04, 0x7c, 0x04, 0x7c, 0x7c, // m |
|
169 |
0x00, 0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x7c, 0x00, // n |
|
170 |
0x00, 0x7c, 0x7c, 0x44, 0x44, 0x7c, 0x7c, 0x00, // o |
|
171 |
0x00, 0xfc, 0xfc, 0x24, 0x24, 0x3c, 0x3c, 0x00, // p |
|
172 |
0x00, 0x3c, 0x3c, 0x24, 0x24, 0xfc, 0xfc, 0x00, // q |
|
173 |
0x00, 0x7c, 0x7c, 0x04, 0x04, 0x0c, 0x0c, 0x00, // r |
|
174 |
0x00, 0x5c, 0x5c, 0x54, 0x54, 0x74, 0x74, 0x00, // s |
|
175 |
0x00, 0x00, 0x04, 0x7f, 0x7f, 0x44, 0x44, 0x00, // t |
|
176 |
0x00, 0x7c, 0x7c, 0x40, 0x40, 0x7c, 0x7c, 0x00, // u |
|
177 |
0x00, 0x1c, 0x3c, 0x60, 0x60, 0x3c, 0x1c, 0x00, // v |
|
178 |
0x00, 0x7c, 0x7c, 0x40, 0x7c, 0x40, 0x7c, 0x7c, // w |
|
179 |
0x00, 0x6c, 0x7c, 0x10, 0x10, 0x7c, 0x6c, 0x00, // x |
|
180 |
0x00, 0xbc, 0xbc, 0xa0, 0xa0, 0xfc, 0xfc, 0x00, // y |
|
181 |
0x00, 0x64, 0x74, 0x54, 0x54, 0x5c, 0x4c, 0x00, // z |
|
182 |
0x00, 0x7f, 0x7f, 0x51, 0x49, 0x45, 0x7f, 0x7f, // 0 |
|
183 |
0x00, 0x41, 0x41, 0x7f, 0x7f, 0x40, 0x40, 0x00, // 1 |
|
184 |
0x00, 0x7b, 0x7b, 0x49, 0x49, 0x49, 0x4f, 0x4f, // 2 |
|
185 |
0x00, 0x63, 0x63, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 3 |
|
186 |
0x00, 0x1f, 0x1f, 0x10, 0x10, 0x7f, 0x7f, 0x10, // 4 |
|
187 |
0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x79, // 5 |
|
188 |
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7b, 0x7b, // 6 |
|
189 |
0x00, 0x03, 0x03, 0x71, 0x79, 0x0d, 0x07, 0x03, // 7 |
|
190 |
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 8 |
|
191 |
0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 9 |
|
192 |
0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, // - |
|
193 |
0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, // : |
|
194 |
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // . |
|
195 |
0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, // , |
|
196 |
}, { // INVD-G |
|
197 |
0x7c, 0x7e, 0x22, 0x7e, 0x7e, 0x7e, 0x7c, 0x00, // A |
|
198 |
0x7c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7e, 0x34, 0x00, // B |
|
199 |
0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0x76, 0x34, 0x00, // C |
|
200 |
0x7c, 0x7e, 0x7e, 0x7e, 0x42, 0x7e, 0x3c, 0x00, // D |
|
201 |
0x3c, 0x7e, 0x7e, 0x7e, 0x4a, 0x4a, 0x00, 0x00, // E |
|
202 |
0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x12, 0x00, 0x00, // F |
|
203 |
0x3c, 0x7e, 0x7e, 0x7e, 0x52, 0x76, 0x34, 0x00, // G |
|
204 |
0x7e, 0x7e, 0x7e, 0x7e, 0x08, 0x7e, 0x7e, 0x00, // H |
|
205 |
0x00, 0x42, 0x7e, 0x7e, 0x7e, 0x7e, 0x42, 0x00, // I |
|
206 |
0x30, 0x70, 0x42, 0x7e, 0x7e, 0x7e, 0x3e, 0x00, // J |
|
207 |
0x7e, 0x7e, 0x7e, 0x7e, 0x08, 0x76, 0x62, 0x00, // K |
|
208 |
0x00, 0x3e, 0x7e, 0x7e, 0x7e, 0x40, 0x40, 0x00, // L |
|
209 |
0x7e, 0x7e, 0x7e, 0x7c, 0x08, 0x7c, 0x7e, 0x00, // M |
|
210 |
0x7e, 0x7e, 0x7e, 0x7c, 0x08, 0x7e, 0x7e, 0x00, // N |
|
211 |
0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0x7e, 0x3c, 0x00, // O |
|
212 |
0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x1e, 0x0c, 0x00, // P |
|
213 |
0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0xfe, 0xbc, 0x00, // Q |
|
214 |
0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x7e, 0x6c, 0x00, // R |
|
215 |
0x24, 0x6e, 0x5e, 0x7e, 0x7a, 0x76, 0x24, 0x00, // S |
|
216 |
0x00, 0x02, 0x7e, 0x7e, 0x7e, 0x7e, 0x02, 0x00, // T |
|
217 |
0x3e, 0x7e, 0x7e, 0x7e, 0x40, 0x7e, 0x3e, 0x00, // U |
|
218 |
0x1e, 0x3e, 0x7e, 0x7e, 0x40, 0x3e, 0x1e, 0x00, // V |
|
219 |
0x3e, 0x7e, 0x7e, 0x7e, 0x20, 0x7e, 0x3e, 0x00, // W |
|
220 |
0x42, 0x66, 0x3e, 0x7e, 0x7c, 0x66, 0x42, 0x00, // X |
|
221 |
0x06, 0x0e, 0x7e, 0x7e, 0x70, 0x0e, 0x06, 0x00, // Y |
|
222 |
0x62, 0x72, 0x7a, 0x7e, 0x5e, 0x4e, 0x46, 0x00, // Z |
|
223 |
0x38, 0x7c, 0x44, 0x3c, 0x7c, 0x7c, 0x78, 0x00, // a |
|
224 |
0x3f, 0x7f, 0x7f, 0x7f, 0x44, 0x7c, 0x38, 0x00, // b |
|
225 |
0x38, 0x7c, 0x7c, 0x7c, 0x44, 0x6c, 0x28, 0x00, // c |
|
226 |
0x38, 0x7c, 0x44, 0x3f, 0x7f, 0x7f, 0x7f, 0x00, // d |
|
227 |
0x38, 0x7c, 0x7c, 0x7c, 0x54, 0x5c, 0x28, 0x00, // e |
|
228 |
0x88, 0xfe, 0xff, 0xff, 0x7f, 0x09, 0x0a, 0x00, // f |
|
229 |
0x58, 0xbc, 0xa4, 0xfc, 0xfc, 0xfc, 0x78, 0x00, // g |
|
230 |
0x7f, 0x7f, 0x7f, 0x7f, 0x04, 0x7c, 0x78, 0x00, // h |
|
231 |
0x00, 0x00, 0x7a, 0x7f, 0x7f, 0x7a, 0x00, 0x00, // i |
|
232 |
0x00, 0x80, 0xfa, 0xff, 0xff, 0x7a, 0x00, 0x00, // j |
|
233 |
0x7f, 0x7f, 0x7f, 0x7f, 0x24, 0x7c, 0x58, 0x00, // k |
|
234 |
0x00, 0x00, 0x3f, 0x7f, 0x7f, 0x7f, 0x40, 0x00, // l |
|
235 |
0x78, 0x7c, 0x7c, 0x04, 0x7c, 0x04, 0x7c, 0x78, // m |
|
236 |
0x7c, 0x7c, 0x7c, 0x78, 0x04, 0x7c, 0x78, 0x00, // n |
|
237 |
0x38, 0x7c, 0x7c, 0x7c, 0x44, 0x7c, 0x38, 0x00, // o |
|
238 |
0xfc, 0xfc, 0xfc, 0xf8, 0x44, 0x7c, 0x38, 0x00, // p |
|
239 |
0x38, 0x7c, 0x44, 0xfc, 0xfc, 0xfc, 0xf8, 0x00, // q |
|
240 |
0x7c, 0x7c, 0x7c, 0x7c, 0x04, 0x0c, 0x08, 0x00, // r |
|
241 |
0x28, 0x5c, 0x5c, 0x7c, 0x74, 0x74, 0x28, 0x00, // s |
|
242 |
0x04, 0x3e, 0x7e, 0x7e, 0x7e, 0x44, 0x24, 0x00, // t |
|
243 |
0x3c, 0x7c, 0x40, 0x3c, 0x7c, 0x7c, 0x7c, 0x00, // u |
|
244 |
0x1c, 0x3c, 0x7c, 0x7c, 0x60, 0x3c, 0x1c, 0x00, // v |
|
245 |
0x3c, 0x7c, 0x7c, 0x40, 0x7c, 0x40, 0x7c, 0x3c, // w |
|
246 |
0x44, 0x6c, 0x3c, 0x7c, 0x78, 0x6c, 0x44, 0x00, // x |
|
247 |
0x9c, 0xbc, 0xfc, 0xfc, 0x60, 0x3c, 0x1c, 0x00, // y |
|
248 |
0x64, 0x74, 0x3c, 0x7c, 0x5c, 0x4c, 0x24, 0x00, // z |
|
249 |
0x3c, 0x7e, 0x42, 0x7e, 0x7e, 0x7e, 0x3c, 0x00, // 0 |
|
250 |
0x00, 0x42, 0x7e, 0x7e, 0x7e, 0x7e, 0x40, 0x00, // 1 |
|
251 |
0x64, 0x72, 0x7a, 0x7e, 0x5e, 0x4e, 0x44, 0x00, // 2 |
|
252 |
0x24, 0x66, 0x4a, 0x7e, 0x7e, 0x7e, 0x34, 0x00, // 3 |
|
253 |
0x0e, 0x1e, 0x10, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, // 4 |
|
254 |
0x2e, 0x6e, 0x4e, 0x7a, 0x7a, 0x7a, 0x32, 0x00, // 5 |
|
255 |
0x3c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7a, 0x34, 0x00, // 6 |
|
256 |
0x02, 0x62, 0x7a, 0x7e, 0x7e, 0x1e, 0x06, 0x00, // 7 |
|
257 |
0x34, 0x7e, 0x4e, 0x7e, 0x7a, 0x7e, 0x34, 0x00, // 8 |
|
258 |
0x2c, 0x5e, 0x52, 0x7e, 0x7e, 0x7e, 0x3c, 0x00, // 9 |
|
259 |
0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // - |
|
260 |
0x00, 0x00, 0x28, 0x7c, 0x7c, 0x28, 0x00, 0x00, // : |
|
261 |
0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x00, 0x00, // . |
|
262 |
0x00, 0x00, 0x10, 0xb8, 0xf8, 0x70, 0x00, 0x00, // , |
|
263 |
}, { // INVD-B |
|
264 |
0x00, 0x78, 0x7f, 0x09, 0x09, 0x0f, 0x78, 0x00, // A |
|
265 |
0x00, 0x7f, 0x79, 0x49, 0x49, 0x4f, 0x78, 0x00, // B |
|
266 |
0x00, 0x7f, 0x79, 0x41, 0x41, 0x41, 0x63, 0x00, // C |
|
267 |
0x00, 0x7f, 0x79, 0x41, 0x41, 0x41, 0x7f, 0x00, // D |
|
268 |
0x00, 0x00, 0x7f, 0x79, 0x49, 0x49, 0x41, 0x00, // E |
|
269 |
0x00, 0x00, 0x7f, 0x79, 0x09, 0x09, 0x01, 0x00, // F |
|
270 |
0x00, 0x7f, 0x79, 0x41, 0x41, 0x49, 0x7b, 0x00, // G |
|
271 |
0x00, 0x7f, 0x78, 0x08, 0x08, 0x08, 0x7f, 0x00, // H |
|
272 |
0x00, 0x00, 0x00, 0x7f, 0x78, 0x00, 0x00, 0x00, // I |
|
273 |
0x00, 0x60, 0x40, 0x40, 0x40, 0x7f, 0x78, 0x00, // J |
|
274 |
0x00, 0x7f, 0x78, 0x08, 0x08, 0x0f, 0x78, 0x00, // K |
|
275 |
0x00, 0x00, 0x7f, 0x78, 0x40, 0x40, 0x40, 0x00, // L |
|
276 |
0x00, 0x7f, 0x79, 0x01, 0x7f, 0x01, 0x7f, 0x00, // M |
|
277 |
0x00, 0x7f, 0x79, 0x01, 0x01, 0x01, 0x7f, 0x00, // N |
|
278 |
0x00, 0x7f, 0x41, 0x41, 0x41, 0x43, 0x7f, 0x00, // O |
|
279 |
0x00, 0x7f, 0x79, 0x09, 0x09, 0x09, 0x0f, 0x00, // P |
|
280 |
0x00, 0x7f, 0x41, 0x41, 0x61, 0x61, 0x7f, 0x00, // Q |
|
281 |
0x00, 0x7f, 0x79, 0x09, 0x09, 0x0f, 0x78, 0x00, // R |
|
282 |
0x00, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x7b, 0x00, // S |
|
283 |
0x00, 0x01, 0x01, 0x7f, 0x79, 0x01, 0x01, 0x00, // T |
|
284 |
0x00, 0x7f, 0x78, 0x40, 0x40, 0x40, 0x7f, 0x00, // U |
|
285 |
0x00, 0x0f, 0x7f, 0x40, 0x40, 0x78, 0x0f, 0x00, // V |
|
286 |
0x00, 0x7f, 0x78, 0x40, 0x7f, 0x40, 0x7f, 0x00, // W |
|
287 |
0x00, 0x77, 0x78, 0x08, 0x08, 0x08, 0x77, 0x00, // X |
|
288 |
0x00, 0x0f, 0x08, 0x78, 0x78, 0x08, 0x0f, 0x00, // Y |
|
289 |
0x00, 0x7b, 0x79, 0x49, 0x49, 0x49, 0x6f, 0x00, // Z |
|
290 |
0x00, 0x74, 0x74, 0x54, 0x54, 0x7c, 0x00, 0x00, // a |
|
291 |
0x00, 0x7f, 0x74, 0x44, 0x44, 0x7c, 0x00, 0x00, // b |
|
292 |
0x00, 0x7c, 0x74, 0x44, 0x44, 0x6c, 0x00, 0x00, // c |
|
293 |
0x00, 0x7c, 0x74, 0x44, 0x44, 0x7f, 0x00, 0x00, // d |
|
294 |
0x00, 0x7c, 0x74, 0x54, 0x54, 0x5c, 0x00, 0x00, // e |
|
295 |
0x00, 0x00, 0x04, 0x7f, 0x75, 0x01, 0x00, 0x00, // f |
|
296 |
0x00, 0xbc, 0xb4, 0xa4, 0xa4, 0xfc, 0x00, 0x00, // g |
|
297 |
0x00, 0x7f, 0x74, 0x04, 0x04, 0x7c, 0x00, 0x00, // h |
|
298 |
0x00, 0x00, 0x00, 0x7d, 0x71, 0x00, 0x00, 0x00, // i |
|
299 |
0x00, 0x00, 0x80, 0xbd, 0xf1, 0x00, 0x00, 0x00, // j |
|
300 |
0x00, 0x7f, 0x70, 0x10, 0x1c, 0x70, 0x00, 0x00, // k |
|
301 |
0x00, 0x00, 0x00, 0x7f, 0x78, 0x00, 0x00, 0x00, // l |
|
302 |
0x00, 0x7c, 0x74, 0x04, 0x7c, 0x04, 0x7c, 0x00, // m |
|
303 |
0x00, 0x7c, 0x74, 0x04, 0x04, 0x7c, 0x00, 0x00, // n |
|
304 |
0x00, 0x7c, 0x74, 0x44, 0x44, 0x7c, 0x00, 0x00, // o |
|
305 |
0x00, 0xfc, 0x34, 0x24, 0x24, 0x3c, 0x00, 0x00, // p |
|
306 |
0x00, 0x3c, 0x34, 0x24, 0x24, 0xfc, 0x00, 0x00, // q |
|
307 |
0x00, 0x00, 0x7c, 0x74, 0x04, 0x04, 0x00, 0x00, // r |
|
308 |
0x00, 0x5c, 0x54, 0x54, 0x74, 0x74, 0x00, 0x00, // s |
|
309 |
0x00, 0x00, 0x04, 0x7f, 0x74, 0x00, 0x00, 0x00, // t |
|
310 |
0x00, 0x7c, 0x70, 0x40, 0x40, 0x7c, 0x00, 0x00, // u |
|
311 |
0x00, 0x1c, 0x7c, 0x40, 0x70, 0x1c, 0x00, 0x00, // v |
|
312 |
0x00, 0x7c, 0x70, 0x40, 0x7c, 0x40, 0x7c, 0x00, // w |
|
313 |
0x00, 0x6c, 0x70, 0x10, 0x10, 0x6c, 0x00, 0x00, // x |
|
314 |
0x00, 0xbc, 0xb0, 0xa0, 0xa0, 0xfc, 0x00, 0x00, // y |
|
315 |
0x00, 0x74, 0x74, 0x54, 0x54, 0x5c, 0x00, 0x00, // z |
|
316 |
0x00, 0x7f, 0x41, 0x41, 0x41, 0x79, 0x7f, 0x00, // 0 |
|
317 |
0x00, 0x00, 0x00, 0x78, 0x7f, 0x00, 0x00, 0x00, // 1 |
|
318 |
0x00, 0x7b, 0x79, 0x49, 0x49, 0x49, 0x4f, 0x00, // 2 |
|
319 |
0x00, 0x63, 0x49, 0x49, 0x49, 0x7f, 0x78, 0x00, // 3 |
|
320 |
0x00, 0x1f, 0x11, 0x11, 0x71, 0x7f, 0x10, 0x00, // 4 |
|
321 |
0x00, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x79, 0x00, // 5 |
|
322 |
0x00, 0x7f, 0x49, 0x49, 0x49, 0x79, 0x7b, 0x00, // 6 |
|
323 |
0x00, 0x01, 0x01, 0x01, 0x79, 0x7f, 0x00, 0x00, // 7 |
|
324 |
0x00, 0x78, 0x4f, 0x49, 0x49, 0x7f, 0x78, 0x00, // 8 |
|
325 |
0x00, 0x1f, 0x11, 0x11, 0x11, 0x71, 0x7f, 0x00, // 9 |
|
326 |
0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, // - |
|
327 |
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // : |
|
328 |
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // . |
|
329 |
0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, // , |
|
330 |
} |
|
331 |
}; |
|
332 |
||
60
by edam
remove TextRenderer singleton and save space |
333 |
// nothing to do? |
334 |
if( c == _glyph_cache_char ) |
|
335 |
return; |
|
336 |
_glyph_cache_char = c; |
|
337 |
||
338 |
// find glyph data position |
|
59
by edam
removed ulibc, fixed button, added text rendering |
339 |
int pos; |
340 |
if( c >= 'A' && c <= 'Z' ) |
|
341 |
pos = c - 'A'; |
|
342 |
else if( c >= 'a' && c <= 'z' ) |
|
343 |
pos = c - 'a' + 26; |
|
344 |
else if( c >= '0' && c <= '9' ) |
|
345 |
pos = c - '0' + 52; |
|
346 |
else if( c == '-' ) |
|
347 |
pos = 62; |
|
348 |
else if( c == ':' ) |
|
349 |
pos = 63; |
|
350 |
else if( c == '.' ) |
|
351 |
pos = 64; |
|
352 |
else if( c == ',' ) |
|
353 |
pos = 65; |
|
354 |
else |
|
355 |
pos = -1; |
|
356 |
||
60
by edam
remove TextRenderer singleton and save space |
357 |
// space? or copy glyph from progmem? |
59
by edam
removed ulibc, fixed button, added text rendering |
358 |
if( pos == -1 ) |
60
by edam
remove TextRenderer singleton and save space |
359 |
memset( _glyph_cache, 0, 8 ); |
360 |
else |
|
361 |
memcpy_P( _glyph_cache, &( fonts[ _font ][ pos * 8 ] ), 8 ); |
|
362 |
} |
|
363 |
||
364 |
||
365 |
// convert segment to display-space segment |
|
366 |
int xform_segment( int segment ) |
|
367 |
{ |
|
368 |
if( segment < TEXT_DISPLAY_SEGMENTS / 2 ) |
|
369 |
return segment + TEXT_DISPLAY_SEGMENTS / 2; |
|
370 |
else if( segment >= NUM_SEGMENTS - TEXT_DISPLAY_SEGMENTS / 2 ) |
|
371 |
return segment - ( NUM_SEGMENTS - TEXT_DISPLAY_SEGMENTS / 2 ); |
|
372 |
else |
|
373 |
return - 1; |
|
374 |
} |
|
375 |
||
376 |
||
377 |
// draw a column of pixels from the current message |
|
378 |
void render( int x ) |
|
379 |
{ |
|
380 |
// handle negative x |
|
381 |
if( x < 0 ) { |
|
382 |
Display::leds_off(); |
|
383 |
return; |
|
384 |
} |
|
385 |
||
386 |
// scale font |
|
387 |
x /= TEXT_SCALE; |
|
388 |
||
389 |
// make sure the correct glyph is cached |
|
390 |
int pos = x / 8; |
|
391 |
cache_glyph( ( pos >= 0 && pos < (signed)_message.length() )? _message[ pos ] : ' ' ); |
|
392 |
||
393 |
// draw a column |
|
394 |
char col_data = _glyph_cache[ x % 8 ]; |
|
395 |
for( int a = 0; a < 8; a++ ) |
|
396 |
Display::led( 8 - a, ( col_data & ( 1 << a ) )? true : false ); |
|
397 |
} |
|
398 |
||
399 |
||
400 |
PString &TextRenderer::get_pstring() |
|
401 |
{ |
|
402 |
// reset renderer |
|
403 |
_duration = 0; |
|
404 |
_last_millis = ::millis(); |
|
405 |
_scroll = -TEXT_DISPLAY_SEGMENTS; |
|
406 |
||
407 |
return _message; |
|
408 |
} |
|
409 |
||
410 |
||
411 |
void TextRenderer::draw_reset() |
|
412 |
{ |
|
413 |
// how many milliseconds have elapsed since last frame? |
|
414 |
unsigned long millis = ::millis(); |
|
415 |
if( millis > _last_millis ) |
|
416 |
_duration = millis - _last_millis; |
|
417 |
_last_millis = millis; |
|
418 |
||
419 |
// move on scroll pos |
|
420 |
_scroll += ( _duration * TEXT_SCROLL_SPEED / 1000 ); |
|
421 |
if( _scroll > (signed long)_message.length() * 8 * TEXT_SCALE ) |
|
422 |
_scroll -= (signed long)_message.length() * 8 * TEXT_SCALE + TEXT_DISPLAY_SEGMENTS; |
|
423 |
} |
|
424 |
||
425 |
||
426 |
void TextRenderer::draw_scroll( int segment ) |
|
427 |
{ |
|
428 |
segment = xform_segment( segment ); |
|
429 |
if( segment < 0 ) |
|
430 |
Display::leds_off(); |
|
431 |
else |
|
432 |
render( (long)segment + _scroll ); |
|
59
by edam
removed ulibc, fixed button, added text rendering |
433 |
} |