/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-21 21:24:17 UTC
  • Revision ID: tim@ed.am-20120321212417-dnba5l1oheddeyxw
fixed time centring and display in settings mode

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
47
46
// cache a glyph
48
47
void cache_glyph( char c )
49
48
{
50
 
        static char fonts[][ 67 * 8 ] PROGMEM = {
 
49
        static char fonts[][ 66 * 8 ] PROGMEM = {
51
50
                { // INVD-A
52
51
                        0x00, 0x7c, 0x7e, 0x12, 0x12, 0x12, 0x7e, 0x7c, // A
53
52
                        0x00, 0x7e, 0x7e, 0x4a, 0x4a, 0x4a, 0x7e, 0x34, // B
115
114
                        0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
116
115
                        0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
117
116
                        0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, // ,
118
 
                        0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, // /
119
117
                }, { // INVD-D
120
118
                        0x00, 0x7f, 0x7f, 0x09, 0x09, 0x09, 0x7f, 0x7f, // A
121
119
                        0x00, 0x7f, 0x7f, 0x49, 0x49, 0x49, 0x7f, 0x77, // B
183
181
                        0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, // :
184
182
                        0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
185
183
                        0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, // ,
186
 
                        0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x00, // /
187
184
                }, { // INVD-G
188
185
                        0x7c, 0x7e, 0x22, 0x7e, 0x7e, 0x7e, 0x7c, 0x00, // A
189
186
                        0x7c, 0x7e, 0x7e, 0x7e, 0x4a, 0x7e, 0x34, 0x00, // B
251
248
                        0x00, 0x00, 0x28, 0x7c, 0x7c, 0x28, 0x00, 0x00, // :
252
249
                        0x00, 0x00, 0x30, 0x78, 0x78, 0x30, 0x00, 0x00, // .
253
250
                        0x00, 0x00, 0x10, 0xb8, 0xf8, 0x70, 0x00, 0x00, // ,
254
 
                        0x60, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x03, 0x00, // /
255
251
                }, { // INVD-B
256
252
                        0x00, 0x78, 0x7f, 0x09, 0x09, 0x0f, 0x78, 0x00, // A
257
253
                        0x00, 0x7f, 0x79, 0x49, 0x49, 0x4f, 0x78, 0x00, // B
319
315
                        0x00, 0x00, 0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00, // :
320
316
                        0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // .
321
317
                        0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, // ,
322
 
                        0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // /
323
318
                }
324
319
        };
325
320
 
344
339
                pos = 64;
345
340
        else if( c == ',' )
346
341
                pos = 65;
347
 
        else if( c == '/' )
348
 
                pos = 66;
349
342
        else
350
343
                pos = -1;
351
344
 
357
350
}
358
351
 
359
352
 
360
 
void TextRenderer::init()
361
 
{
362
 
        Nvram::load( Nvram::NVRAM_FONT, _font );
363
 
        if( _font < 0 || _font >= 4 ) _font = 0;
364
 
}
365
 
 
366
 
 
367
 
int TextRenderer::get_width( int message_len, int scale )
368
 
{
369
 
        return message_len * 8 * scale;
 
353
int TextRenderer::get_width( int message_len )
 
354
{
 
355
        return message_len * 8 * TEXT_SCALE;
370
356
}
371
357
 
372
358
 
373
359
void TextRenderer::render( const char *message, int message_len, int x,
374
 
                                                   bool y_flip, int y_shift, int scale )
 
360
                                                   bool y_flip, int y_shift )
375
361
{
376
362
        char glyph_col = 0;
377
363
 
379
365
        if( x >= 0 )
380
366
        {
381
367
                // scale font
382
 
                x /= scale;
 
368
                x /= TEXT_SCALE;
383
369
 
384
370
                int pos = x / 8;
385
371
                if( pos < message_len )
423
409
{
424
410
        if( !_need_render ) return;
425
411
 
426
 
        // outer led on
427
 
        led( 9, true );
428
 
 
429
 
        // output buffer
430
412
        for( int a = 8; a >= 0; a-- ) {
431
413
                led( a, ( _output_buffer & 1 )? true : false );
432
414
                _output_buffer >>= 1;
445
427
{
446
428
        if( ++_font >= 4 )
447
429
                _font = 0;
448
 
        Nvram::save( Nvram::NVRAM_FONT, _font );
449
430
}