/elec/propeller-clock

To get this branch, use:
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>
65 by Tim Marston
removed most OOP/inheritance crap, saved loads of space!
27
#include "common.h"
76 by edam
switch button to no interim presses during settings mode; added NVRAM support
28
#include "nvram.h"
59 by edam
removed ulibc, fixed button, added text rendering
29
30
60 by edam
remove TextRenderer singleton and save space
31
// cached glyph
32
static char _glyph_cache[ 8 ];
33
34
// the character the current cached glyph is for
35
static char _glyph_cache_char;
36
37
// selected font
38
static int _font = 0;
39
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
40
// output buffer
41
static unsigned char _output_buffer;
60 by edam
remove TextRenderer singleton and save space
42
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
43
// does buffer need rendering?
44
static bool _need_render;
45
60 by edam
remove TextRenderer singleton and save space
46
47
// cache a glyph
48
void cache_glyph( char c )
59 by edam
removed ulibc, fixed button, added text rendering
49
{
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
50
	static char fonts[][ 67 * 8 ] PROGMEM = {
59 by edam
removed ulibc, fixed button, added text rendering
51
		{ // INVD-A
52
			0x00, 0x7c, 0x7e, 0x12, 0x12, 0x12, 0x7e, 0x7c, // A
53
			0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // B
54
			0x00, 0x3c, 0x7e, 0x42, 0x42, 0x42, 0x66, 0x24, // C
55
			0x00, 0x7e, 0x7e, 0x42, 0x42, 0x66, 0x3c, 0x18, // D
56
			0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x42, 0x00, // E
57
			0x00, 0x7e, 0x7e, 0x0a, 0x0a, 0x0a, 0x02, 0x00, // F
58
			0x00, 0x3c, 0x7e, 0x42, 0x52, 0x52, 0x76, 0x34, // G
59
			0x00, 0x7e, 0x7e, 0x08, 0x08, 0x08, 0x7e, 0x7e, // H
60
			0x00, 0x42, 0x42, 0x7e, 0x7e, 0x42, 0x42, 0x00, // I
61
			0x00, 0x30, 0x70, 0x40, 0x40, 0x40, 0x7e, 0x3e, // J
62
			0x00, 0x7e, 0x7e, 0x08, 0x1c, 0x36, 0x62, 0x40, // K
63
			0x00, 0x7e, 0x7e, 0x40, 0x40, 0x40, 0x40, 0x00, // L
64
			0x00, 0x7e, 0x7e, 0x0c, 0x18, 0x0c, 0x7e, 0x7e, // M
65
			0x00, 0x7e, 0x7e, 0x0c, 0x18, 0x30, 0x7e, 0x7e, // N
66
			0x00, 0x3c, 0x7e, 0x42, 0x42, 0x42, 0x7e, 0x3c, // O
67
			0x00, 0x7e, 0x7e, 0x12, 0x12, 0x12, 0x1e, 0x0c, // P
68
			0x00, 0x3c, 0x7e, 0x52, 0x52, 0x62, 0x7e, 0x3c, // Q
69
			0x00, 0x7e, 0x7e, 0x12, 0x12, 0x32, 0x7e, 0x4c, // R
70
			0x00, 0x24, 0x6e, 0x4a, 0x4a, 0x4a, 0x7a, 0x30, // S
71
			0x00, 0x02, 0x02, 0x7e, 0x7e, 0x02, 0x02, 0x00, // T
72
			0x00, 0x3e, 0x7e, 0x40, 0x40, 0x40, 0x7e, 0x3e, // U
73
			0x00, 0x1e, 0x3e, 0x60, 0x40, 0x60, 0x3e, 0x1e, // V
74
			0x00, 0x3e, 0x7e, 0x60, 0x30, 0x60, 0x7e, 0x3e, // W
75
			0x00, 0x42, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0x42, // X
76
			0x02, 0x06, 0x0c, 0x78, 0x78, 0x0c, 0x06, 0x02, // Y
77
			0x00, 0x42, 0x62, 0x72, 0x5a, 0x4e, 0x46, 0x42, // Z
78
			0x00, 0x20, 0x74, 0x54, 0x54, 0x7c, 0x78, 0x00, // a
79
			0x00, 0x00, 0x7e, 0x7e, 0x48, 0x48, 0x78, 0x30, // b
80
			0x00, 0x00, 0x38, 0x7c, 0x44, 0x44, 0x00, 0x00, // c
81
			0x00, 0x30, 0x78, 0x48, 0x48, 0x7e, 0x7e, 0x00, // d
82
			0x00, 0x38, 0x7c, 0x54, 0x54, 0x5c, 0x08, 0x00, // e
83
			0x00, 0x00, 0x7c, 0x7e, 0x0a, 0x02, 0x00, 0x00, // f
84
			0x00, 0x18, 0xbc, 0xa4, 0xa4, 0xfc, 0x7c, 0x00, // g
85
			0x00, 0x7e, 0x7e, 0x08, 0x08, 0x78, 0x70, 0x00, // h
86
			0x00, 0x00, 0x48, 0x7a, 0x7a, 0x40, 0x00, 0x00, // i
87
			0x00, 0x00, 0x40, 0xc0, 0x80, 0xfa, 0x7a, 0x00, // j
88
			0x00, 0x00, 0x7e, 0x7e, 0x10, 0x3c, 0x64, 0x40, // k
89
			0x00, 0x00, 0x00, 0x3e, 0x7e, 0x40, 0x40, 0x00, // l
90
			0x7c, 0x7c, 0x04, 0x78, 0x7c, 0x04, 0x7c, 0x78, // m
91
			0x00, 0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x78, 0x00, // n
92
			0x00, 0x38, 0x7c, 0x44, 0x44, 0x7c, 0x38, 0x00, // o
93
			0x00, 0xfc, 0xfc, 0x24, 0x24, 0x3c, 0x18, 0x00, // p
94
			0x00, 0x18, 0x3c, 0x24, 0x24, 0xfc, 0xfc, 0x80, // q
95
			0x00, 0x00, 0x78, 0x7c, 0x04, 0x04, 0x00, 0x00, // r
96
			0x00, 0x48, 0x5c, 0x54, 0x54, 0x74, 0x20, 0x00, // s
97
			0x00, 0x04, 0x3e, 0x7e, 0x44, 0x44, 0x00, 0x00, // t
98
			0x00, 0x3c, 0x7c, 0x40, 0x40, 0x7c, 0x3c, 0x00, // u
99
			0x00, 0x0c, 0x3c, 0x70, 0x60, 0x3c, 0x0c, 0x00, // v
100
			0x3c, 0x7c, 0x40, 0x30, 0x40, 0x7c, 0x3c, 0x00, // w
101
			0x00, 0x44, 0x6c, 0x38, 0x38, 0x6c, 0x44, 0x00, // x
102
			0x00, 0x1c, 0xbc, 0xa0, 0xa0, 0xfc, 0x7c, 0x00, // y
103
			0x00, 0x44, 0x64, 0x74, 0x5c, 0x4c, 0x44, 0x00, // z
104
			0x00, 0x3c, 0x7e, 0x52, 0x4a, 0x46, 0x7e, 0x3c, // 0
105
			0x00, 0x00, 0x44, 0x44, 0x7e, 0x7e, 0x40, 0x40, // 1
106
			0x00, 0x64, 0x76, 0x52, 0x52, 0x52, 0x5e, 0x4c, // 2
107
			0x00, 0x24, 0x66, 0x42, 0x4a, 0x4a, 0x7e, 0x34, // 3
108
			0x00, 0x30, 0x28, 0x24, 0x7e, 0x7e, 0x20, 0x20, // 4
109
			0x00, 0x2e, 0x6e, 0x4a, 0x4a, 0x4a, 0x7a, 0x32, // 5
110
			0x00, 0x3c, 0x7e, 0x4a, 0x4a, 0x4a, 0x7a, 0x30, // 6
111
			0x00, 0x02, 0x02, 0x62, 0x72, 0x1a, 0x0e, 0x06, // 7
112
			0x00, 0x34, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // 8
113
			0x00, 0x0c, 0x5e, 0x52, 0x52, 0x52, 0x7e, 0x3c, // 9
114
			0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, // -
115
			0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
116
			0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
117
			0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, // ,
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
118
			0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, // /
59 by edam
removed ulibc, fixed button, added text rendering
119
		}, { // INVD-D
120
			0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x7f, // A
121
			0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x77, // B
122
			0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x77, 0x77, // C
123
			0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f, 0x3e, // D
124
			0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x63, 0x63, // E
125
			0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x03, 0x03, // F
126
			0x00, 0x7f, 0x7f, 0x41, 0x49, 0x49, 0x7b, 0x7b, // G
127
			0x00, 0x7f, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x7f, // H
128
			0x00, 0x41, 0x41, 0x7f, 0x7f, 0x41, 0x41, 0x00, // I
129
			0x00, 0x60, 0x60, 0x40, 0x40, 0x40, 0x7f, 0x7f, // J
130
			0x00, 0x7f, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x77, // K
131
			0x00, 0x7f, 0x7f, 0x40, 0x40, 0x40, 0x60, 0x60, // L
132
			0x00, 0x7f, 0x7f, 0x02, 0x04, 0x02, 0x7f, 0x7f, // M
133
			0x00, 0x7f, 0x7f, 0x06, 0x0c, 0x18, 0x7f, 0x7f, // N
134
			0x00, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f, 0x7f, // O
135
			0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x0f, 0x0f, // P
136
			0x00, 0x7f, 0x7f, 0x41, 0x51, 0x21, 0x7f, 0x7f, // Q
137
			0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x77, // R
138
			0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x7b, 0x7b, // S
139
			0x00, 0x01, 0x01, 0x7f, 0x7f, 0x01, 0x01, 0x00, // T
140
			0x00, 0x7f, 0x7f, 0x40, 0x40, 0x40, 0x7f, 0x7f, // U
141
			0x00, 0x1f, 0x3f, 0x60, 0x40, 0x60, 0x3f, 0x1f, // V
142
			0x00, 0x7f, 0x7f, 0x20, 0x10, 0x20, 0x7f, 0x7f, // W
143
			0x00, 0x77, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x77, // X
144
			0x00, 0x6f, 0x6f, 0x48, 0x48, 0x48, 0x7f, 0x7f, // Y
145
			0x00, 0x63, 0x73, 0x59, 0x4d, 0x47, 0x63, 0x61, // Z
146
			0x00, 0x74, 0x74, 0x54, 0x54, 0x7c, 0x7c, 0x00, // a
147
			0x00, 0x7f, 0x7f, 0x44, 0x44, 0x7c, 0x7c, 0x00, // b
148
			0x00, 0x7c, 0x7c, 0x44, 0x44, 0x6c, 0x6c, 0x00, // c
149
			0x00, 0x7c, 0x7c, 0x44, 0x44, 0x7f, 0x7f, 0x00, // d
150
			0x00, 0x7c, 0x7c, 0x54, 0x54, 0x5c, 0x5c, 0x00, // e
151
			0x00, 0x00, 0x04, 0x7f, 0x7f, 0x05, 0x05, 0x01, // f
152
			0x00, 0xbc, 0xbc, 0xa4, 0xa4, 0xfc, 0xfc, 0x00, // g
153
			0x00, 0x7f, 0x7f, 0x04, 0x04, 0x7c, 0x7c, 0x00, // h
154
			0x00, 0x44, 0x44, 0x7d, 0x7d, 0x40, 0x40, 0x00, // i
155
			0x00, 0x80, 0x80, 0xfd, 0xfd, 0x00, 0x00, 0x00, // j
156
			0x00, 0x7f, 0x7f, 0x10, 0x10, 0x7c, 0x6c, 0x00, // k
157
			0x00, 0x00, 0x00, 0x7f, 0x7f, 0x40, 0x40, 0x00, // l
158
			0x00, 0x7c, 0x7c, 0x04, 0x7c, 0x04, 0x7c, 0x7c, // m
159
			0x00, 0x7c, 0x7c, 0x04, 0x04, 0x7c, 0x7c, 0x00, // n
160
			0x00, 0x7c, 0x7c, 0x44, 0x44, 0x7c, 0x7c, 0x00, // o
161
			0x00, 0xfc, 0xfc, 0x24, 0x24, 0x3c, 0x3c, 0x00, // p
162
			0x00, 0x3c, 0x3c, 0x24, 0x24, 0xfc, 0xfc, 0x00, // q
163
			0x00, 0x7c, 0x7c, 0x04, 0x04, 0x0c, 0x0c, 0x00, // r
164
			0x00, 0x5c, 0x5c, 0x54, 0x54, 0x74, 0x74, 0x00, // s
165
			0x00, 0x00, 0x04, 0x7f, 0x7f, 0x44, 0x44, 0x00, // t
166
			0x00, 0x7c, 0x7c, 0x40, 0x40, 0x7c, 0x7c, 0x00, // u
167
			0x00, 0x1c, 0x3c, 0x60, 0x60, 0x3c, 0x1c, 0x00, // v
168
			0x00, 0x7c, 0x7c, 0x40, 0x7c, 0x40, 0x7c, 0x7c, // w
169
			0x00, 0x6c, 0x7c, 0x10, 0x10, 0x7c, 0x6c, 0x00, // x
170
			0x00, 0xbc, 0xbc, 0xa0, 0xa0, 0xfc, 0xfc, 0x00, // y
171
			0x00, 0x64, 0x74, 0x54, 0x54, 0x5c, 0x4c, 0x00, // z
172
			0x00, 0x7f, 0x7f, 0x51, 0x49, 0x45, 0x7f, 0x7f, // 0
173
			0x00, 0x41, 0x41, 0x7f, 0x7f, 0x40, 0x40, 0x00, // 1
174
			0x00, 0x7b, 0x7b, 0x49, 0x49, 0x49, 0x4f, 0x4f, // 2
175
			0x00, 0x63, 0x63, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 3
176
			0x00, 0x1f, 0x1f, 0x10, 0x10, 0x7f, 0x7f, 0x10, // 4
177
			0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x79, // 5
178
			0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7b, 0x7b, // 6
179
			0x00, 0x03, 0x03, 0x71, 0x79, 0x0d, 0x07, 0x03, // 7
180
			0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 8
181
			0x00, 0x6f, 0x6f, 0x49, 0x49, 0x49, 0x7f, 0x7f, // 9
182
			0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, // -
183
			0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, // :
184
			0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
185
			0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, // ,
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
186
			0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x00, // /
59 by edam
removed ulibc, fixed button, added text rendering
187
		}, { // INVD-G
188
			0x7c, 0x7e, 0x22, 0x7e, 0x7e, 0x7e, 0x7c, 0x00, // A
189
			0x7c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7e, 0x34, 0x00, // B
190
			0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0x76, 0x34, 0x00, // C
191
			0x7c, 0x7e, 0x7e, 0x7e, 0x42, 0x7e, 0x3c, 0x00, // D
192
			0x3c, 0x7e, 0x7e, 0x7e, 0x4a, 0x4a, 0x00, 0x00, // E
193
			0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x12, 0x00, 0x00, // F
194
			0x3c, 0x7e, 0x7e, 0x7e, 0x52, 0x76, 0x34, 0x00, // G
195
			0x7e, 0x7e, 0x7e, 0x7e, 0x08, 0x7e, 0x7e, 0x00, // H
196
			0x00, 0x42, 0x7e, 0x7e, 0x7e, 0x7e, 0x42, 0x00, // I
197
			0x30, 0x70, 0x42, 0x7e, 0x7e, 0x7e, 0x3e, 0x00, // J
198
			0x7e, 0x7e, 0x7e, 0x7e, 0x08, 0x76, 0x62, 0x00, // K
199
			0x00, 0x3e, 0x7e, 0x7e, 0x7e, 0x40, 0x40, 0x00, // L
200
			0x7e, 0x7e, 0x7e, 0x7c, 0x08, 0x7c, 0x7e, 0x00, // M
201
			0x7e, 0x7e, 0x7e, 0x7c, 0x08, 0x7e, 0x7e, 0x00, // N
202
			0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0x7e, 0x3c, 0x00, // O
203
			0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x1e, 0x0c, 0x00, // P
204
			0x3c, 0x7e, 0x7e, 0x7e, 0x42, 0xfe, 0xbc, 0x00, // Q
205
			0x7c, 0x7e, 0x7e, 0x7e, 0x12, 0x7e, 0x6c, 0x00, // R
206
			0x24, 0x6e, 0x5e, 0x7e, 0x7a, 0x76, 0x24, 0x00, // S
207
			0x00, 0x02, 0x7e, 0x7e, 0x7e, 0x7e, 0x02, 0x00, // T
208
			0x3e, 0x7e, 0x7e, 0x7e, 0x40, 0x7e, 0x3e, 0x00, // U
209
			0x1e, 0x3e, 0x7e, 0x7e, 0x40, 0x3e, 0x1e, 0x00, // V
210
			0x3e, 0x7e, 0x7e, 0x7e, 0x20, 0x7e, 0x3e, 0x00, // W
211
			0x42, 0x66, 0x3e, 0x7e, 0x7c, 0x66, 0x42, 0x00, // X
212
			0x06, 0x0e, 0x7e, 0x7e, 0x70, 0x0e, 0x06, 0x00, // Y
213
			0x62, 0x72, 0x7a, 0x7e, 0x5e, 0x4e, 0x46, 0x00, // Z
214
			0x38, 0x7c, 0x44, 0x3c, 0x7c, 0x7c, 0x78, 0x00, // a
215
			0x3f, 0x7f, 0x7f, 0x7f, 0x44, 0x7c, 0x38, 0x00, // b
216
			0x38, 0x7c, 0x7c, 0x7c, 0x44, 0x6c, 0x28, 0x00, // c
217
			0x38, 0x7c, 0x44, 0x3f, 0x7f, 0x7f, 0x7f, 0x00, // d
218
			0x38, 0x7c, 0x7c, 0x7c, 0x54, 0x5c, 0x28, 0x00, // e
219
			0x88, 0xfe, 0xff, 0xff, 0x7f, 0x09, 0x0a, 0x00, // f
220
			0x58, 0xbc, 0xa4, 0xfc, 0xfc, 0xfc, 0x78, 0x00, // g
221
			0x7f, 0x7f, 0x7f, 0x7f, 0x04, 0x7c, 0x78, 0x00, // h
222
			0x00, 0x00, 0x7a, 0x7f, 0x7f, 0x7a, 0x00, 0x00, // i
223
			0x00, 0x80, 0xfa, 0xff, 0xff, 0x7a, 0x00, 0x00, // j
224
			0x7f, 0x7f, 0x7f, 0x7f, 0x24, 0x7c, 0x58, 0x00, // k
225
			0x00, 0x00, 0x3f, 0x7f, 0x7f, 0x7f, 0x40, 0x00, // l
226
			0x78, 0x7c, 0x7c, 0x04, 0x7c, 0x04, 0x7c, 0x78, // m
227
			0x7c, 0x7c, 0x7c, 0x78, 0x04, 0x7c, 0x78, 0x00, // n
228
			0x38, 0x7c, 0x7c, 0x7c, 0x44, 0x7c, 0x38, 0x00, // o
229
			0xfc, 0xfc, 0xfc, 0xf8, 0x44, 0x7c, 0x38, 0x00, // p
230
			0x38, 0x7c, 0x44, 0xfc, 0xfc, 0xfc, 0xf8, 0x00, // q
231
			0x7c, 0x7c, 0x7c, 0x7c, 0x04, 0x0c, 0x08, 0x00, // r
232
			0x28, 0x5c, 0x5c, 0x7c, 0x74, 0x74, 0x28, 0x00, // s
233
			0x04, 0x3e, 0x7e, 0x7e, 0x7e, 0x44, 0x24, 0x00, // t
234
			0x3c, 0x7c, 0x40, 0x3c, 0x7c, 0x7c, 0x7c, 0x00, // u
235
			0x1c, 0x3c, 0x7c, 0x7c, 0x60, 0x3c, 0x1c, 0x00, // v
236
			0x3c, 0x7c, 0x7c, 0x40, 0x7c, 0x40, 0x7c, 0x3c, // w
237
			0x44, 0x6c, 0x3c, 0x7c, 0x78, 0x6c, 0x44, 0x00, // x
238
			0x9c, 0xbc, 0xfc, 0xfc, 0x60, 0x3c, 0x1c, 0x00, // y
239
			0x64, 0x74, 0x3c, 0x7c, 0x5c, 0x4c, 0x24, 0x00, // z
240
			0x3c, 0x7e, 0x42, 0x7e, 0x7e, 0x7e, 0x3c, 0x00, // 0
241
			0x00, 0x42, 0x7e, 0x7e, 0x7e, 0x7e, 0x40, 0x00, // 1
242
			0x64, 0x72, 0x7a, 0x7e, 0x5e, 0x4e, 0x44, 0x00, // 2
243
			0x24, 0x66, 0x4a, 0x7e, 0x7e, 0x7e, 0x34, 0x00, // 3
244
			0x0e, 0x1e, 0x10, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, // 4
245
			0x2e, 0x6e, 0x4e, 0x7a, 0x7a, 0x7a, 0x32, 0x00, // 5
246
			0x3c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7a, 0x34, 0x00, // 6
247
			0x02, 0x62, 0x7a, 0x7e, 0x7e, 0x1e, 0x06, 0x00, // 7
248
			0x34, 0x7e, 0x4e, 0x7e, 0x7a, 0x7e, 0x34, 0x00, // 8
249
			0x2c, 0x5e, 0x52, 0x7e, 0x7e, 0x7e, 0x3c, 0x00, // 9
250
			0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // -
251
			0x00, 0x00, 0x28, 0x7c, 0x7c, 0x28, 0x00, 0x00, // :
252
			0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x00, 0x00, // .
253
			0x00, 0x00, 0x10, 0xb8, 0xf8, 0x70, 0x00, 0x00, // ,
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
254
			0x60, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x03, 0x00, // /
59 by edam
removed ulibc, fixed button, added text rendering
255
		}, { // INVD-B
256
			0x00, 0x78, 0x7f, 0x09, 0x09, 0x0f, 0x78, 0x00, // A
257
			0x00, 0x7f, 0x79, 0x49, 0x49, 0x4f, 0x78, 0x00, // B
258
			0x00, 0x7f, 0x79, 0x41, 0x41, 0x41, 0x63, 0x00, // C
259
			0x00, 0x7f, 0x79, 0x41, 0x41, 0x41, 0x7f, 0x00, // D
260
			0x00, 0x00, 0x7f, 0x79, 0x49, 0x49, 0x41, 0x00, // E
261
			0x00, 0x00, 0x7f, 0x79, 0x09, 0x09, 0x01, 0x00, // F
262
			0x00, 0x7f, 0x79, 0x41, 0x41, 0x49, 0x7b, 0x00, // G
263
			0x00, 0x7f, 0x78, 0x08, 0x08, 0x08, 0x7f, 0x00, // H
264
			0x00, 0x00, 0x00, 0x7f, 0x78, 0x00, 0x00, 0x00, // I
265
			0x00, 0x60, 0x40, 0x40, 0x40, 0x7f, 0x78, 0x00, // J
266
			0x00, 0x7f, 0x78, 0x08, 0x08, 0x0f, 0x78, 0x00, // K
267
			0x00, 0x00, 0x7f, 0x78, 0x40, 0x40, 0x40, 0x00, // L
268
			0x00, 0x7f, 0x79, 0x01, 0x7f, 0x01, 0x7f, 0x00, // M
269
			0x00, 0x7f, 0x79, 0x01, 0x01, 0x01, 0x7f, 0x00, // N
270
			0x00, 0x7f, 0x41, 0x41, 0x41, 0x43, 0x7f, 0x00, // O
271
			0x00, 0x7f, 0x79, 0x09, 0x09, 0x09, 0x0f, 0x00, // P
272
			0x00, 0x7f, 0x41, 0x41, 0x61, 0x61, 0x7f, 0x00, // Q
273
			0x00, 0x7f, 0x79, 0x09, 0x09, 0x0f, 0x78, 0x00, // R
274
			0x00, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x7b, 0x00, // S
275
			0x00, 0x01, 0x01, 0x7f, 0x79, 0x01, 0x01, 0x00, // T
276
			0x00, 0x7f, 0x78, 0x40, 0x40, 0x40, 0x7f, 0x00, // U
277
			0x00, 0x0f, 0x7f, 0x40, 0x40, 0x78, 0x0f, 0x00, // V
278
			0x00, 0x7f, 0x78, 0x40, 0x7f, 0x40, 0x7f, 0x00, // W
279
			0x00, 0x77, 0x78, 0x08, 0x08, 0x08, 0x77, 0x00, // X
280
			0x00, 0x0f, 0x08, 0x78, 0x78, 0x08, 0x0f, 0x00, // Y
281
			0x00, 0x7b, 0x79, 0x49, 0x49, 0x49, 0x6f, 0x00, // Z
282
			0x00, 0x74, 0x74, 0x54, 0x54, 0x7c, 0x00, 0x00, // a
283
			0x00, 0x7f, 0x74, 0x44, 0x44, 0x7c, 0x00, 0x00, // b
284
			0x00, 0x7c, 0x74, 0x44, 0x44, 0x6c, 0x00, 0x00, // c
285
			0x00, 0x7c, 0x74, 0x44, 0x44, 0x7f, 0x00, 0x00, // d
286
			0x00, 0x7c, 0x74, 0x54, 0x54, 0x5c, 0x00, 0x00, // e
287
			0x00, 0x00, 0x04, 0x7f, 0x75, 0x01, 0x00, 0x00, // f
288
			0x00, 0xbc, 0xb4, 0xa4, 0xa4, 0xfc, 0x00, 0x00, // g
289
			0x00, 0x7f, 0x74, 0x04, 0x04, 0x7c, 0x00, 0x00, // h
290
			0x00, 0x00, 0x00, 0x7d, 0x71, 0x00, 0x00, 0x00, // i
291
			0x00, 0x00, 0x80, 0xbd, 0xf1, 0x00, 0x00, 0x00, // j
292
			0x00, 0x7f, 0x70, 0x10, 0x1c, 0x70, 0x00, 0x00, // k
293
			0x00, 0x00, 0x00, 0x7f, 0x78, 0x00, 0x00, 0x00, // l
294
			0x00, 0x7c, 0x74, 0x04, 0x7c, 0x04, 0x7c, 0x00, // m
295
			0x00, 0x7c, 0x74, 0x04, 0x04, 0x7c, 0x00, 0x00, // n
296
			0x00, 0x7c, 0x74, 0x44, 0x44, 0x7c, 0x00, 0x00, // o
297
			0x00, 0xfc, 0x34, 0x24, 0x24, 0x3c, 0x00, 0x00, // p
298
			0x00, 0x3c, 0x34, 0x24, 0x24, 0xfc, 0x00, 0x00, // q
299
			0x00, 0x00, 0x7c, 0x74, 0x04, 0x04, 0x00, 0x00, // r
300
			0x00, 0x5c, 0x54, 0x54, 0x74, 0x74, 0x00, 0x00, // s
301
			0x00, 0x00, 0x04, 0x7f, 0x74, 0x00, 0x00, 0x00, // t
302
			0x00, 0x7c, 0x70, 0x40, 0x40, 0x7c, 0x00, 0x00, // u
303
			0x00, 0x1c, 0x7c, 0x40, 0x70, 0x1c, 0x00, 0x00, // v
304
			0x00, 0x7c, 0x70, 0x40, 0x7c, 0x40, 0x7c, 0x00, // w
305
			0x00, 0x6c, 0x70, 0x10, 0x10, 0x6c, 0x00, 0x00, // x
306
			0x00, 0xbc, 0xb0, 0xa0, 0xa0, 0xfc, 0x00, 0x00, // y
307
			0x00, 0x74, 0x74, 0x54, 0x54, 0x5c, 0x00, 0x00, // z
308
			0x00, 0x7f, 0x41, 0x41, 0x41, 0x79, 0x7f, 0x00, // 0
309
			0x00, 0x00, 0x00, 0x78, 0x7f, 0x00, 0x00, 0x00, // 1
310
			0x00, 0x7b, 0x79, 0x49, 0x49, 0x49, 0x4f, 0x00, // 2
311
			0x00, 0x63, 0x49, 0x49, 0x49, 0x7f, 0x78, 0x00, // 3
312
			0x00, 0x1f, 0x11, 0x11, 0x71, 0x7f, 0x10, 0x00, // 4
313
			0x00, 0x6f, 0x49, 0x49, 0x49, 0x79, 0x79, 0x00, // 5
314
			0x00, 0x7f, 0x49, 0x49, 0x49, 0x79, 0x7b, 0x00, // 6
315
			0x00, 0x01, 0x01, 0x01, 0x79, 0x7f, 0x00, 0x00, // 7
316
			0x00, 0x78, 0x4f, 0x49, 0x49, 0x7f, 0x78, 0x00, // 8
317
			0x00, 0x1f, 0x11, 0x11, 0x11, 0x71, 0x7f, 0x00, // 9
318
			0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, // -
319
			0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
320
			0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
321
			0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, // ,
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
322
			0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // /
59 by edam
removed ulibc, fixed button, added text rendering
323
		}
324
	};
325
60 by edam
remove TextRenderer singleton and save space
326
	// nothing to do?
327
	if( c == _glyph_cache_char )
328
		return;
329
	_glyph_cache_char = c;
330
331
	// find glyph data position
59 by edam
removed ulibc, fixed button, added text rendering
332
	int pos;
333
	if( c >= 'A' && c <= 'Z' )
334
		pos = c - 'A';
335
	else if( c >= 'a' && c <= 'z' )
336
		pos = c - 'a' + 26;
337
	else if( c >= '0' && c <= '9' )
338
		pos = c - '0' + 52;
339
	else if( c == '-' )
340
		pos = 62;
341
	else if( c == ':' )
342
		pos = 63;
343
	else if( c == '.' )
344
		pos = 64;
345
	else if( c == ',' )
346
		pos = 65;
82 by Tim Marston
added info mode, a '/' to the fonts and cleaned up a couple of bits
347
	else if( c == '/' )
348
		pos = 66;
59 by edam
removed ulibc, fixed button, added text rendering
349
	else
350
		pos = -1;
351
60 by edam
remove TextRenderer singleton and save space
352
	// space? or copy glyph from progmem?
59 by edam
removed ulibc, fixed button, added text rendering
353
	if( pos == -1 )
60 by edam
remove TextRenderer singleton and save space
354
		memset( _glyph_cache, 0, 8 );
355
	else
356
		memcpy_P( _glyph_cache, &( fonts[ _font ][ pos * 8 ] ), 8 );
357
}
358
359
76 by edam
switch button to no interim presses during settings mode; added NVRAM support
360
void TextRenderer::init()
361
{
362
	Nvram::load( Nvram::NVRAM_FONT, _font );
363
	if( _font < 0 || _font >= 4 ) _font = 0;
364
}
365
366
79 by Tim Marston
added adjustable text scaling factor
367
int TextRenderer::get_width( int message_len, int scale )
60 by edam
remove TextRenderer singleton and save space
368
{
79 by Tim Marston
added adjustable text scaling factor
369
	return message_len * 8 * scale;
60 by edam
remove TextRenderer singleton and save space
370
}
371
372
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
373
void TextRenderer::render( const char *message, int message_len, int x,
79 by Tim Marston
added adjustable text scaling factor
374
						   bool y_flip, int y_shift, int scale )
