38
46
static int _font = 0;
41
static unsigned char _output_buffer;
43
// does buffer need rendering?
44
static bool _need_render;
49
static unsigned long _last_millis;
51
// duration last frame (in case we can't calculate it this frame!)
52
static unsigned long _duration;
54
// scroll position (in segments )
55
static signed long _scroll;
48
59
void cache_glyph( char c )
50
static char fonts[][ 67 * 8 ] PROGMEM = {
61
static char fonts[][ 66 * 8 ] PROGMEM = {
52
63
0x00, 0x7c, 0x7e, 0x12, 0x12, 0x12, 0x7e, 0x7c, // A
53
64
0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // B
115
126
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
116
127
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
117
128
0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, // ,
118
0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, // /
120
130
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x7f, // A
121
131
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x77, // B
183
193
0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, // :
184
194
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
185
195
0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, // ,
186
0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x00, // /
188
197
0x7c, 0x7e, 0x22, 0x7e, 0x7e, 0x7e, 0x7c, 0x00, // A
189
198
0x7c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7e, 0x34, 0x00, // B
251
260
0x00, 0x00, 0x28, 0x7c, 0x7c, 0x28, 0x00, 0x00, // :
252
261
0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x00, 0x00, // .
253
262
0x00, 0x00, 0x10, 0xb8, 0xf8, 0x70, 0x00, 0x00, // ,
254
0x60, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x03, 0x00, // /
256
264
0x00, 0x78, 0x7f, 0x09, 0x09, 0x0f, 0x78, 0x00, // A
257
265
0x00, 0x7f, 0x79, 0x49, 0x49, 0x4f, 0x78, 0x00, // B
319
327
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
320
328
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
321
329
0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, // ,
322
0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // /
360
void TextRenderer::init()
362
Nvram::load( Nvram::NVRAM_FONT, _font );
363
if( _font < 0 || _font >= 4 ) _font = 0;
367
int TextRenderer::get_width( int message_len, int scale )
369
return message_len * 8 * scale;
373
void TextRenderer::render( const char *message, int message_len, int x,
374
bool y_flip, int y_shift, int scale )
365
// convert segment to display-space segment
366
int xform_segment( int segment )
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 );
377
// draw a column of pixels from the current message
378
380
// handle negative x
385
if( pos < message_len )
387
// ensure correct glyph is cached and pull out column of data
388
cache_glyph( message[ pos ] );
389
glyph_col = _glyph_cache[ x % 8 ];
389
// make sure the correct glyph is cached
391
cache_glyph( ( pos >= 0 && pos < (signed)_message.length() )? _message[ pos ] : ' ' );
395
for( int a = 7; a >= 0; a-- ) {
397
_output_buffer |= 1 << ( a + y_shift );
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 );
400
PString &TextRenderer::get_pstring()
404
_last_millis = ::millis();
405
_scroll = -TEXT_DISPLAY_SEGMENTS;
411
void TextRenderer::draw_reset()
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;
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;
426
void TextRenderer::draw_scroll( int segment )
428
segment = xform_segment( segment );
401
for( int a = 0; a < 8; a++ ) {
403
_output_buffer |= 1 << ( a + y_shift );
409
void TextRenderer::reset_buffer()
412
_need_render = false;
416
void TextRenderer::buffer_in_use()
422
void TextRenderer::output_buffer()
424
if( !_need_render ) return;
426
for( int a = 8; a >= 0; a-- ) {
427
led( a, ( _output_buffer & 1 )? true : false );
428
_output_buffer >>= 1;
434
int TextRenderer::get_font()
440
void TextRenderer::inc_font()
444
Nvram::save( Nvram::NVRAM_FONT, _font );
432
render( (long)segment + _scroll );