/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: 2013-03-31 17:07:36 UTC
  • Revision ID: tim@ed.am-20130331170736-hphm2hg0y6l7w6z1
made rtc-test's DS1307 library a symlink to the main one in src/util

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