/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.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

Lines of Context:
25
25
#include "config.h"
26
26
#include "Arduino.h"
27
27
#include <avr/pgmspace.h>
 
28
#include "display.h"
 
29
 
 
30
 
 
31
// the proportion of the display to use (in segments)
 
32
#define BIG_SEGMENTS ( NUM_SEGMENTS * 2 / 3 )
 
33
#define SMALL_SEGMENTS ( NUM_SEGMENTS - BIG_TEXT_SEGMENTS )
 
34
#define HALF_SEGMENTS ( NUM_SEGMENTS / 2 )
28
35
 
29
36
 
30
37
// the buffer for the message
51
58
 
52
59
void reset_message_param( int message_num )
53
60
{
54
 
        if( _message_modes[ message_num ] & Text::MODE_HSCROLL )
55
 
        {
56
 
                switch( _message_modes[ message_num ] & 0x1c )
57
 
                {
58
 
                case Text::MODE_ONEQUARTER:
59
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 4; break;
60
 
                case Text::MODE_ONETHIRD:
61
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 3; break;
62
 
                case Text::MODE_HALF:
63
 
                        _message_params[ message_num ] = -NUM_SEGMENTS / 2; break;
64
 
                case Text::MODE_TWOTHIRDS:
65
 
                        _message_params[ message_num ] = -NUM_SEGMENTS * 2 / 3; break;
66
 
                case Text::MODE_THREEQUARTERS:
67
 
                        _message_params[ message_num ] = -NUM_SEGMENTS * 3 / 4; break;
68
 
                case Text::MODE_ALL:
69
 
                        _message_params[ message_num ] = -NUM_SEGMENTS; break;
70
 
                }
71
 
        }
72
 
        else
73
 
        {
74
 
                switch( _message_modes[ message_num ] & 0x1c )
75
 
                {
76
 
                case Text::MODE_ONEQUARTER:
77
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 4; break;
78
 
                case Text::MODE_ONETHIRD:
79
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 3; break;
80
 
                case Text::MODE_HALF:
81
 
                        _message_params[ message_num ] = NUM_SEGMENTS / 2; break;
82
 
                case Text::MODE_TWOTHIRDS:
83
 
                        _message_params[ message_num ] = NUM_SEGMENTS * 2 / 3; break;
84
 
                case Text::MODE_THREEQUARTERS:
85
 
                        _message_params[ message_num ] = NUM_SEGMENTS * 3 / 4; break;
86
 
                case Text::MODE_ALL:
87
 
                        _message_params[ message_num ] = NUM_SEGMENTS; break;
88
 
                }
89
 
                _message_params[ message_num ] = -( _message_params[ message_num ] -
90
 
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
61
        switch( _message_modes[ message_num ] )
 
62
        {
 
63
        case 'S':
 
64
                _message_params[ message_num ] = -BIG_SEGMENTS;
 
65
                break;
 
66
        case 's':
 
67
                _message_params[ message_num ] = -HALF_SEGMENTS;
 
68
                break;
 
69
        case 'B':
 
70
        case 'T':
 
71
                _message_params[ message_num ] = -( BIG_SEGMENTS -
 
72
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
73
                break;
 
74
        case 'b':
 
75
        case 't':
 
76
                _message_params[ message_num ] = -( HALF_SEGMENTS -
 
77
                        TextRenderer::get_width( _message_lens[ message_num ] ) ) / 2;
 
78
                break;
91
79
        }
92
80
}
93
81
 
99
87
}
100
88
 
101
89
 
102
 
void Text::reset_message( int message_num, char mode )
 
90
void Text::set_message_mode( int message_num, char mode )
103
91
{
104
92
        _message_modes[ message_num ] = mode;
105
93
        reset_message_param( message_num );
188
176
        case MODE_BOTTOM:
189
177
                if( segment > ( NUM_SEGMENTS - width ) / 2 &&
190
178
                        segment < ( NUM_SEGMENTS - width ) / 2 + width )
191
 
                {
192
 
                        segment = width - ( segment - ( NUM_SEGMENTS - width ) / 2 );
193
 
                }               
 
179
                        segment -= ( NUM_SEGMENTS - width ) / 2;
194
180
                else
195
181
                        return;
196
182
                break;
200
186
        TextRenderer::render(
201
187
                _messages[ message_num ], _message_lens[ message_num ],
202
188
                (long)segment + _message_params[ message_num ],
203
 
                ( _message_modes[ message_num ] & 1 ) == 0, 0 );
 
189
                _message_modes[ message_num ] & 1 == 0, 0 );
204
190
}