60 by edam
remove TextRenderer singleton and save space
375
{
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
376
	char glyph_col = 0;
377
60 by edam
remove TextRenderer singleton and save space
378
	// handle negative x
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
379
	if( x >= 0 )
380
	{
381
		// scale font
79 by Tim Marston
added adjustable text scaling factor
382
		x /= scale;
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
383
384
		int pos = x / 8;
385
		if( pos < message_len )
386
		{
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
387
			// ensure correct glyph is cached and pull out column of data
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
388
			cache_glyph( message[ pos ] );
389
			glyph_col = _glyph_cache[ x % 8 ];
390
		}
60 by edam
remove TextRenderer singleton and save space
391
	}
392
393
	// draw a column
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
394
	if( y_flip )
63 by edam
widenned clock hands, tweaked scales, got top & bottom text modes working
395
		for( int a = 7; a >= 0; a-- ) {
396
			if( glyph_col & 1 )
397
				_output_buffer |= 1 << ( a + y_shift );
398
			glyph_col >>= 1;
399
		}
400
	else
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
401
		for( int a = 0; a < 8; a++ ) {
402
			if( glyph_col & 1 )
403
				_output_buffer |= 1 << ( a + y_shift );
404
			glyph_col >>= 1;
405
		}
406
}
407
408
409
void TextRenderer::reset_buffer()
410
{
411
	_output_buffer = 0;
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
412
	_need_render = false;
413
}
414
415
416
void TextRenderer::buffer_in_use()
417
{
418
	_need_render = true;
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
419
}
420
421
422
void TextRenderer::output_buffer()
423
{
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
424
	if( !_need_render ) return;
425
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
426
	for( int a = 8; a >= 0; a-- ) {
65 by Tim Marston
removed most OOP/inheritance crap, saved loads of space!
427
		led( a, ( _output_buffer & 1 )? true : false );
62 by edam
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages
428
		_output_buffer >>= 1;
429
	}
430
	_output_buffer = 0;
59 by edam
removed ulibc, fixed button, added text rendering
431
}
63 by edam
widenned clock hands, tweaked scales, got top & bottom text modes working
432
433
71 by Tim Marston
added time set mode, made text renderer's buffer auto reset/output
434
int TextRenderer::get_font()
435
{
436
	return _font;
437
}
438
439
440
void TextRenderer::inc_font()
441
{
442
	if( ++_font >= 4 )
443
		_font = 0;
76 by edam
switch button to no interim presses during settings mode; added NVRAM support
444
	Nvram::save( Nvram::NVRAM_FONT, _font );
63 by edam
widenned clock hands, tweaked scales, got top & bottom text modes working
445
}