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;
354
void TextRenderer::init()
356
Nvram::load( Nvram::NVRAM_FONT, _font );
357
if( _font < 0 || _font >= 4 ) _font = 0;
361
int TextRenderer::get_width( int message_len, int scale )
363
return message_len * 8 * scale;
367
void TextRenderer::render( const char *message, int message_len, int x,
368
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
372
380
// handle negative x
379
if( pos < message_len )
381
// ensure correct glyph is cached and pull out column of data
382
cache_glyph( message[ pos ] );
383
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 ] : ' ' );
389
for( int a = 7; a >= 0; a-- ) {
391
_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 );
395
for( int a = 0; a < 8; a++ ) {
397
_output_buffer |= 1 << ( a + y_shift );
403
void TextRenderer::reset_buffer()
406
_need_render = false;
410
void TextRenderer::buffer_in_use()
416
void TextRenderer::output_buffer()
418
if( !_need_render ) return;
420
for( int a = 8; a >= 0; a-- ) {
421
led( a, ( _output_buffer & 1 )? true : false );
422
_output_buffer >>= 1;
428
int TextRenderer::get_font()
434
void TextRenderer::inc_font()
438
Nvram::save( Nvram::NVRAM_FONT, _font );
432
render( (long)segment + _scroll );