46
38
static int _font = 0;
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;
41
static unsigned char _output_buffer;
43
// does buffer need rendering?
44
static bool _need_render;
59
48
void cache_glyph( char c )
61
static char fonts[][ 66 * 8 ] PROGMEM = {
50
static char fonts[][ 67 * 8 ] PROGMEM = {
63
52
0x00, 0x7c, 0x7e, 0x12, 0x12, 0x12, 0x7e, 0x7c, // A
64
53
0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // B
126
115
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
127
116
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
128
117
0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, // ,
118
0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, // /
130
120
0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x7f, // A
131
121
0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x77, // B
193
183
0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, // :
194
184
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
195
185
0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, // ,
186
0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x00, // /
197
188
0x7c, 0x7e, 0x22, 0x7e, 0x7e, 0x7e, 0x7c, 0x00, // A
198
189
0x7c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7e, 0x34, 0x00, // B
260
251
0x00, 0x00, 0x28, 0x7c, 0x7c, 0x28, 0x00, 0x00, // :
261
252
0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x00, 0x00, // .
262
253
0x00, 0x00, 0x10, 0xb8, 0xf8, 0x70, 0x00, 0x00, // ,
254
0x60, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x03, 0x00, // /
264
256
0x00, 0x78, 0x7f, 0x09, 0x09, 0x0f, 0x78, 0x00, // A
265
257
0x00, 0x7f, 0x79, 0x49, 0x49, 0x4f, 0x78, 0x00, // B
327
319
0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
328
320
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
329
321
0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, // ,
322
0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // /
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
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 )
380
378
// 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 ] : ' ' );
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 );
395
for( int a = 7; a >= 0; a-- ) {
397
_output_buffer |= 1 << ( a + y_shift );
432
render( (long)segment + _scroll );
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;
430
for( int a = 8; a >= 0; a-- ) {
431
led( a, ( _output_buffer & 1 )? true : false );
432
_output_buffer >>= 1;
438
int TextRenderer::get_font()
444
void TextRenderer::inc_font()
448
Nvram::save( Nvram::NVRAM_FONT, _font );