/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: Tim Marston
  • Date: 2012-03-10 12:31:16 UTC
  • Revision ID: tim@ed.am-20120310123116-l348p5btgecmdj1q
added realtime clock test

Show diffs side-by-side

added added

removed removed

25
25
#include "Arduino.h"
26
26
#include <avr/pgmspace.h>
27
27
#include "common.h"
28
 
#include "nvram.h"
29
28
 
30
29
 
31
30
// cached glyph
40
39
// output buffer
41
40
static unsigned char _output_buffer;
42
41
 
43
 
// does buffer need rendering?
44
 
static bool _need_render;
45
 
 
46
42
 
47
43
// cache a glyph
48
44
void cache_glyph( char c )
351
347
}
352
348
 
353
349
 
354
 
void TextRenderer::init()
355
 
{
356
 
        Nvram::load( Nvram::NVRAM_FONT, _font );
357
 
        if( _font < 0 || _font >= 4 ) _font = 0;
358
 
}
359
 
 
360
 
 
361
350
int TextRenderer::get_width( int message_len )
362
351
{
363
352
        return message_len * 8 * TEXT_SCALE;
378
367
                int pos = x / 8;
379
368
                if( pos < message_len )
380
369
                {
381
 
                        // ensure correct glyph is cached and pull out column of data
 
370
                        // ensure correct glyph is cached and pull out colun of data
382
371
                        cache_glyph( message[ pos ] );
383
372
                        glyph_col = _glyph_cache[ x % 8 ];
384
373
                }
403
392
void TextRenderer::reset_buffer()
404
393
{
405
394
        _output_buffer = 0;
406
 
        _need_render = false;
407
 
}
408
 
 
409
 
 
410
 
void TextRenderer::buffer_in_use()
411
 
{
412
 
        _need_render = true;
413
395
}
414
396
 
415
397
 
416
398
void TextRenderer::output_buffer()
417
399
{
418
 
        if( !_need_render ) return;
419
 
 
420
400
        for( int a = 8; a >= 0; a-- ) {
421
401
                led( a, ( _output_buffer & 1 )? true : false );
422
402
                _output_buffer >>= 1;
425
405
}
426
406
 
427
407
 
428
 
int TextRenderer::get_font()
429
 
{
430
 
        return _font;
431
 
}
432
 
 
433
 
 
434
 
void TextRenderer::inc_font()
435
 
{
436
 
        if( ++_font >= 4 )
437
 
                _font = 0;
438
 
        Nvram::save( Nvram::NVRAM_FONT, _font );
 
408
void TextRenderer::select_font( int font_num )
 
409
{
 
410
        _font = font_num;
439
411
}