/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/text_renderer.cc

  • Committer: edam
  • Date: 2012-02-29 21:56:32 UTC
  • Revision ID: edam@waxworlds.org-20120229215632-kypb9491vx7bicef
moved some stuf round, created a re-usable pool of message buffers, genericised "modes" for messages

Show diffs side-by-side

added added

removed removed

24
24
#include "config.h"
25
25
#include "Arduino.h"
26
26
#include <avr/pgmspace.h>
27
 
#include "common.h"
 
27
#include "display.h"
28
28
 
29
29
 
30
30
// cached glyph
39
39
// output buffer
40
40
static unsigned char _output_buffer;
41
41
 
42
 
// does buffer need rendering?
43
 
static bool _need_render;
44
 
 
45
42
 
46
43
// cache a glyph
47
44
void cache_glyph( char c )
370
367
                int pos = x / 8;
371
368
                if( pos < message_len )
372
369
                {
373
 
                        // ensure correct glyph is cached and pull out column of data
 
370
                        // ensure correct glyph is cached and pull out colun of data
374
371
                        cache_glyph( message[ pos ] );
375
372
                        glyph_col = _glyph_cache[ x % 8 ];
376
373
                }
378
375
 
379
376
        // draw a column
380
377
        if( y_flip )
381
 
                for( int a = 7; a >= 0; a-- ) {
382
 
                        if( glyph_col & 1 )
383
 
                                _output_buffer |= 1 << ( a + y_shift );
384
 
                        glyph_col >>= 1;
385
 
                }
386
 
        else
387
378
                for( int a = 0; a < 8; a++ ) {
388
379
                        if( glyph_col & 1 )
389
380
                                _output_buffer |= 1 << ( a + y_shift );
390
381
                        glyph_col >>= 1;
391
382
                }
 
383
        else
 
384
                for( int a = 8; a < 0; a++ ) {
 
385
                        if( glyph_col & 1 )
 
386
                                _output_buffer |= 1 << ( a + y_shift );
 
387
                        glyph_col >>= 1;
 
388
                }
392
389
}
393
390
 
394
391
 
395
392
void TextRenderer::reset_buffer()
396
393
{
397
394
        _output_buffer = 0;
398
 
        _need_render = false;
399
 
}
400
 
 
401
 
 
402
 
void TextRenderer::buffer_in_use()
403
 
{
404
 
        _need_render = true;
405
395
}
406
396
 
407
397
 
408
398
void TextRenderer::output_buffer()
409
399
{
410
 
        if( !_need_render ) return;
411
 
 
412
400
        for( int a = 8; a >= 0; a-- ) {
413
 
                led( a, ( _output_buffer & 1 )? true : false );
 
401
                Display::led( a, ( _output_buffer & 1 )? true : false );
414
402
                _output_buffer >>= 1;
415
403
        }
416
404
        _output_buffer = 0;
417
405
}
418
 
 
419
 
 
420
 
int TextRenderer::get_font()
421
 
{
422
 
        return _font;
423
 
}
424
 
 
425
 
 
426
 
void TextRenderer::inc_font()
427
 
{
428
 
        if( ++_font >= 4 )
429
 
                _font = 0;
430
 
}